From 90cf81e686da14a30955e281baacc6bd4b22525f Mon Sep 17 00:00:00 2001 From: psychon Date: Wed, 22 Oct 2008 19:40:51 +0000 Subject: [PATCH] Make ZNC compile on Mac OS out of the box Thanks to ashikase for pointing out the needed linker and compiler flags. Thanks to GiZMo for testing on his mac 10.5.4. This also cleans up configure.in a little by adding appendMod. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1258 726aef4b-f618-498e-8847-2d620e286838 --- configure | 42 ++++++++++++++++++++++++++++++++++++------ configure.in | 35 ++++++++++++++++++++++++++++++----- modules/Makefile.in | 3 ++- znc-config.in | 4 ++++ 4 files changed, 72 insertions(+), 12 deletions(-) diff --git a/configure b/configure index 5a43bca7..34ec7e85 100755 --- a/configure +++ b/configure @@ -630,6 +630,8 @@ host_cpu host_vendor host_os MODFLAGS +MODULES +MODLINK MODTARGET NOSSL PERL @@ -2426,6 +2428,14 @@ appendCXX () { fi } +appendMod () { + if test "$MODFLAGS" != ""; then + MODFLAGS="$MODFLAGS $*" + else + MODFLAGS=$* + fi +} + appendLD () { if test "$LDFLAGS" != ""; then LDFLAGS="$LDFLAGS $*" @@ -2440,7 +2450,7 @@ case "${host_os}" in freebsd*) appendCXX -I/usr/local/include appendLib -L/usr/local/lib -lcompat - MODFLAGS="$MODFLAGS -L/usr/local/lib" + appendMod -L/usr/local/lib ;; solaris*) appendLib -lsocket -lnsl @@ -2449,6 +2459,9 @@ case "${host_os}" in cygwin) ISCYGWIN=1 ;; + darwin*) + ISDARWIN=1 + ;; esac # cygwin @@ -3055,15 +3068,28 @@ echo "$as_me: error: could not find dlopen. Try --disable-modules" >&2;} fi appendCXX -D_MODULES - MODFLAGS="$MODFLAGS $CXXFLAGS" - if test -z "$ISSUN"; then + appendMod "$CXXFLAGS" + + if test -z "$ISSUN" -a -z "$ISDARWIN"; then + # This is an unknown compiler flag on some OS appendLD -Wl,--export-dynamic fi MODTARGET="modules" - # FIXME why don't we do this for sun? + # FIXME why do we need this for sun? if test -n "$ISSUN"; then - MODFLAGS="$MODFLAGS -mimpure-text" + appendMod -mimpure-text + fi + + if test -z "$ISDARWIN"; then + MODLINK="-shared" + else + # Mac OS X differentiates between shared libs (-dynamiclib) + # and loadable modules (-bundle). + MODLINK="-bundle -flat_namespace -undefined suppress" + # TODO test if -twolevel_namespace and/or + # -undefined dynamic_lookup work + # (dynamic_lookup might only work on 10.4 and later) fi appendCXX "-D_MODDIR_=\\\"${MODDIR}\\\"" @@ -3241,6 +3267,8 @@ fi + + ac_config_files="$ac_config_files Makefile" ac_config_files="$ac_config_files znc-config" @@ -3938,6 +3966,8 @@ host_cpu!$host_cpu$ac_delim host_vendor!$host_vendor$ac_delim host_os!$host_os$ac_delim MODFLAGS!$MODFLAGS$ac_delim +MODULES!$MODULES$ac_delim +MODLINK!$MODLINK$ac_delim MODTARGET!$MODTARGET$ac_delim NOSSL!$NOSSL$ac_delim PERL!$PERL$ac_delim @@ -3948,7 +3978,7 @@ LIBOBJS!$LIBOBJS$ac_delim LTLIBOBJS!$LTLIBOBJS$ac_delim _ACEOF - if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 61; then + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 63; then break elif $ac_last_try; then { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 diff --git a/configure.in b/configure.in index c16b2466..ea6f8002 100644 --- a/configure.in +++ b/configure.in @@ -24,6 +24,14 @@ appendCXX () { fi } +appendMod () { + if test "$MODFLAGS" != ""; then + MODFLAGS="$MODFLAGS $*" + else + MODFLAGS=$* + fi +} + appendLD () { if test "$LDFLAGS" != ""; then LDFLAGS="$LDFLAGS $*" @@ -38,7 +46,7 @@ case "${host_os}" in freebsd*) appendCXX -I/usr/local/include appendLib -L/usr/local/lib -lcompat - MODFLAGS="$MODFLAGS -L/usr/local/lib" + appendMod -L/usr/local/lib ;; solaris*) appendLib -lsocket -lnsl @@ -47,6 +55,9 @@ case "${host_os}" in cygwin) ISCYGWIN=1 ;; + darwin*) + ISDARWIN=1 + ;; esac # cygwin @@ -159,15 +170,28 @@ if test "$MODULES" = "yes"; then fi appendCXX -D_MODULES - MODFLAGS="$MODFLAGS $CXXFLAGS" - if test -z "$ISSUN"; then + appendMod "$CXXFLAGS" + + if test -z "$ISSUN" -a -z "$ISDARWIN"; then + # This is an unknown compiler flag on some OS appendLD -Wl,--export-dynamic fi MODTARGET="modules" - # FIXME why don't we do this for sun? + # FIXME why do we need this for sun? if test -n "$ISSUN"; then - MODFLAGS="$MODFLAGS -mimpure-text" + appendMod -mimpure-text + fi + + if test -z "$ISDARWIN"; then + MODLINK="-shared" + else + # Mac OS X differentiates between shared libs (-dynamiclib) + # and loadable modules (-bundle). + MODLINK="-bundle -flat_namespace -undefined suppress" + # TODO test if -twolevel_namespace and/or + # -undefined dynamic_lookup work + # (dynamic_lookup might only work on 10.4 and later) fi appendCXX "-D_MODDIR_=\\\"${MODDIR}\\\"" @@ -202,6 +226,7 @@ AC_SUBST([CPPFLAGS]) AC_SUBST([MODFLAGS]) AC_SUBST([LDFLAGS]) AC_SUBST([LIBS]) +AC_SUBST([MODLINK]) AC_SUBST([MODTARGET]) AC_SUBST([NOSSL]) AC_SUBST([PERL]) diff --git a/modules/Makefile.in b/modules/Makefile.in index 597a26d1..683dbe3e 100644 --- a/modules/Makefile.in +++ b/modules/Makefile.in @@ -14,6 +14,7 @@ localstatedir := @localstatedir@ CXX := @CXX@ # CXXFLAGS are for the main binary, so don't use them here, use MODFLAGS instead MODFLAGS := @CPPFLAGS@ @MODFLAGS@ -I$(srcdir)/.. +MODLINK := @MODLINK@ LDFLAGS := @LDFLAGS@ # LIBS are not and should not be used in here. # The znc binary links already against those. @@ -75,7 +76,7 @@ clean: %.so: %.cpp Makefile @mkdir -p .depend - $(CXX) $(MODFLAGS) $(LDFLAGS) -shared -o $@ $< $($(basename $@)FLAGS) -MMD -MF .depend/$@.dep + $(CXX) $(MODFLAGS) $(LDFLAGS) $(MODLINK) -o $@ $< $($(basename $@)FLAGS) -MMD -MF .depend/$@.dep modperl_install: create_install_dir for i in $(srcdir)/*.pm; do \ diff --git a/znc-config.in b/znc-config.in index 0d941b68..dd6e2715 100755 --- a/znc-config.in +++ b/znc-config.in @@ -8,6 +8,7 @@ datadir="@datadir@" CXX="@CXX@" CXXFLAGS="@CPPFLAGS@ @MODFLAGS@ -I@prefix@/include/znc" +MODLINK="@MODLINK@" # LIBS="@LIBS@" # No libs needed, ZNC links against $LIBS and thus modules don't need to. LIBS="" @@ -19,6 +20,7 @@ if test -z "$1"; then echo "USAGE: $0 " echo " --cxx [$CXX]" echo " --cflags [$CXXFLAGS]" + echo " --modlink [$MODLINK]" echo " --libs [$LIBS]" echo " --moddir [$MODDIR]" echo " --datadir [$DATADIR]" @@ -32,6 +34,8 @@ case $1 in echo $CXX;; --cflags) echo $CXXFLAGS;; + --modlink) + echo $MODLINK;; --include) # Left here for backwards compatibility ;;