Help with Building toolchain with crosstool-ng on Mac OS X 10.6.2 (Snow Leopard)

tvb377@gmx.de tvb377@gmx.de
Mon Feb 1 02:26:00 GMT 2010


> > I recently made a patch for using crosstool-ng on mac and freebsd.
> > I will rework the cosmetics according to Yann's comments this month.
> 
> Titus, I think you are the one that can handle this stuff, as you have a

Uwe, Yann, all

here is the reworked patch for crosstool-ng on FreeBSD and MacOS against a current (31 January 23:00 CET) version.
And two new READMEs (instead of docs/MacOS-X.txt).

Almost all patch parts revolve around GNU/BSD incompatibilities.
I try to explain what I did:
- enlarge the list of configurable tools that ctng uses (for usage of GNU tools).
- also make sure that the configured tools actually get used.
- make all calls to stat(1) dependent to `uname -s` or replace the call.
- replace all calls to readlink(1GNU) with compatible variants.
  This makes the usage of wrapper.c mandatory on MacOS because there is no way known to me emulating readlink -m without a lengthy shell script.
- uname -o is not portable. use -s when -o fails
- a bug in the sed-expression that sets the nanoseconds to 0 for a date(1) not handling %N

Notable other reasons besides GNU/BSD are:
- have to compile mpfr with --disable-thread-safe on darwin.
- "You did not specify the build system. That's OK, I can guess...":
  Under MacOS 10.6 gcc reports itself as "i686-apple-..."
  However, it's default behaviour is to generate 64bit objects.
  This clashes with some configure scripts that require "x86_64-..." for configuring for a 64bit host.
  Using CT_DoConfigGuess does the job correctly.
  Why not use that in general?
BTW, the above two changes are the only changes actually for BUILDING the toolchain, and not for porting ctng itself.
- the compiler command line options for compiling wrapper.c crashes gcc on MacOS (and IMHO were a little bit overdone for the complexity of wrapper.c).
- you should not link statically on MacOS (wrapper.c command line again)
- under Darwin, use DYLD_LIBRARY_PATH in wrapper.c
- added printenv to the build.log (I found that helpful).

I can now compile gcc4.4.2 for powerpc for linux/glibc under Linux, BSD, and MacOS.
I only shortly grepped through scripts not necessary for this configuration, so more incompatibilities may arise. However, they should be easy to fix in this manner.

Hope this helps.
Further comments are welcome.

Regards
Titus
-------------- next part --------------
diff -r 160fc94ed49f Makefile.in
--- a/Makefile.in	Sun Jan 31 23:04:35 2010 +0100
+++ b/Makefile.in	Mon Feb 01 02:33:37 2010 +0100
@@ -52,6 +52,11 @@
 grep   := @@grep@@
 make   := @@make@@
 sed    := @@sed@@
+libtool:= @@libtool@@
+objcopy:= @@objcopy@@
+objdump:= @@objdump@@
+readelf:= @@readelf@@
+patch  := @@patch@@
 
 ###############################################################################
 # Sanity checks
@@ -139,6 +144,11 @@
 	  echo "export grep=$(grep)";       \
 	  echo "export make=$(make)";       \
 	  echo "export sed=$(sed)";         \
+	  echo "export libtool=$(libtool)"; \
+	  echo "export objcopy=$(objcopy)"; \
+	  echo "export objdump=$(objdump)"; \
+	  echo "export readelf=$(readelf)"; \
+	  echo "export patch=$(patch)";     \
 	 ) >paths.mk
 
 #--------------------------------------
diff -r 160fc94ed49f configure
--- a/configure	Sun Jan 31 23:04:35 2010 +0100
+++ b/configure	Mon Feb 01 02:33:37 2010 +0100
@@ -160,7 +160,7 @@
                 printf "Checking for '${item}'... "
                 where="$( gcc -print-file-name="${item}" )"
                 if [ "${where}" != "${item}" ]; then
-                    where="$( readlink -e "${where}" )"
+                    where="$( readlink "${where}" )"
                     status=yes
                     break;
                 fi
@@ -346,17 +346,17 @@
              ver='^GNU Make (3.[89][[:digit:]]|[4-9])'  \
              err="GNU 'make' 3.80 or above was not found"
 has_or_abort prog=gcc
