changeset 29313:6dea3b384846

Optionally disable building libraries with visibility attributes (bug #59820). * configure.ac: Add argument --disable-lib-visibility-flags to manually disable building and linking Octave libraries with visibility attributes. * Makefile.am: Use compiler flags for symbol visibility according to configure result. * oct-conf-post.in.h, build-aux/mk-octave-config-h.sh: Set preprocessor macros with visibility attributes to empty optionally.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 23 Jan 2021 10:54:47 +0100
parents 875d799ab0b3
children 960ea0ccff98
files Makefile.am build-aux/mk-octave-config-h.sh configure.ac oct-conf-post.in.h
diffstat 4 files changed, 64 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.am	Sat Jan 23 11:27:46 2021 +0100
+++ b/Makefile.am	Sat Jan 23 10:54:47 2021 +0100
@@ -44,13 +44,17 @@
 
 AM_YFLAGS = -dv ${WARN_YFLAGS}
 
+if AMCOND_LIB_VISIBILITY_FLAGS
+  OCTAVE_VISIBILITY_FLAGS = ${CFLAG_VISIBILITY}
+endif
+
 # Fortran compiler flags.
 
-AM_FFLAGS = ${FPICFLAG} @FFLAGS@ ${CFLAG_VISIBILITY}
+AM_FFLAGS = ${FPICFLAG} @FFLAGS@ $(OCTAVE_VISIBILITY_FLAGS)
 
 # C compiler flags.
 
-AM_CFLAGS = ${CPICFLAG} ${XTRA_CFLAGS} ${WARN_CFLAGS} ${CFLAG_VISIBILITY}
+AM_CFLAGS = ${CPICFLAG} ${XTRA_CFLAGS} ${WARN_CFLAGS} $(OCTAVE_VISIBILITY_FLAGS)
 
 # ifeq (${INCLUDE_DEPS},no)
 #   omit_deps = true;
@@ -58,7 +62,7 @@
 
 # C++ compiler flags.
 
-AM_CXXFLAGS = ${CXXPICFLAG} ${XTRA_CXXFLAGS} ${WARN_CXXFLAGS} ${CFLAG_VISIBILITY}
+AM_CXXFLAGS = ${CXXPICFLAG} ${XTRA_CXXFLAGS} ${WARN_CXXFLAGS} $(OCTAVE_VISIBILITY_FLAGS)
 
 FFTW_XCPPFLAGS = @FFTW_XCPPFLAGS@
 FFTW_XLDFLAGS = @FFTW_XLDFLAGS@
--- a/build-aux/mk-octave-config-h.sh	Sat Jan 23 11:27:46 2021 +0100
+++ b/build-aux/mk-octave-config-h.sh	Sat Jan 23 10:54:47 2021 +0100
@@ -182,20 +182,25 @@
 #    define octave_unused_parameter(param) (void) param;
 #  endif
 
-#  if defined (_WIN32) || defined (__CYGWIN__)
-#    if defined (__GNUC__)
-       /* GCC */
-#      define OCTAVE_EXPORT __attribute__ ((dllexport))
-#      define OCTAVE_IMPORT __attribute__ ((dllimport))
+#  if defined (OCTAVE_ENABLE_LIB_VISIBILITY_FLAGS)
+#    if defined (_WIN32) || defined (__CYGWIN__)
+#      if defined (__GNUC__)
+         /* GCC */
+#        define OCTAVE_EXPORT __attribute__ ((dllexport))
+#        define OCTAVE_IMPORT __attribute__ ((dllimport))
+#      else
+         /* MSVC */
+#        define OCTAVE_EXPORT __declspec(dllexport)
+#        define OCTAVE_IMPORT __declspec(dllimport)
+#      endif
 #    else
-       /* MSVC */
-#      define OCTAVE_EXPORT __declspec(dllexport)
-#      define OCTAVE_IMPORT __declspec(dllimport)
+       /* All other platforms. */
+#      define OCTAVE_EXPORT __attribute__ ((visibility ("default")))
+#      define OCTAVE_IMPORT
 #    endif
 #  else
-     /* All other platforms. */
-#    define OCTAVE_EXPORT __attribute__ ((visibility ("default")))
-#    define OCTAVE_IMPORT
+#      define OCTAVE_EXPORT
+#      define OCTAVE_IMPORT
 #  endif
 
 /* API macro for liboctave */
--- a/configure.ac	Sat Jan 23 11:27:46 2021 +0100
+++ b/configure.ac	Sat Jan 23 10:54:47 2021 +0100
@@ -2680,6 +2680,32 @@
   [if test "$enableval" = yes; then install_build_logs=yes; fi])
 AM_CONDITIONAL([AMCOND_INSTALL_BUILD_LOGS], [test $install_build_logs = yes])
 
