From 86a83a3462d610c28863fa77477a1fef0b51fd09 Mon Sep 17 00:00:00 2001 From: Ian MacLarty Date: Thu, 23 Dec 2004 04:19:36 +0000 Subject: [PATCH] Fix linking error for hlc.par.gc grade on Darwin. Estimated hours taken: 3 Branches: main Fix linking error for hlc.par.gc grade on Darwin. The problem was that the "-undefined suppress" option is not allowed with two level namespaces. The solution is to use "-undefined dynamic_lookup" instead. However this means the MACOSX_DEPLOYMENT_TARGET environment variable must be set to 10.3 since this feature will not work on Mac OS < 10.3. To allow hlc.gc.par to be built on Mac 10.3, but targetted for Mac OS 10.0 - 10.2 add a configuration option to force the use of flat namespaces (the "-undefined suppress" option may be used with flat namespaces). configure.in Add --enable-darwin-flat-namespace option. This is the default for Mac OS < 10.3. For Mac OS 10.3 two level namespaces are used unless this option is given. Set a variable to cause the MACOSX_DEPLOYMENT_TARGET environment variable to be set if two level namespaces are being used. scripts/mmake.in scripts/ml.in scripts/mmc.in Set the MACOSX_DEPLOYMENT_TARGET environment variable wherever the linker may be called. --- configure.in | 51 ++++++++++++++++++++++++++++++++++++++++++------ scripts/ml.in | 3 +++ scripts/mmake.in | 3 +++ scripts/mmc.in | 5 ++++- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/configure.in b/configure.in index 3663ce3a5..77b7107a5 100644 --- a/configure.in +++ b/configure.in @@ -2591,8 +2591,7 @@ AC_ARG_ENABLE(libgrades, [ --enable-libgrades=... install exactly the given versions of the library. The versions are specified using a comma-separated - list. -], + list.], enable_libgrades_given=yes;enable_libgrades="$enableval",enable_libgrades_given=no) if test "$enable_most_grades" = no; then @@ -3227,16 +3226,56 @@ case "$host" in # If the compiler is gcc then use darwin style dynamic linking. # Otherwise use static linking. if test "$GCC_PROG" != ""; then + AC_MSG_RESULT(yes) + # Check if the user has explicitly requested that flat + # namespaces be used. + darwin_flat_namespaces=no + AC_ARG_ENABLE(darwin-flat-namespace, + [ --enable-darwin-flat-namespace + enable flat namespaces on Darwin. This is the + default for Darwin versions less than 7 (Mac OS + 10.3). On versions greater than or equal to 7 + two-level namespaces are used by default. This + option therefore only affects Darwin versions + greater than or equal to 7.], + [ darwin_flat_namespaces=yes ]) SHLIB_USE_INSTALL_NAME="--shlib-linker-use-install-name" SHLIB_INSTALL_NAME_FLAG="-install_name " - LINK_SHARED_OBJ="$GCC_PROG -dynamiclib -single_module" - LINK_SHARED_OBJ_SH="$GCC_PROG -dynamiclib -single_module" EXT_FOR_SHARED_LIB=dylib EXT_FOR_LINK_WITH_PIC_OBJECTS=o CFLAGS_FOR_PIC="-fPIC -DMR_PIC" ERROR_UNDEFINED="-undefined error" - ALLOW_UNDEFINED="-undefined suppress" - AC_MSG_RESULT(yes) + # Test if the Darwin version is >= 7. If it is + # then we can use the -undefined dynamic_lookup option + # and two-level namespaces. If it isn't then we use + # flat namespaces. + AC_MSG_CHECKING(whether to use two-level namespaces) + if uname -r | sed "s/^\(@<:@0-9@:>@*\)\..*$/\1/" | \ + xargs test "$darwin_flat_namespaces" != "yes" \ + -a 7 -le; + then + AC_MSG_RESULT(yes) + # The MACOSX_DEPLOYMENT_TARGET environment variable + # needs to be set when linking with two level + # namespaces so we can use the + # `-undefined dynamic_lookup' option. + SET_MACOSX_DEPLOYMENT_TARGET="\ + MACOSX_DEPLOYMENT_TARGET=10.3; \ + export MACOSX_DEPLOYMENT_TARGET" + AC_SUBST(SET_MACOSX_DEPLOYMENT_TARGET) + LINK_SHARED_OBJ="$GCC_PROG -multiply_defined suppress \ + -dynamiclib -single_module" + LINK_SHARED_OBJ_SH="$GCC_PROG -multiply_defined \ + suppress -dynamiclib -single_module" + ALLOW_UNDEFINED="-undefined dynamic_lookup" + else + AC_MSG_RESULT(no) + LINK_SHARED_OBJ="$GCC_PROG -flat_namespace \ + -dynamiclib -single_module" + LINK_SHARED_OBJ_SH="$GCC_PROG -flat_namespace \ + -dynamiclib -single_module" + ALLOW_UNDEFINED="-undefined error" + fi else CFLAGS_FOR_PIC= EXT_FOR_PIC_OBJECTS=o diff --git a/scripts/ml.in b/scripts/ml.in index e713f774c..ac3b3323a 100644 --- a/scripts/ml.in +++ b/scripts/ml.in @@ -57,6 +57,9 @@ MATH_LIB=${MERCURY_MATH_LIB="@MATH_LIB@"} # since @SHARED_LIBS_SH@ may refer to $MATH_LIB. SHARED_LIBS=${MERCURY_SHARED_LIBS="@SHARED_LIBS_SH@"} +# Set the MACOSX_DEPLOYMENT_TARGET environment variable if needed. +@SET_MACOSX_DEPLOYMENT_TARGET@ + # When compiling in the hlc.gc grade using the Microsoft Visual C # compiler, the default maximum stack size of 4Mb is too low for a # recursive language. diff --git a/scripts/mmake.in b/scripts/mmake.in index f120f1175..a03e01748 100644 --- a/scripts/mmake.in +++ b/scripts/mmake.in @@ -80,6 +80,9 @@ MERCURY_DEFAULT_GRADE=${MERCURY_DEFAULT_GRADE=@DEFAULT_GRADE@} MKTEMP=@MKTEMP@ TMPDIR=${TMPDIR=/tmp} +# Set the MACOSX_DEPLOYMENT_TARGET environment variable if needed. +@SET_MACOSX_DEPLOYMENT_TARGET@ + MMAKE=$0 include_makefile= verbose=false diff --git a/scripts/mmc.in b/scripts/mmc.in index cc68bd074..e36f4b652 100644 --- a/scripts/mmc.in +++ b/scripts/mmc.in @@ -1,7 +1,7 @@ #! /bin/sh # @configure_input@ #---------------------------------------------------------------------------# -# Copyright (C) 1994-1998, 2000-2003 The University of Melbourne. +# Copyright (C) 1994-1998, 2000-2004 The University of Melbourne. # This file may only be copied under the terms of the GNU General # Public License - see the file COPYING in the Mercury distribution. #---------------------------------------------------------------------------# @@ -18,6 +18,9 @@ MERCURY_COMPILER=${MERCURY_COMPILER-'@LIBDIR@/bin/@FULLARCH@/mercury_compile'} MERCURY_CONFIG_DIR=${MERCURY_CONFIG_DIR-${MERCURY_STDLIB_DIR-'@CONFIG_LIBDIR@'}} export MERCURY_COMPILER MERCURY_CONFIG_DIR +# Set the MACOSX_DEPLOYMENT_TARGET environment variable if needed. +@SET_MACOSX_DEPLOYMENT_TARGET@ + case $# in 0) exec $MERCURY_COMPILER ;; *) exec $MERCURY_COMPILER "$@" ;;