]> granicus.if.org Git - sudo/commitdiff
Add support for installing a shared zlib
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 27 Oct 2014 20:39:07 +0000 (14:39 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 27 Oct 2014 20:39:07 +0000 (14:39 -0600)
INSTALL
configure
configure.ac
lib/zlib/Makefile.in
lib/zlib/zconf.h.in

diff --git a/INSTALL b/INSTALL
index b0a658d48fd04be086fc4df63c3aafcf4026279f..e19b08e1fabd2e85b80f63306b1de6063e17fb0b 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -206,11 +206,13 @@ Compilation options:
        Enable the use of the zlib compress library when storing
        I/O log files.  If specified, location is the base directory
        containing the zlib include and lib directories.  The special
-       values "system" and "builtin" can be used to indicate that
-       the system version of zlib should be used or that the version
-       of zlib shipped with sudo should be used instead.
-       If this option is not specified, configure will use the
-       system zlib if it is present.
+       values "system", "builtin", "shared" and "static" can be
+       used to indicate that the system version of zlib should be
+       used or that the version of zlib shipped with sudo should
+       be used instead.  If "static" is specified, sudo will
+       statically link the builtin zlib and not install it.  If
+       this option is not specified, configure will use the system
+       zlib if it is present, falling back on the sudo version.
 
   --with-incpath=DIR
        Adds the specified directory (or directories) to CPPFLAGS
index 32c44475c92be11ad370792a33bc241105fe7129..132ba04242db8b6fca60f7836356d90009558dc8 100755 (executable)
--- a/configure
+++ b/configure
@@ -784,6 +784,7 @@ LT_STATIC
 LT_LDEXPORTS
 LT_LDDEP
 LT_LDFLAGS
+ZLIB_LDFLAGS
 LIBUTIL_LDFLAGS
 SUDOERS_LDFLAGS
 LDFLAGS
@@ -2977,6 +2978,7 @@ $as_echo "$as_me: Configuring Sudo version $PACKAGE_VERSION" >&6;}
 
 
 
+
 
 
 #
@@ -19912,7 +19914,7 @@ fi
 
        ZLIB="-lz"
        ;;
-    builtin)
+    static|shared|builtin)
        # handled below
        ;;
     *)
        ZLIB="${ZLIB} -lz"
        ;;
 esac
-if test X"$enable_zlib" = X"builtin"; then
-    $as_echo "#define HAVE_ZLIB_H 1" >>confdefs.h
+case "$enable_zlib" in
+    builtin|static|dynamic)
+       $as_echo "#define HAVE_ZLIB_H 1" >>confdefs.h
 
-    CPPFLAGS='-I$(top_builddir)/lib/zlib -I$(top_srcdir)/lib/zlib '"${CPPFLAGS}"
-    ZLIB="${ZLIB}"' $(top_builddir)/lib/zlib/libz.la'
-    ZLIB_SRC=lib/zlib
-    ac_config_headers="$ac_config_headers lib/zlib/zconf.h"
+       CPPFLAGS='-I$(top_builddir)/lib/zlib -I$(top_srcdir)/lib/zlib '"${CPPFLAGS}"
+       ZLIB="${ZLIB}"' $(top_builddir)/lib/zlib/libsudo_z.la'
+       ZLIB_SRC=lib/zlib
+       ac_config_headers="$ac_config_headers lib/zlib/zconf.h"
 
-    ac_config_files="$ac_config_files lib/zlib/Makefile"
+       ac_config_files="$ac_config_files lib/zlib/Makefile"
 
-fi
+       if test X"$enable_shared" = X"no" -o "$enable_zlib" = "static"; then
+           if test "$enable_zlib" = "shared"; then
+               as_fn_error $? "\"Unable to build shared libraries on this system\"" "$LINENO" 5
+           fi
+           # Build as convenience library
+           ZLIB_LDFLAGS=-no-install
+       fi
+       ;;
+esac
 
 ac_fn_c_check_decl "$LINENO" "errno" "ac_cv_have_decl_errno" "
 $ac_includes_default
