302212 Mac OS X x86 and Xcode 2.2/gcc 4.0.1 builds can't target SDKs. Use -isysroot and -Wl,-syslibroot with gcc 4.0.0, -isysroot only with gcc 4.0.1. Core r=josh r=cls sr=bryner, NSPR and NSS r=josh sr=wtchang, all portions a=bsmedberg for 1.8.1 and 1.8.0.1. MOZILLA_1_8_BRANCH
authormark%moxienet.com
Thu, 05 Jan 2006 15:40:16 +0000
branchMOZILLA_1_8_BRANCH
changeset 3526 f3ca530a5c2126546f4cae0733f35813f22f19b3
parent 3481 d17dd1306d3b59b86ec28ffb69dedeb3cdf0417e
child 3528 dbeb5c0b4c95c781b64ae5aabb99215ac72ed457
push idunknown
push userunknown
push dateunknown
reviewersjosh, cls, bryner, NSPR, josh, wtchang, all, bsmedberg
bugs302212
302212 Mac OS X x86 and Xcode 2.2/gcc 4.0.1 builds can't target SDKs. Use -isysroot and -Wl,-syslibroot with gcc 4.0.0, -isysroot only with gcc 4.0.1. Core r=josh r=cls sr=bryner, NSPR and NSS r=josh sr=wtchang, all portions a=bsmedberg for 1.8.1 and 1.8.0.1.
config/autoconf.mk.in
configure.in
pr/src/linking/Makefile.in
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -114,8 +114,15 @@ endif
 
 VISIBILITY_FLAGS = @VISIBILITY_FLAGS@
 WRAP_SYSTEM_INCLUDES = @WRAP_SYSTEM_INCLUDES@
 
 MACOSX_DEPLOYMENT_TARGET = @MACOSX_DEPLOYMENT_TARGET@
 ifdef MACOSX_DEPLOYMENT_TARGET
 export MACOSX_DEPLOYMENT_TARGET
 endif
+
+MACOS_SDK_DIR = @MACOS_SDK_DIR@
+
+NEXT_ROOT = @NEXT_ROOT@
+ifdef NEXT_ROOT
+export NEXT_ROOT
+endif
--- a/configure.in
+++ b/configure.in
@@ -15,16 +15,17 @@ dnl
 dnl The Initial Developer of the Original Code is Netscape
 dnl Communications Corporation.  Portions created by Netscape are 
 dnl Copyright (C) 1998o-2000 Netscape Communications Corporation.  All
 dnl Rights Reserved.
 dnl 
 dnl Contributor(s):
 dnl     Christopher Seawood <cls@seawood.org>
 dnl     Howard Chu <hyc@symas.com>
+dnl     Mark Mentovai <mark@moxienet.com>
 dnl 
 dnl Alternatively, the contents of this file may be used under the
 dnl terms of the GNU General Public License Version 2 or later (the
 dnl "GPL"), in which case the provisions of the GPL are applicable 
 dnl instead of those above.  If you wish to allow use of your 
 dnl version of this file only under the terms of the GPL and not to
 dnl allow others to use your version of this file under the MPL,
 dnl indicate your decision by deleting the provisions above and
@@ -64,16 +65,18 @@ MOZ_OPTIMIZE=
 OBJDIR=.
 OBJDIR_NAME=.
 OBJDIR_SUFFIX=OBJ
 NSINSTALL='$(MOD_DEPTH)/config/$(OBJDIR_NAME)/nsinstall'
 NOSUCHFILE=/no-such-file
 LIBNSPR='-L$(dist_libdir) -lnspr$(MOD_MAJOR_VERSION)'
 LIBPLC='-L$(dist_libdir) -lplc$(MOD_MAJOR_VERSION)'
 CYGWIN_WRAPPER=
+MACOS_SDK_DIR=
+NEXT_ROOT=
 
 dnl Link in libraries necessary to resolve all symbols for shared libs
 RESOLVE_LINK_SYMBOLS=
 
 dnl ========================================================
 dnl =
 dnl = Dont change the following lines.  Doing so breaks:
 dnl =
