changeset 29239:f6058c6e1b18

Visibility: Compile with visibility attributes for Windows (patch #8919). * configure.ac: Remove flag for exporting all symbols. Use DEF file with exported Fortran symbols for all compilers for Windows targets. * m4/acinclude.m4, build-aux/mk-octave-config-h.sh: Define macro for exporting symbols for all compilers for Windows platform. * oct-conf-post.in.h: Set attribute for visibility according to compiler.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 26 Dec 2020 10:07:32 +0100
parents cd6b616b36a8
children 0a6ed9dcd601
files build-aux/mk-octave-config-h.sh configure.ac m4/acinclude.m4 oct-conf-post.in.h
diffstat 4 files changed, 34 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/build-aux/mk-octave-config-h.sh	Wed Dec 16 01:05:17 2020 -0500
+++ b/build-aux/mk-octave-config-h.sh	Sat Dec 26 10:07:32 2020 +0100
@@ -182,11 +182,18 @@
 #    define octave_unused_parameter(param) (void) param;
 #  endif
 
-#  if defined (_MSC_VER)
-#    define OCTAVE_EXPORT __declspec(dllexport)
-#    define OCTAVE_IMPORT __declspec(dllimport)
+#  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
-     /* All other compilers, at least for now. */
+     /* All other platforms. */
 #    define OCTAVE_EXPORT __attribute__ ((visibility ("default")))
 #    define OCTAVE_IMPORT
 #  endif
--- a/configure.ac	Wed Dec 16 01:05:17 2020 -0500
+++ b/configure.ac	Sat Dec 26 10:07:32 2020 +0100
@@ -626,10 +626,12 @@
 AC_SUBST(STATIC_LIBS)
 
 XTRA_EXTERNAL_SH_LDFLAGS=
-if test $have_msvc = yes; then
-  FLIBS="$FLIBS -lkernel32"
-  XTRA_EXTERNAL_SH_LDFLAGS="-Wl,external/external.def"
-fi
+case $host_os in
+  msdosmsvc | mingw*)
+    FLIBS="$FLIBS -lkernel32"
+    XTRA_EXTERNAL_SH_LDFLAGS="-Wl,liboctave/external/external.def"
+  ;;
+esac
 AC_SUBST(XTRA_EXTERNAL_SH_LDFLAGS)
 
 if test $STATIC_LIBS = no && test $SHARED_LIBS = no; then
@@ -2488,7 +2490,6 @@
         else
           JAVA_CPPFLAGS="-I\"${JAVA_HOME}/include\" -I\"${JAVA_HOME}/include/win32\""
         fi
-        LDFLAGS="$LDFLAGS -Wl,--export-all-symbols"
       fi
       AC_DEFINE(HAVE_JAVA, 1,
         [Define to 1 if Java is available and is at least version 1.5])
--- a/m4/acinclude.m4	Wed Dec 16 01:05:17 2020 -0500
+++ b/m4/acinclude.m4	Sat Dec 26 10:07:32 2020 +0100
@@ -2955,12 +2955,6 @@
         fi
         NO_OCT_FILE_STRIP=true
         library_path_var=PATH
-        ## Extra compilation flags.
-        EXTERNAL_DLL_DEFS="-DEXTERNAL_DLL"
-        OCTAVE_DLL_DEFS="-DOCTAVE_DLL"
-        OCTINTERP_DLL_DEFS="-DOCTINTERP_DLL"
-        OCTGUI_DLL_DEFS="-DOCTGUI_DLL"
-        OCTGRAPHICS_DLL_DEFS="-DOCTGRAPHICS_DLL"
       else
         CPICFLAG=
         CXXPICFLAG=
@@ -2969,6 +2963,12 @@
         SH_LDFLAGS="-shared -Wl,--export-all-symbols -Wl,--enable-auto-import -Wl,--enable-auto-image-base"
         library_path_var=PATH
       fi
+      ## Extra compilation flags.
+      EXTERNAL_DLL_DEFS="-DEXTERNAL_DLL"
+      OCTAVE_DLL_DEFS="-DOCTAVE_DLL"
+      OCTINTERP_DLL_DEFS="-DOCTINTERP_DLL"
+      OCTGUI_DLL_DEFS="-DOCTGUI_DLL"
+      OCTGRAPHICS_DLL_DEFS="-DOCTGRAPHICS_DLL"
     ;;
     *-*-msdosmsvc)
       DL_LDFLAGS="-shared"
--- a/oct-conf-post.in.h	Wed Dec 16 01:05:17 2020 -0500
+++ b/oct-conf-post.in.h	Sat Dec 26 10:07:32 2020 +0100
@@ -170,14 +170,18 @@
 
 /* oct-dlldefs.h */
 
-/* FIXME: GCC supports visibility attributes as well, even using the
-   same __declspec declaration if desired.  The build system should be
-   extended to support GCC and visibility attributes.  */
-#if defined (_MSC_VER)
-#  define OCTAVE_EXPORT __declspec(dllexport)
-#  define OCTAVE_IMPORT __declspec(dllimport)
+#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
-   /* All other compilers, at least for now. */
+   /* All other platforms. */
 #  define OCTAVE_EXPORT __attribute__ ((visibility ("default")))
 #  define OCTAVE_IMPORT
 #endif