index 8a5892c765ea15ad8f47bc6dc6f27308516cd408..420ef4bdd3db2a71d039409264b0cc43a4707692 100644 (file)
@@ -22,6 +22,7 @@ AC_SUBST([CPPFLAGS])
 AC_SUBST([LDFLAGS])
 AC_SUBST([SUDOERS_LDFLAGS])
 AC_SUBST([LIBUTIL_LDFLAGS])
+AC_SUBST([ZLIB_LDFLAGS])
 AC_SUBST([LT_LDFLAGS])
 AC_SUBST([LT_LDDEP])
 AC_SUBST([LT_LDEXPORTS])
@@ -2903,7 +2904,7 @@ case "$enable_zlib" in
        AC_DEFINE(HAVE_ZLIB_H)
        ZLIB="-lz"
        ;;
-    builtin)
+    static|shared|builtin)
        # handled below
        ;;
     *)
@@ -2913,14 +2914,23 @@ case "$enable_zlib" in
        ZLIB="${ZLIB} -lz"
        ;;
 esac
-if test X"$enable_zlib" = X"builtin"; then
-    AC_DEFINE(HAVE_ZLIB_H)
-    CPPFLAGS='-I$(top_builddir)/lib/zlib -I$(top_srcdir)/lib/zlib '"${CPPFLAGS}"
-    ZLIB="${ZLIB}"' $(top_builddir)/lib/zlib/libz.la'
-    ZLIB_SRC=lib/zlib
-    AC_CONFIG_HEADER([lib/zlib/zconf.h])
-    AC_CONFIG_FILES([lib/zlib/Makefile])
-fi
+case "$enable_zlib" in
+    builtin|static|dynamic)
+       AC_DEFINE(HAVE_ZLIB_H)
+       CPPFLAGS='-I$(top_builddir)/lib/zlib -I$(top_srcdir)/lib/zlib '"${CPPFLAGS}"
+       ZLIB="${ZLIB}"' $(top_builddir)/lib/zlib/libsudo_z.la'
+       ZLIB_SRC=lib/zlib
+       AC_CONFIG_HEADER([lib/zlib/zconf.h])
+       AC_CONFIG_FILES([lib/zlib/Makefile])
+       if test X"$enable_shared" = X"no" -o "$enable_zlib" = "static"; then
+           if test "$enable_zlib" = "shared"; then
+               AC_MSG_ERROR(["Unable to build shared libraries on this system"])
+           fi
+           # Build as convenience library
+           ZLIB_LDFLAGS=-no-install
+       fi
+       ;;
+esac
 
 dnl
 dnl Check for errno declaration in errno.h
index ed7379aaeabbe2fe00619aed4675f9cba73a5fc4..bf493fa6989e6856a5ce4b33f755b19a5940b46e 100644 (file)
@@ -24,16 +24,56 @@ top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
 cross_compiling = @CROSS_COMPILING@
 
+# Where to install things...
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+bindir = @bindir@
+sbindir = @sbindir@
+sysconfdir = @sysconfdir@
+libexecdir = @libexecdir@
+datarootdir = @datarootdir@
+localstatedir = @localstatedir@
+
+# File extension, mode and map file to use for shared libraries/objects
+shlib_enable = @SHLIB_ENABLE@
+shlib_mode = @SHLIB_MODE@
+shlib_exp = ./zlib.exp
+shlib_map = zlib.map
+shlib_opt = zlib.opt
+
 # Compiler & tools to use
 CC = @CC@
 LIBTOOL = @LIBTOOL@
 
+# Our install program supports extra flags...
+INSTALL = $(SHELL) $(top_srcdir)/install-sh -c
+INSTALL_OWNER = -o $(install_uid) -g $(install_gid)
+
 # C preprocessor flags
 CPPFLAGS = -I. -I$(srcdir)
 
 # Usually -O and/or -g
 CFLAGS = @CFLAGS@
 
+# Flags to pass to the link stage
+LT_LDFLAGS = @ZLIB_LDFLAGS@
+LDFLAGS =
+
+# PIE flags
+PIE_CFLAGS = @PIE_CFLAGS@
+PIE_LDFLAGS = @PIE_LDFLAGS@
+
+# Stack smashing protection flags
+SSP_CFLAGS = @SSP_CFLAGS@
+SSP_LDFLAGS = @SSP_LDFLAGS@
+
+# Libtool style shared library version
+SHLIB_VERSION = 0:0:0
+
+# User and group ids the installed files should be "owned" by
+install_uid = 0
+install_gid = 0
+
 # OS dependent defines
 DEFS = @OSDEFS@
 
@@ -45,7 +85,7 @@ LTOBJS = adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzlib.lo \
         gzread.lo gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo \
         trees.lo uncompr.lo zutil.lo
 
-all: libz.la
+all: libsudo_z.la
 
 Makefile: $(srcdir)/Makefile.in
        (cd $(top_builddir) && ./config.status --file lib/zlib/Makefile)
@@ -53,14 +93,31 @@ Makefile: $(srcdir)/Makefile.in
 .SUFFIXES: .c .h .lo
 
 .c.lo:
-       $(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(DEFS) $<
+       $(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $<
+
+$(shlib_map): $(shlib_exp)
+       @awk 'BEGIN { print "{\n\tglobal:" } { print "\t\t"$$0";" } END { print "\tlocal:\n\t\t*;\n};" }' $(shlib_exp) > $@
+
+$(shlib_opt): $(shlib_exp)
+       @$(SED) 's/^/+e /' $(shlib_exp) > $@
 
-libz.la: $(LTOBJS)
-       $(LIBTOOL) --mode=link $(CC) -o $@ $(LTOBJS) -no-install
+libsudo_z.la: $(LTOBJS)
+       case "$(LT_LDFLAGS)" in \
+       *-no-install*) \
+           $(LIBTOOL) --mode=link $(CC) -o $@ $(LDFLAGS) $(LT_LDFLAGS) $(LTOBJS);; \
+       *) \
+           $(LIBTOOL) --mode=link $(CC) -o $@ $(LDFLAGS) $(LT_LDFLAGS) $(LTOBJS) -version-info $(SHLIB_VERSION) -rpath $(libexecdir)/sudo;; \
+       esac
 
 pre-install:
 
 install:
+       case "$(LT_LDFLAGS)" in \
+       *-no-install*) ;; \
+       *)  if [ X"$(shlib_enable)" = X"yes" ]; then \
+               INSTALL_BACKUP='~' $(LIBTOOL) --quiet --mode=install $(INSTALL) $(INSTALL_OWNER) libsudo_z.la $(DESTDIR)$(libexecdir)/sudo; \
+           fi;; \
+       esac
 
 install-dirs:
 
@@ -73,6 +130,7 @@ install-doc:
 install-plugin:
 
 uninstall:
+       $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libexecdir)/sudo/libsudo_z.la
 
 cppcheck:
 
index e14d0190642992cfa3afa4e1bb7a402eba3286ef..aab2a65a0ac5d77a13d825e6c82e9b2391d1b9cc 100644 (file)
@@ -9,13 +9,27 @@
 #define ZCONF_H
 
 /* The following four defines are enabled by sudo's configure script. */
+#undef HAVE_DSO_VISIBILITY
+#undef HAVE_MEMCPY
 #undef HAVE_UNISTD_H
 #undef HAVE_VSNPRINTF
-#undef HAVE_MEMCPY
 #undef _FILE_OFFSET_BITS
 #undef _LARGE_FILES
 #undef const
 
+/* We build sudo and its libs with -fvisibility=hidden where supported. */
+#ifdef HAVE_DSO_VISIBILITY
+# if defined(__GNUC__)
+#  define ZEXTERN extern __attribute__((__visibility__("default")))
+# elif defined(__SUNPRO_C)
+#  define ZEXTERN extern __global
+# elif defined(ZLIB_INTERNAL)
+#  define ZEXTERN extern __declspec(dllexport)
+# else
+#  define ZEXTERN extern __declspec(dllimport)
+# endif
+#endif
+
 /*
  * If you *really* need a unique prefix for all types and library functions,
  * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.