[PATCH] build-sys: add --enable-static-programs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add support for static versions of mount, umount, losetup, fdisk,
and sfdisk.

Co-Author: Karel Zak <kzak@xxxxxxxxxx>
Signed-off-by: Stepan Kasal <skasal@xxxxxxxxxx>
---

Hi,
  so here is another iteration.  Supports --enable-static-programs
without an argument, and tests the static build during "make
distcheck".

Thank you, Mike, for all the suggestions.

Is this patch OK?

Stepan

 Makefile.am       |    3 +-
 configure.ac      |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 fdisk/Makefile.am |   12 ++++++++++
 mount/Makefile.am |   31 +++++++++++++++++++++++--
 4 files changed, 105 insertions(+), 4 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 29b11d8..f7907b6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -39,7 +39,8 @@ distclean-local:
 	-find . -name \*~ -o -name \*.orig -o -name \*.rej | xargs rm -f
 	rm -rf autom4te.cache
 
-ENABLE_ALL = --enable-elvtune --enable-init --enable-kill --enable-last \
+ENABLE_ALL = --enable-static-programs \
+ --enable-elvtune --enable-init --enable-kill --enable-last \
  --enable-mesg --enable-partx --enable-raw --enable-rdev --enable-reset \
  --enable-login-utils --enable-write
 DISTCHECK_CONFIGURE_FLAGS = --disable-use-tty-group $(ENABLE_ALL)
diff --git a/configure.ac b/configure.ac
index e38c501..eb71b0e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,6 +64,47 @@ AC_CHECK_FUNCS(
 	rpmatch])
 AC_FUNC_FSEEKO
 