@@ -221,16 +224,23 @@ AC_ARG_ENABLE(64bit,
       fi ])
 
 AC_ARG_ENABLE(mdupdate,
     [  --enable-mdupdate       Enable use of certain compilers' mdupdate feature],
     [ if test "$enableval" = "yes"; then
 	    USE_MDUPDATE=1
       fi ])
 
+dnl ========================================================
+dnl = Mac OS X SDK support
+dnl ========================================================
+AC_ARG_WITH(macos-sdk,
+    [  --with-macos-sdk=dir    Location of platform SDK to use (Mac OS X only)],
+    MACOS_SDK_DIR=$withval)
+
 AC_ARG_ENABLE(macos-target,
              [  --enable-macos-target=VER
                           Set the minimum MacOS version needed at runtime
                           [10.1 for ppc, 10.4 for x86]],
              [_MACOSX_DEPLOYMENT_TARGET=$enableval])
 
 dnl ========================================================
 dnl =
@@ -912,23 +922,26 @@ case "$target" in
 
     ;;
 
 *-darwin*)
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(DARWIN)
     AC_DEFINE(HAVE_BSD_FLOCK)
     CFLAGS="$CFLAGS -Wmost -fno-common"
-    if echo $OS_TEST | grep -c 86 2>/dev/null; then
-        AC_DEFINE(i386)
-        CPU_ARCH=i386
-    else
-        AC_DEFINE(ppc)
-        CPU_ARCH=ppc
-    fi
+    case "${target_cpu}" in
+        i*86*)
+            AC_DEFINE(i386)
+            CPU_ARCH=i386
+            ;;
+        *)
+            AC_DEFINE(ppc)
+            CPU_ARCH=ppc
+            ;;
+    esac
     DSO_CFLAGS=-fPIC
     DSO_LDOPTS='-dynamiclib -compatibility_version 1 -current_version 1 -all_load -install_name @executable_path/$@ -headerpad_max_install_names'
     # Use the standard preprocessor (cpp)
     CFLAGS="$CFLAGS -no-cpp-precomp"
     MKSHLIB='$(CC) -arch $(CPU_ARCH) $(DSO_LDOPTS) -o $@'
     STRIP="$STRIP -x -S"
     DLL_SUFFIX=dylib
     USE_PTHREADS=1
@@ -956,62 +969,91 @@ case "$target" in
                     export MACOSX_DEPLOYMENT_TARGET=10.1
                     ;;
                 i*86*)
                     dnl Architecture minimum 10.4
                     export MACOSX_DEPLOYMENT_TARGET=10.4
                     ;;
             esac
         fi
-    fi
+
+        dnl MACOS_SDK_DIR will be set to the SDK location whenever one is
+        dnl in use.  NEXT_ROOT will be set and exported if it's needed for
+        dnl ld.
 
-    # do the right thing for SDK support
-    if test "$NEXT_ROOT"; then
-        dnl Synced to the MACOS_SDK_DIR block in Mozilla's top-level
-        dnl configure.in
+        if test "$MACOS_SDK_DIR"; then
+            dnl Sync this section with the one in Mozilla's top level.
+
+            if test ! -d "$MACOS_SDK_DIR"; then
+                AC_MSG_ERROR([SDK not found.  When using --with-macos-sdk, you must
+specify a valid SDK.  SDKs are installed when the optional cross-development
+tools are selected during the Xcode/Developer Tools installation.])
+            fi
 
-        dnl Current known valid versions for GCC_VERSION are 2.95.2 3.1 3.3 4.0.
-        dnl 4.0 identifies itself as 4.0.x, so strip the decidecimal for
-        dnl the environment and includedir purposes (when using an SDK, below),
-        dnl but remember the full version number for the libdir (SDK).
+            changequote(,)
+            CC_VERSION=`$CC -v 2>&1 | grep 'gcc version'`
+            GCC_VERSION_FULL=`echo $CC_VERSION | $PERL -pe 's/^.*gcc version ([^ ]*).*/$1/'`
+            GCC_VERSION=`echo $GCC_VERSION_FULL | $PERL -pe '(split(/\./))[0]>=4&&s/(^\d*\.\d*).*/$1/;'`
+            changequote([,])
+            GCC_VERSION_MAJOR=`echo $GCC_VERSION_FULL | $PERL -pe 's/(^\d*).*/$1/;'`
+            if test "$GCC_VERSION_MAJOR" -lt "4" ; then
+                SDK_C_FRAMEWORK="-F${MACOS_SDK_DIR}/System/Library/Frameworks"
+                if test -d "${MACOS_SDK_DIR}/Library/Frameworks" ; then
+                    SDK_C_FRAMEWORK="$SDK_C_FRAMEWORK -F${MACOS_SDK_DIR}/Library/Frameworks"
+                fi
 
