Support for making DLL correctly on Cygwin
authorEric Biggers <ebiggers3@gmail.com>
Sat, 9 Mar 2013 19:51:59 +0000 (13:51 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 9 Mar 2013 19:51:59 +0000 (13:51 -0600)
Makefile.am
configure.ac
src/util.h

index 1e545bb..9f45562 100644 (file)
@@ -7,7 +7,7 @@ AM_CFLAGS       = -std=gnu99 -D_LARGEFILE_SOURCE \
 
 lib_LTLIBRARIES = libwim.la
 
-libwim_la_LDFLAGS = -version-info 4:0:2
+libwim_la_LDFLAGS = -version-info 4:0:2 $(CYGWIN_EXTRA_LDFLAGS)
 
 libwim_la_SOURCES =            \
        src/add_image.c         \
@@ -86,7 +86,7 @@ libwim_la_LIBADD =            \
 
 libwim_la_CFLAGS =             \
        $(AM_CFLAGS)            \
-       -fvisibility=hidden     \
+       $(VISIBILITY_CFLAGS)    \
        $(LIBXML2_CFLAGS)       \
        $(LIBFUSE_CFLAGS)       \
        $(LIBNTFS_3G_CFLAGS)    \
index 3b02ef8..c0c0f13 100644 (file)
@@ -323,4 +323,22 @@ AC_SUBST([LIBCRYPTO_LDADD], [$LIBCRYPTO_LDADD])
 AC_SUBST([LIBCRYPTO_CFLAGS], [$LIBCRYPTO_CFLAGS])
 AC_SUBST([SHA1_SOURCES], [$SHA1_SOURCES])
 
+case "$host" in
+       *-*-cygwin*)
+               dnl -no-undefined is needed to build a DLL in a Cygwin environment.
+               CYGWIN_EXTRA_LDFLAGS="-no-undefined"
+
+               dnl -fvisibility=hidden should not be used in a Cygwin
+               dnl  environment
+               VISIBILITY_CFLAGS=""
+               ;;
+       *)
+               CYGWIN_EXTRA_LDFLAGS=""
+               VISIBILITY_CFLAGS="-fvisibility=hidden"
+               ;;
+esac
+
+AC_SUBST([CYGWIN_EXTRA_LDFLAGS], [$CYGWIN_EXTRA_LDFLAGS])
+AC_SUBST([VISIBILITY_CFLAGS], [$VISIBILITY_CFLAGS])
+
 AC_OUTPUT
index 4f40566..b79490e 100644 (file)
@@ -9,7 +9,11 @@
 #include "config.h"
 
 #ifdef __GNUC__
-#      define WIMLIBAPI __attribute__((visibility("default")))
+#      if defined(__CYGWIN__) || defined(__WIN32__)
+#              define WIMLIBAPI __declspec(dllexport)
+#      else
+#              define WIMLIBAPI __attribute__((visibility("default")))
+#      endif
 #      define ALWAYS_INLINE inline __attribute__((always_inline))
 #      define PACKED __attribute__((packed))
 #      define FORMAT(type, format_str, args_start) \