+### Determine whether libraries should be linked with visibility attributes
+
+ENABLE_LIB_VISIBILITY_FLAGS=yes
+AC_ARG_ENABLE(lib-visibility-flags,
+  [AS_HELP_STRING([--disable-lib-visibility-flags],
+    [don't build libraries with visibility flags (export all symbols)])],
+  [case $enableval in
+     yes) ENABLE_LIB_VISIBILITY_FLAGS=yes ;;
+     no) ENABLE_LIB_VISIBILITY_FLAGS=no ;;
+     *) AC_MSG_ERROR([bad value $enableval for --enable-lib-visibility-flags]) ;;
+   esac])
+
+if test $ENABLE_LIB_VISIBILITY_FLAGS = yes; then
+  AC_DEFINE(OCTAVE_ENABLE_LIB_VISIBILITY_FLAGS, 1,
+    [Define to 1 if building libraries with visibility flags])
+else
+  case $host_os in
+    msdosmsvc | mingw* | cygwin*)
+      LDFLAGS="$LDFLAGS -Wl,--export-all-symbols"
+    ;;
+  esac
+fi
+
+AM_CONDITIONAL([AMCOND_LIB_VISIBILITY_FLAGS],
+  [test $ENABLE_LIB_VISIBILITY_FLAGS = yes])
+
 ### Add extra compiler flags now that feature testing is complete.
 
 ## Add warning flags
--- a/oct-conf-post.in.h	Sat Jan 23 11:27:46 2021 +0100
+++ b/oct-conf-post.in.h	Sat Jan 23 10:54:47 2021 +0100
@@ -170,19 +170,24 @@
 
 /* oct-dlldefs.h */
 
-#if defined (_WIN32) || defined (__CYGWIN__)
-#  if defined (__GNUC__)
-     /* GCC */
-#    define OCTAVE_EXPORT __attribute__ ((dllexport))
-#    define OCTAVE_IMPORT __attribute__ ((dllimport))
+#if defined (OCTAVE_ENABLE_LIB_VISIBILITY_FLAGS)
+#  if defined (_WIN32) || defined (__CYGWIN__)
+#    if defined (__GNUC__)
+       /* GCC */
+#      define OCTAVE_EXPORT __attribute__ ((dllexport))
+#      define OCTAVE_IMPORT __attribute__ ((dllimport))
+#    else
+       /* MSVC */
+#      define OCTAVE_EXPORT __declspec(dllexport)
+#      define OCTAVE_IMPORT __declspec(dllimport)
+#    endif
 #  else
-     /* MSVC */
-#    define OCTAVE_EXPORT __declspec(dllexport)
-#    define OCTAVE_IMPORT __declspec(dllimport)
+     /* All other platforms. */
+#    define OCTAVE_EXPORT __attribute__ ((visibility ("default")))
+#    define OCTAVE_IMPORT
 #  endif
 #else
-   /* All other platforms. */
-#  define OCTAVE_EXPORT __attribute__ ((visibility ("default")))
+#  define OCTAVE_EXPORT
 #  define OCTAVE_IMPORT
 #endif