-        changequote(,)
-        CC_VERSION=`$CC -v 2>&1 | grep 'gcc version'`
-        GCC_VERSION_FULL=`echo $CC_VERSION | $PERL -pe 's/^.*gcc version ([^ ]*).*/$1/'`
-        GCC_VERSION=`echo $GCC_VERSION_FULL | $PERL -pe '(split(/\./))[0]>=4&&s/(^\d*\.\d*).*/$1/;'`
-        changequote([,])
-        GCC_VERSION_MAJOR=`echo $GCC_VERSION_FULL | $PERL -pe 's/(^\d*).*/$1/;'`
+                SDK_C_INCLUDE="-isystem ${MACOS_SDK_DIR}/usr/include/gcc/darwin/${GCC_VERSION} -isystem ${MACOS_SDK_DIR}/usr/include ${SDK_C_FRAMEWORK}"
+
+                CFLAGS="$CFLAGS -nostdinc ${SDK_C_INCLUDE}"
+
+                dnl CPP needs to be set for AC_CHECK_HEADER.
+                CPP="$CPP -nostdinc ${SDK_C_INCLUDE}"
 
-        if test "$GCC_VERSION_MAJOR" -lt "4" ; then
-            dnl gcc < 4.0 only supports PowerPC, OK to hard-code
-            TARGET_ARCH_LIB="darwin"
-            TARGET_ARCH_INCLUDE="ppc-darwin"
-            SDK_C_INCLUDE="-isystem ${NEXT_ROOT}/usr/include/gcc/darwin/${GCC_VERSION} -isystem ${NEXT_ROOT}/usr/include -F${NEXT_ROOT}/System/Library/Frameworks"
-        else
-            dnl If gcc >= 4, use cpu-apple-darwin#, where # is the version
-            dnl of the Darwin release corresponding to the target Mac OS X
-            dnl release.  For OS X >= 10.1.1, take the minor version number and
-            dnl add 4 to get the Darwin major version number.  If it can't be 
-            dnl determined, use current Darwin major version number and hope
-            dnl that there's a symlink.
-            TARGET_ARCH_LIB=${target_cpu}-${target_vendor}-darwin`echo $NEXT_ROOT | $PERL -pe 's/MacOSX10\.([\d]*)//;if ($1) {$_=$1+4;} else {$_="'${target_os}'";s/(\d+)//;$_=$1;}'`
-            TARGET_ARCH_INCLUDE=$TARGET_ARCH_LIB
-            SDK_C_INCLUDE="-isystem ${NEXT_ROOT}/usr/lib/gcc/${TARGET_ARCH_LIB}/${GCC_VERSION_FULL}/include -isystem ${NEXT_ROOT}/usr/include -F${NEXT_ROOT}/System/Library/Frameworks"
+                dnl ld support for -syslibroot is compiler-agnostic, but only
+                dnl available on Tiger.  Although it's possible to switch on
+                dnl the build host's OS release to use ld -syslibroot when
+                dnl available, ld -syslibroot cause warnings as long as
+                dnl NEXT_ROOT is set.  NEXT_ROOT should be set because both
+                dnl both the compiler and linker use it.
+                dnl
+                dnl LDFLAGS is for the utilities built in config (now and
+                dnl nsinstall).  DSO_LDOPTS is used when linking shared
+                dnl libraries.
+                MACOS_SDK_LIBS="-L${MACOS_SDK_DIR}/usr/lib/gcc/darwin -L${MACOS_SDK_DIR}/usr/lib/gcc/darwin/${GCC_VERSION_FULL} -L${MACOS_SDK_DIR}/usr/lib ${SDK_C_FRAMEWORK}"
+                LDFLAGS="${MACOS_SDK_LIBS} $LDFLAGS"
+                DSO_LDOPTS="${MACOS_SDK_LIBS} $DSO_LDOPTS"
+                export NEXT_ROOT=$MACOS_SDK_DIR
+            else
+                dnl gcc >= 4.0 uses different paths than above, but knows
+                dnl how to find them itself.
+                CFLAGS="$CFLAGS -isysroot ${MACOS_SDK_DIR}"
+
+                dnl CPP needs to be set for AC_CHECK_HEADER.
+                CPP="$CPP -isysroot ${MACOS_SDK_DIR}"
+
+                dnl If gcc >= 4.0.0, we're guaranteed to be on Tiger, which
+                dnl has an ld that supports -syslibroot.  Don't set
+                dnl NEXT_ROOT because it will be ignored and cause
+                dnl warnings when -syslibroot is specified.
+                dnl
+                dnl Both LDFLAGS and DSO_LDOPTS are set here, see the
+                dnl gcc < 4.0 case for the explanation.
+                if test "$GCC_VERSION_FULL" != "4.0.0" ; then
+                    dnl gcc > 4.0.0 will pass -syslibroot to ld automatically
+                    dnl based on the -isysroot it receives.
+                    LDFLAGS="$LDFLAGS -isysroot ${MACOS_SDK_DIR}"
+                    DSO_LDOPTS="$DSO_LDOPTS -isysroot ${MACOS_SDK_DIR}"
+                else
+                    dnl gcc 4.0.0 doesn't pass -syslibroot to ld, it needs
+                    dnl to be explicit.
+                    LDFLAGS="$LDFLAGS -Wl,-syslibroot,${MACOS_SDK_DIR}"
+                    DSO_LDOPTS="$DSO_LDOPTS -Wl,-syslibroot,${MACOS_SDK_DIR}"
+                fi
+            fi
         fi
-
-        if test -d "${NEXT_ROOT}/Library/Frameworks" ; then
-            SDK_C_INCLUDE="$SDK_C_INCLUDE -F${NEXT_ROOT}/Library/Frameworks"
-        fi
-
-        CFLAGS="$CFLAGS -nostdinc ${SDK_C_INCLUDE}"
-
-        dnl CPP needs to be set for AC_CHECK_HEADER.
-        CPP="$CPP -nostdinc ${SDK_C_INCLUDE}"
-
-        OS_LIBS="-L${NEXT_ROOT}/usr/lib/gcc/${TARGET_ARCH_LIB} -L${NEXT_ROOT}/usr/lib/gcc/${TARGET_ARCH_LIB}/${GCC_VERSION_FULL} -L${NEXT_ROOT}/usr/lib $OS_LIBS"
     fi
     ;;
 
 *-dgux*)
     AC_DEFINE(XP_UNIX)
     AC_DEFINE(_PR_LOCAL_THREADS_ONLY)
     AC_DEFINE(SVR4)
     AC_DEFINE(SYSV)
@@ -2654,16 +2696,18 @@ AC_SUBST(OPTIMIZER)
 AC_SUBST(RC)
 AC_SUBST(RCFLAGS)
 AC_SUBST(DLLFLAGS)
 AC_SUBST(EXEFLAGS)
 AC_SUBST(OS_DLLFLAGS)
 AC_SUBST(CYGWIN_WRAPPER)
 AC_SUBST(VISIBILITY_FLAGS)
 AC_SUBST(WRAP_SYSTEM_INCLUDES)
+AC_SUBST(MACOS_SDK_DIR)
+AC_SUBST(NEXT_ROOT)
 
 dnl ========================================================
 dnl Generate output files.
 dnl ========================================================
 MAKEFILES="
 Makefile 
 config/Makefile
 config/autoconf.mk
--- a/pr/src/linking/Makefile.in
+++ b/pr/src/linking/Makefile.in
@@ -64,17 +64,17 @@ INCLUDES = -I$(dist_includedir) -I$(tops
 
 # For Dl_info and dladdr.
 ifeq ($(OS_TARGET),Linux)
 DEFINES    += -D_GNU_SOURCE
 endif
 
 # On Mac OS X use flat #includes.
 ifeq ($(OS_TARGET),MacOSX)
-INCLUDES    += -I$(NEXT_ROOT)/Developer/Headers/FlatCarbon
+INCLUDES    += -I$(MACOS_SDK_DIR)/Developer/Headers/FlatCarbon
 endif
 
 DEFINES += -D_NSPR_BUILD_
 
 include $(topsrcdir)/config/rules.mk
 
 export:: $(TARGETS)