+dnl Static compilation
+m4_define([UTIL_STATIC_PROGRAMS], [losetup, mount, umount, fdisk, sfdisk])
+
+AC_ARG_ENABLE([static-programs],
+  [AS_HELP_STRING([--enable-static-programs=LIST],
+      [link static the programs in LIST (comma-separated,
+      supported for ]m4_defn([UTIL_STATIC_PROGRAMS])[)])])
+
+case $enable_static_programs in
+yes) enable_static_programs=m4_quote(UTIL_STATIC_PROGRAMS) ;;
+no) enable_static_programs= ;;
+esac
+
+if test "$enable_static_programs" != ""; then
+  AC_CACHE_CHECK([whether linker accepts -static],
+  [static_cv_option],
+  [SAVE_LDFLAGS="$LDFLAGS"
+   LDFLAGS="$LDFLAGS -static"
+   AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+#include <stdio.h>
+]], [[
+fflush(stdout);
+]])], [static_cv_option=yes],[static_cv_option=no])
+   LDFLAGS="$SAVE_LDFLAGS"
+  ])
+  if test "$static_cv_option" = "no"; then
+     AC_MSG_ERROR([the linker does not accept option -static])
+  fi
+fi
+AC_SUBST([LDFLAGS_STATIC], [-static])
+
+dnl Set all the individual AM_CONDITIONALs
+m4_foreach([UTIL_PRG], m4_defn([UTIL_STATIC_PROGRAMS]), [
+  case ,$enable_static_programs, in
+   *,UTIL_PRG,*) static_[]UTIL_PRG=yes ;;
+  esac
+  AM_CONDITIONAL([HAVE_STATIC_]m4_toupper(UTIL_PRG),
+    [test "$static_[]UTIL_PRG" = "yes"])
+])
+
+
 dnl UTIL_CHECK_LIB(LIBRARY, FUNCTION)
 dnl ---------------------------------
 AC_DEFUN([UTIL_CHECK_LIB], [
@@ -102,6 +143,22 @@ if test $have_blkid = no && test $have_volume_id = no; then
   AC_MSG_ERROR([blkid or volume_id is needed to build util-linux-ng.])
 fi
 
+# These default values should work in most cases:
+: ${BLKID_LIBS='-lblkid -luuid'}
+: ${VOLUMEID_LIBS='-lvolume_id'}
+
+# OTOH, the following two has little chance to succeed; please specify the
+# right values on the configure command-line:
+#
+: ${BLKID_LIBS_STATIC='$(BLKID_LIBS)'}
+: ${VOLUMEID_LIBS_STATIC='$(VOLUMEID_LIBS)'}
+
+AC_ARG_VAR([BLKID_LIBS], [-l options for linking dynamically with blkid])
+AC_ARG_VAR([BLKID_LIBS_STATIC], [-l options for linking statically with blkid])
+AC_ARG_VAR([VOLUMEID_LIBS], [-l options for linking dynamically with volume_id])
+AC_ARG_VAR([VOLUMEID_LIBS_STATIC], [-l options for linking statically with volume_id])
+
+
 AM_GNU_GETTEXT_VERSION([0.14.1])
 AM_GNU_GETTEXT([external])
 if test -d $srcdir/po
@@ -455,6 +512,12 @@ else
   esac
 fi
 
+if test "$have_selinux" = yes; then
+  SELINUX_LIBS="-lselinux -lsepol"
+  SELINUX_LIBS_STATIC="-lselinux -lsepol"
+fi
+AC_SUBST([SELINUX_LIBS])
+AC_SUBST([SELINUX_LIBS_STATIC])
 
 AC_ARG_WITH([audit],
   AS_HELP_STRING([--with-audit], [compile with audit support]),
diff --git a/fdisk/Makefile.am b/fdisk/Makefile.am
index 2246702..3b9dec5 100644
--- a/fdisk/Makefile.am
+++ b/fdisk/Makefile.am
@@ -14,12 +14,24 @@ fdisk_SOURCES = fdisk.c fdiskbsdlabel.c fdisksgilabel.c \
 	fdisk.h fdisksunlabel.h fdisksgilabel.h fdiskaixlabel.h \
 	fdiskbsdlabel.h fdiskmaclabel.h $(fdisk_common)
 
+if HAVE_STATIC_FDISK
+sbin_PROGRAMS += fdisk.static
+fdisk_static_SOURCES = $(fdisk_SOURCES)
+fdisk_static_LDFLAGS = $(LDFLAGS_STATIC)
+endif
+
 if !ARCH_SPARC
 
 sbin_PROGRAMS += sfdisk
 dist_man_MANS += sfdisk.8
 sfdisk_SOURCES = sfdisk.c partname.c $(fdisk_common)
 
+if HAVE_STATIC_SFDISK
+sbin_PROGRAMS += sfdisk.static
+sfdisk_static_SOURCES = $(sfdisk_SOURCES)
+sfdisk_static_LDFLAGS = $(LDFLAGS_STATIC)
+endif
+
 if USE_SLANG
 sbin_PROGRAMS += cfdisk
 dist_man_MANS += cfdisk.8
diff --git a/mount/Makefile.am b/mount/Makefile.am
index bba5962..a43fcd5 100644
--- a/mount/Makefile.am
+++ b/mount/Makefile.am
@@ -35,20 +35,45 @@ umount_LDADD = $(LDADD_common)
 swapon_LDADD = $(LDADD_common)
 
 LDADD_common =
+LDADD_common_static =
+
+if HAVE_STATIC_MOUNT
+bin_PROGRAMS += mount.static
+mount_static_SOURCES = $(mount_SOURCES)
+mount_static_LDFLAGS = $(LDFLAGS_STATIC)
+mount_static_LDADD = $(LDADD_common_static)
+endif
+
+if HAVE_STATIC_UMOUNT
+bin_PROGRAMS += umount.static
+umount_static_SOURCES = $(umount_SOURCES)
+umount_static_LDFLAGS = $(LDFLAGS_STATIC)
+umount_static_LDADD = $(LDADD_common_static)
+endif
+
+if HAVE_STATIC_LOSETUP
+bin_PROGRAMS += losetup.static
+losetup_static_SOURCES = $(losetup_SOURCES)
+losetup_static_LDFLAGS = $(LDFLAGS_STATIC)
+losetup_static_CPPFLAGS = -DMAIN $(AM_CPPFLAGS)
+endif
 
 if HAVE_BLKID
 utils_common += fsprobe_blkid.c
-LDADD_common += -lblkid -luuid
+LDADD_common += $(BLKID_LIBS)
+LDADD_common_static += $(BLKID_LIBS_STATIC)
 endif
 
 if HAVE_SELINUX
-mount_LDADD += -lselinux
+mount_LDADD += $(SELINUX_LIBS)
+mount_static_LDADD = $(SELINUX_LIBS_STATIC)
 endif
 
 if HAVE_VOLUME_ID
 utils_common += fsprobe_volumeid.c
 swapon_SOURCES += ../lib/linux_version.c ../lib/blkdev.c
-LDADD_common += -lvolume_id
+LDADD_common += $(VOLUMEID_LIBS)
+LDADD_common_static += $(VOLUMEID_LIBS_STATIC)
 endif
 
 if HAVE_PIVOT_ROOT
-- 
1.5.3.4

-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux