Statically linking is discouraged. Although, there are situations in which it is required. This commit includes some required dependency checks to enable building a statically linked version of iprconfig. It includes a new flag in the Autotools Build System, '--enable-build-static' to support this option. To keep static linked binary to a minimum inside iprutils, only iprconfig has a static version in this patch.
This also includes a new subpackage in the spec file to hold the static binary. To generate this subpackage, one must call rpmbuild passing '--with static'. The static version will be installed as 'iprconfig-static' and will not conflict with iprutils package. Be aware that static building requires the static version of ncurses and glibc packages. Otherwise, iprconfig-static build will fail. Since dependency order matters a lot when statically linking, this patch depends heavily on my last fix, ("Fail on libncurses if ncurses-devel is missing."), which is not upstream yet. I made sure this one will not even apply cleanly without it. For testing purposes, make sure you have that patch applied. This was tested on F21, RHEL7x and SLES12. Signed-off-by: Gabriel Krisman Bertazi <kris...@linux.vnet.ibm.com> --- Makefile.am | 8 ++++++++ configure.ac | 24 ++++++++++++++++++++++++ spec/iprutils.spec | 38 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 68 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index daae8e5..d285399 100644 --- a/Makefile.am +++ b/Makefile.am @@ -29,6 +29,14 @@ iprinit_LDADD= libipr.la iprdbg_SOURCES = iprdbg.c iprdbg_LDADD= libipr.la +if STATIC_BUILD +sbin_PROGRAMS += iprconfig-static + +iprconfig_static_SOURCES = iprconfig.c iprconfig.h +iprconfig_static_LDADD= libipr.la +iprconfig_static_LDFLAGS=-all-static +endif + dist_man_MANS = iprconfig.8 iprdump.8 iprinit.8 iprupdate.8 iprsos.8 SUBDIRS = . systemd init.d spec diff --git a/configure.ac b/configure.ac index 6fd7b93..71de904 100644 --- a/configure.ac +++ b/configure.ac @@ -24,7 +24,31 @@ if test -n ${ncurses_include}; then CFLAGS="${CFLAGS} ${ncurses_include}" fi +AC_ARG_ENABLE([build_static], + [--enable-build-static Generate statically linked binaries], +[case "${enableval}" in + yes) + build_static=true + CFLAGS="-static ${CFLAGS}" + ;; + no) + build_static=false + ;; + *) + AC_MSG_ERROR([bad value ${enableval} for --static]) + ;; + esac], [build_static=false]) +AM_CONDITIONAL([STATIC_BUILD], [test "x${build_static}" = xtrue]) + # Check for Libraries. +if test "x${STATIC_BUILD_TRUE}" = "x"; then + AC_CHECK_LIB(dl, dlopen, [], + [AC_ERROR("glibc-static required")]) + AC_CHECK_LIB(tinfo, tgetent, [], + [AC_ERROR("libtinfo not found. + It should be provided by ncurses")]) +fi + AC_CHECK_LIB([ncurses], [curses_version], [], [AC_ERROR("libncurses not found.")]) AC_CHECK_LIB([form], [free_form], [], [AC_ERROR("libform not found.")]) diff --git a/spec/iprutils.spec b/spec/iprutils.spec index c3af8c3..d002453 100644 --- a/spec/iprutils.spec +++ b/spec/iprutils.spec @@ -10,15 +10,37 @@ Source0: iprutils-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-root BuildRequires: ncurses-devel python +# Predicate whether we want to build -static package. +%bcond_with static + %description Provides a suite of utilities to manage and configure SCSI devices supported by the ipr SCSI storage device driver. +%if %{with static} +%package static +Summary: Static version of iprutils. +%if 0%{?suse_version} +BuildRequires: glibc-static +%else +BuildRequires: glibc-static ncurses-static +%endif + +%description static +Static version of some tools of iprutils. +%endif # with_static + %prep %setup -q -n %{name}-%{version} %build -%configure --sbindir=%{_sbindir} --libdir=%{_libdir} +%configure --sbindir=%{_sbindir} --libdir=%{_libdir} \ +%if 0%{with static} + --enable-build-static=yes +%else + --enable-build-static=no +%endif #!with_static + make %install @@ -124,7 +146,12 @@ rm -rf %{_topdir}/BUILD%{name} %files %defattr(-,root,root) -%{_sbindir}/* +%{_sbindir}/iprconfig +%{_sbindir}/iprdump +%{_sbindir}/iprupdate +%{_sbindir}/iprinit +%{_sbindir}/iprdbg +%{_sbindir}/iprsos %{_includedir}/* %{_libdir}/* %{python_sitelib}/sos/plugins/* @@ -142,6 +169,13 @@ rm -rf %{_topdir}/BUILD%{name} %{_sysconfdir}/init.d/iprupdate %endif +%if 0%{with static} +%files static + +%defattr(-,root,root) +%{_sbindir}/iprconfig-static + +%endif #with_static %changelog * Wed May 6 2015 Brian King <brk...@linux.vnet.ibm.com> 2.4.6 -- 2.1.0 ------------------------------------------------------------------------------ _______________________________________________ Iprdd-devel mailing list Iprdd-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/iprdd-devel