-has_or_abort prog="awk gawk" ver='^GNU Awk' err="GNU 'awk' was not found"
+has_or_abort prog="gawk awk" ver='^GNU Awk' err="GNU 'awk' was not found"
 has_or_abort prog=bison
 has_or_abort prog=flex
 has_or_abort prog=makeinfo
 has_or_abort prog=automake                                                      \
              ver='\(GNU automake\) (1\.[[:digit:]]{2,}|[2-9][[:digit:]]*\.)'    \
              err="'automake' 1.10 or above was not found"
-has_or_abort prog=libtool                                                                           \
+has_or_abort prog=libtool var=libtool                                                               \
              ver='\(GNU libtool.*\) (2[[:digit:]]*\.|1\.6[[:digit:]]*\.|1\.5\.[2-9][[:digit:]]+)'   \
              err="'libtool' 1.5.26 or above was not found"
-has_or_abort prog=stat ver='GNU coreutils'
+has_or_abort prog=stat
 has_or_abort prog="aria2c curl wget"
 has_or_abort prog=cvs
 has_or_abort prog=patch
@@ -365,6 +365,10 @@
 has_or_abort prog=bzip2
 has_or_abort prog=lzma
 has_or_abort prog=readlink
+has_or_abort prog=objcopy var=objcopy
+has_or_abort prog=objdump var=objdump
+has_or_abort prog=readelf var=readelf
+has_or_abort prog=patch var=patch
 
 has_or_abort inc="ncurses/ncurses.h ncurses/curses.h ncurses.h curses.h"    \
              err="'ncurses' headers files were not found"
diff -r 160fc94ed49f samples/samples.mk
--- a/samples/samples.mk	Sun Jan 31 23:04:35 2010 +0100
+++ b/samples/samples.mk	Mon Feb 01 02:33:37 2010 +0100
@@ -5,10 +5,10 @@
 CT_TOP_SAMPLES := $(patsubst $(CT_TOP_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_TOP_DIR)/samples/*/crosstool.config))
 CT_LIB_SAMPLES := $(filter-out $(CT_TOP_SAMPLES),$(patsubst $(CT_LIB_DIR)/samples/%/crosstool.config,%,$(wildcard $(CT_LIB_DIR)/samples/*/crosstool.config)))
 CT_SAMPLES := $(shell echo $(sort $(CT_TOP_SAMPLES) $(CT_LIB_SAMPLES))  \
-                      |sed -r -e 's/ /\n/g;'                            \
-                      |sed -r -e 's/(.*),(.*)/\2,\1/;'                  \
+                      |$(sed) -r -e 's/ /\n/g;'                            \
+                      |$(sed) -r -e 's/(.*),(.*)/\2,\1/;'                  \
                       |LC_ALL=C sort                                    \
-                      |sed -r -e 's/(.*),(.*)/\2,\1/;'                  \
+                      |$(sed) -r -e 's/(.*),(.*)/\2,\1/;'                  \
                )
 
 # ----------------------------------------------------------
diff -r 160fc94ed49f scripts/build/companion_libs/mpfr.sh
--- a/scripts/build/companion_libs/mpfr.sh	Sun Jan 31 23:04:35 2010 +0100
+++ b/scripts/build/companion_libs/mpfr.sh	Mon Feb 01 02:33:37 2010 +0100
@@ -75,6 +75,7 @@
     case "${CT_HOST}" in
         *cygwin*)   mpfr_opt="--disable-thread-safe";;
         *mingw*)    mpfr_opt="--disable-thread-safe";;
+        *darwin*)   mpfr_opt="--disable-thread-safe";;
         *)          mpfr_opt="--enable-thread-safe";;
     esac
 
diff -r 160fc94ed49f scripts/build/internals.sh
--- a/scripts/build/internals.sh	Sun Jan 31 23:04:35 2010 +0100
+++ b/scripts/build/internals.sh	Mon Feb 01 02:33:37 2010 +0100
@@ -42,6 +42,11 @@
         CT_DoLog EXTRA "Installing toolchain wrappers"
         CT_Pushd "${CT_PREFIX_DIR}/bin"
 
+        if [ "$CT_SYS_OS" = "Darwin" -o "$CT_SYS_OS" = "FreeBSD" ] ; then
+            # wrapper does not work (when using readlink -m)
+            CT_DoLog EXTRA "Forcing usage of binary wrappers"
+            CT_TOOLS_WRAPPER="exec"
+        fi
         # Install the wrapper
         case "${CT_TOOLS_WRAPPER}" in
             script)
@@ -55,9 +60,8 @@
                 if [ "${CT_DEBUG_CT}" = "y" ]; then
                   _t="" # If debugging crosstool-NG, don't strip the wrapper
                 fi
-                CT_DoExecLog DEBUG "${CT_HOST}-gcc"                           \
-                                   -Wall -Wextra -Wunreachable-code -Werror   \
-                                   -O3 -static ${_t}                          \
+                CT_DoExecLog DEBUG "cc" -Wall -Wextra -Werror        \
+                                   -O -D$CT_SYS_OS ${_t}             \
                                    "${CT_LIB_DIR}/scripts/wrapper.c"          \
                                    -o ".${CT_TARGET}-wrapper"
                 ;;
@@ -68,7 +72,7 @@
         # scripts, we don't know if they would in the end spawn a binary...
         # Just skip symlinks
         for _t in "${CT_TARGET}-"*; do
-            if [ "$( LANG=C stat -c '%F' "${_t}" )" != "symbolic link" ]; then
+            if [ -z "`readlink ${_t}`" ]; then
                 CT_DoExecLog ALL mv "${_t}" ".${_t}"
                 CT_DoExecLog ALL ln ".${CT_TARGET}-wrapper" "${_t}"
             fi
diff -r 160fc94ed49f scripts/crosstool-NG.sh.in
--- a/scripts/crosstool-NG.sh.in	Sun Jan 31 23:04:35 2010 +0100
+++ b/scripts/crosstool-NG.sh.in	Mon Feb 01 02:33:37 2010 +0100
@@ -189,8 +189,8 @@
 CT_SYS_HOSTNAME="${CT_SYS_HOSTNAME:-$(uname -n)}"
 CT_SYS_KERNEL=$(uname -s)
 CT_SYS_REVISION=$(uname -r)
-# MacOS X lacks '-o' :
-CT_SYS_OS=$(uname -o || echo "Unknown (maybe MacOS-X)")
+# uname -o is a GNU Extension. Others lack '-o' --> use System name for OS name.
+CT_SYS_OS=$(uname -o || uname -s)
 CT_SYS_MACHINE=$(uname -m)
 CT_SYS_PROCESSOR=$(uname -p)
 CT_SYS_GCC=$(gcc -dumpversion)
@@ -326,7 +326,12 @@
     # Determine build system if not set by the user
     CT_Test "You did not specify the build system. That's OK, I can guess..." -z "${CT_BUILD}"
     case "${CT_BUILD}" in
-        "") CT_BUILD=$("${CT_BUILD_PREFIX}gcc${CT_BUILD_SUFFIX}" -dumpmachine);;
+        "") if [ "$CT_SYS_OS" = "Darwin" -o "$CT_SYS_OS" = "FreeBSD" ] ; then
+                CT_BUILD=$(CT_DoConfigGuess)
+            else
+                CT_BUILD=$("${CT_BUILD_PREFIX}gcc${CT_BUILD_SUFFIX}" -dumpmachine)
+            fi
+            ;;
     esac
 
     # Prepare mangling patterns to later modify BUILD and HOST (see below)
@@ -454,7 +459,7 @@
     CT_DoExecLog ALL chmod 700 "${CT_PREFIX_DIR}/buildtools/makeinfo"
 
     # Help gcc
-    CT_CFLAGS_FOR_HOST=
+    # Why clear that ? CT_CFLAGS_FOR_HOST=
     [ "${CT_USE_PIPES}" = "y" ] && CT_CFLAGS_FOR_HOST="${CT_CFLAGS_FOR_HOST} -pipe"
 
     # Override the configured jobs with what's been given on the command line
@@ -474,7 +479,7 @@
     CT_DoLog EXTRA "Installing user-supplied crosstool-NG configuration"
     CT_DoExecLog ALL mkdir -p "${CT_PREFIX_DIR}/bin"
     CT_DoExecLog DEBUG install -m 0755 "${CT_LIB_DIR}/scripts/toolchain-config.in" "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
-    CT_DoExecLog DEBUG sed -r -i -e 's,@@grep@@,"'"${grep}"'",;' "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
+    CT_DoExecLog DEBUG sed -i -e 's,@@grep@@,"'"${grep}"'",;' "${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
     bzip2 -c -9 .config >>"${CT_PREFIX_DIR}/bin/${CT_TARGET}-ct-ng.config"
 
     CT_DoStep EXTRA "Dumping internal crosstool-NG configuration"
@@ -483,6 +488,8 @@
     CT_DoLog EXTRA "  host   = ${CT_REAL_HOST}"
     CT_DoLog EXTRA "  target = ${CT_TARGET}"
     set |grep -E '^CT_.+=' |sort |CT_DoLog DEBUG
+    CT_DoLog DEBUG "  Other environment:"
+    printenv |grep -v -E '^CT_.+=' |sort |CT_DoLog DEBUG
     CT_EndStep
 fi
 
diff -r 160fc94ed49f scripts/functions
--- a/scripts/functions	Sun Jan 31 23:04:35 2010 +0100
+++ b/scripts/functions	Mon Feb 01 02:33:37 2010 +0100
@@ -192,7 +192,7 @@
 # to the highest entire second
 # Usage: CT_DoDate <fmt>
 CT_DoDate() {
-    date "$1" |sed -r -e 's/%N$/000000000/;'
+    date "$1" |sed -r -e 's/N$/000000000/;'
 }
 
 CT_STEP_COUNT=1
@@ -249,7 +249,17 @@
     local mode
     for dir in "${@}"; do
         [ -d "${dir}" ] || continue
-        mode="$(stat -c '%a' "$(dirname "${dir}")")"
+        case "$CT_SYS_OS" in
+            GNU/Linux)
+                mode="$(stat -c '%a' "$(dirname "${dir}")")"
+                ;;
+            Darwin|FreeBSD)
+                mode="$(stat -f '%Lp' "$(dirname "${dir}")")"
+                ;;
+            *)
+                CT_Abort "Unhandled host OS $CT_SYS_OS"
+                ;;
+        esac
         CT_DoExecLog ALL chmod u+w "$(dirname "${dir}")"
         CT_DoExecLog ALL chmod -R u+w "${dir}"
         CT_DoExecLog ALL rm -rf "${dir}"
diff -r 160fc94ed49f scripts/wrapper.c
--- a/scripts/wrapper.c	Sun Jan 31 23:04:35 2010 +0100
+++ b/scripts/wrapper.c	Mon Feb 01 02:33:37 2010 +0100
@@ -7,6 +7,11 @@
 #include <unistd.h>
 #include <errno.h>
 
+#ifdef	Darwin
+static const char * ldlp = "DYLD_LIBRARY_PATH";
+#else
+static const char * ldlp = "LD_LIBRARY_PATH";
+#endif
 
 /* Needed for execve */
 extern char **environ;
@@ -106,7 +111,7 @@
 
   /* Now add the directory with our runtime libraries to the
      front of the library search path, LD_LIBRARY_PATH */
-  ldlibpath = getenv( "LD_LIBRARY_PATH" );
+  ldlibpath = getenv(ldlp);
   if( ldlibpath ) {
     basedir = (char*) realloc( basedir,   strlen( basedir )
                                         + strlen( ldlibpath )
@@ -115,7 +120,7 @@
     strcat( basedir, ldlibpath );
   }
 
-  if( setenv( "LD_LIBRARY_PATH", basedir, 1 ) ) {
+  if( setenv( ldlp, basedir, 1 ) ) {
     errno = ENOMEM;
     perror( "tool wrapper" );
     exit( 1 );
diff -r 160fc94ed49f scripts/wrapper.in
--- a/scripts/wrapper.in	Sun Jan 31 23:04:35 2010 +0100
+++ b/scripts/wrapper.in	Mon Feb 01 02:33:37 2010 +0100
@@ -1,5 +1,10 @@
 #!/bin/sh
 
+# this wrapper will not work under BSD systems or others
+# not containig the GNU readlink.
+# Under those, wrapper.c will forcibly be used
+# regardless of the config file setting.
+
 canonicalizedname=$(readlink -nm "${0}")
 dirname="$(dirname "${canonicalizedname}")"
 basename="$(basename "${canonicalizedname}")"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: README.freebsd
Type: application/octet-stream
Size: 517 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/crossgcc/attachments/20100201/637a54b2/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: README.macos
Type: application/octet-stream
Size: 1287 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/crossgcc/attachments/20100201/637a54b2/attachment-0001.obj>
-------------- next part --------------
--
For unsubscribe information see http://sourceware.org/lists.html#faq


More information about the crossgcc mailing list