docs/MacOS-X.txt
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jan 17 23:06:02 2010 +0100 (2010-01-17)
changeset 1740 c57458bb354d
permissions -rw-r--r--
configure: do not require hg when configuring in an hg clone

When configuring in an hg clone, we need hg to compute the version string.
It can happen that users do not have Mercurial (eg. if they got a snapshot
rather that they did a full clone). In this case, we can still run, of
course, so simply fill the version string with a sufficiently explicit
value, that does not require hg. The date is a good candidate.
info@1523
     1
Introduction
info@1523
     2
------------
info@1523
     3
info@1523
     4
This file introduces you to building a cross-toolchain on MacOS-X.
info@1523
     5
Apart from the crosstool-NG configuration options for the specific target,
info@1523
     6
what is important is:
info@1523
     7
 - what pre-requisites to install
info@1523
     8
 - how to install them
info@1523
     9
 - how to work around the case-insensitivity of HFS+
info@1523
    10
info@1523
    11
This file was submitted by:
info@1523
    12
  Blair Burtan <info@northernlightstactical.com>
info@1523
    13
The original version was found at:
info@1523
    14
  http://homepage.mac.com/macg3/TS7390-OSX-crosstool-instructions.txt
info@1523
    15
info@1523
    16
info@1523
    17
Text
info@1523
    18
----
info@1523
    19
info@1523
    20
Compiling cross compiler for default TS-7390 debian system on Mac OS X
info@1523
    21
info@1523
    22
Forewarning: It's kind of a pain. Several of OS X's packages aren't good enough
info@1523
    23
so you need to install some GNU stuff. You might have an easier time using a
info@1523
    24
package manager for OS X but I prefer to compile everything from source so I'm
info@1523
    25
going to provide the instructions for that. Also there are a few little catches
info@1523
    26
with how some of the older gcc/glibc stuff compiles on OS X.
info@1523
    27
info@1523
    28
The version of glibc on the TS-7390 default file system is 2.3.6. So we need to
info@1523
    29
make a compiler with glibc 2.3.6 or older. I guess you can pick whatever version
info@1523
    30
of gcc you want to use. I'll pick 4.1.2, which is what is included with the 7390
info@1523
    31
debian. But you could theoretically do something newer like 4.3.3 (or older,
info@1523
    32
like 4.0.4) if you want, I think. All I know is the following works fine for gcc
info@1523
    33
4.1.2 and glibc 2.3.6.
info@1523
    34
info@1523
    35
First, you have to install some prerequisites. Go in a temporary folder
info@1523
    36
somewhere and follow these directions.
info@1523
    37
info@1523
    38
Some of the included OS X utilities aren't cool enough. So we need to download
info@1523
    39
and install some GNU utilities. Luckily they compile with no trouble in
info@1523
    40
Mac OS X! Nice work GNU people!
info@1523
    41
info@1523
    42
First make sure you've installed the latest version of Xcode so you have gcc
info@1523
    43
on your Mac.
info@1523
    44
info@1523
    45
Install GNU sed into /usr/local. Note: I believe configure defaults to
info@1523
    46
/usr/local as a prefix, but better safe than sorry.
info@1523
    47
info@1523
    48
    curl -O http://ftp.gnu.org/gnu/sed/sed-4.2.1.tar.bz2
info@1523
    49
    tar -xf sed-4.2.1.tar.bz2
info@1523
    50
    cd sed-4.2.1
info@1523
    51
    ./configure --prefix=/usr/local
info@1523
    52
    make -j 2 (or 4 or whatever...# of jobs that can run in parallel...
info@1523
    53
                        on a dual core machine I use 4)
info@1523
    54
    sudo make install
info@1523
    55
info@1523
    56
Install GNU coreutils:
info@1523
    57
info@1523
    58
    curl -O http://ftp.gnu.org/gnu/coreutils/coreutils-7.4.tar.gz
info@1523
    59
    tar -xf coreutils-7.4.tar.gz
info@1523
    60
    cd coreutils-7.4
info@1523
    61
    ./configure --prefix=/usr/local
info@1523
    62
    make -j 2
info@1523
    63
    sudo make install
info@1523
    64
info@1523
    65
Install GNU libtool:
info@1523
    66
info@1523
    67
    curl -O http://ftp.gnu.org/gnu/libtool/libtool-2.2.6a.tar.gz
info@1523
    68
    tar -xf libtool-2.2.6a.tar.gz
info@1523
    69
    cd libtool-2.2.6
info@1523
    70
    ./configure --prefix=/usr/local
info@1523
    71
    make -j 2
info@1523
    72
    sudo make install
info@1523
    73
info@1523
    74
Install GNU awk, needed to fix a weird error in glibc compile:
info@1523
    75
info@1523
    76
    curl -O http://ftp.gnu.org/gnu/gawk/gawk-3.1.7.tar.bz2
info@1523
    77
    tar -xf gawk-3.1.7.tar.bz2
info@1523
    78
    cd gawk-3.1.7
info@1523
    79
    ./configure --prefix=/usr/local
info@1523
    80
    make -j 2
info@1523
    81
    sudo make install
info@1523
    82
info@1523
    83
Xcode doesn't come with objcopy/objdump, but you need them. Download GNU
info@1523
    84
binutils 2.19.1 and install just objcopy and objdump. Not sure how exactly to
info@1523
    85
do only them so I compile it all and copy them manually....there may be a
info@1523
    86
better way.
info@1523
    87
info@1523
    88
    curl -O http://ftp.gnu.org/gnu/binutils/binutils-2.19.1.tar.bz2
info@1523
    89
    tar -xf binutils-2.19.1.tar.bz2
info@1523
    90
    cd binutils-2.19.1
info@1523
    91
    ./configure --prefix=/usr/local
info@1523
    92
    make -j 2
info@1523
    93
    sudo cp binutils/obj{dump,copy} /usr/local/bin
info@1523
    94
info@1523
    95
info@1523
    96
Done installing prerequisites...now do the fun stuff!
info@1523
    97
info@1523
    98
info@1523
    99
1) Create a disk image with Disk Utility (in /Utilities/Disk Utility).
info@1523
   100
    Open it and go to File->New->Blank Disk Image.
info@1523
   101
    Save As: Call it whatever you want.
info@1523
   102
    Volume name: Call it CrosstoolCompile
info@1523
   103
    Volume size: Go to custom and choose 2000 MB. This is a temporary image you
info@1523
   104
                 can delete once you're done compiling if you wish.
info@1523
   105
    Volume format: Choose Mac OS Extended (Case-sensitive, journaled).
info@1523
   106
        Mac OS X's default file system does not allow you to name two files
info@1523
   107
        the same with different cases (abcd and ABCD) but you need this for
info@1523
   108
        crosstool. So that's why we're creating a disk image. Leave everything
info@1523
   109
        else the default and save it wherever you want.
info@1523
   110
info@1523
   111
2) Create another disk image where the final toolchain will be installed.
info@1523
   112
    Your crosstool needs to go on a disk image for the same reason--needs a
info@1523
   113
    case sensitive file system and regular Mac OS X HFS+ is not. So we have to
info@1523
   114
    make another one. Follow the steps above but set the volume name to
info@1523
   115
    Crosstool and then make the volume size something like 300MB. Just make
info@1523
   116
    sure you leave plenty of room for any libraries you want to add to your
info@1523
   117
    cross compiler and that kind of stuff. The resulting toolchain will be about
info@1523
   118
    110 MB in size. Set the Volume Format to
info@1523
   119
    Mac OS Extended (Case-sensitive, journaled).
info@1523
   120
    Save this image somewhere handy. You'll be using it forever after this.
info@1523
   121
info@1523
   122
info@1523
   123
3) Make sure they're both mounted.
info@1523
   124
info@1523
   125
4) cd /Volumes/CrosstoolCompile
info@1523
   126
info@1523
   127
5) Grab crosstool-ng:
info@1523
   128
    curl -O http://ymorin.is-a-geek.org/download    \
info@1523
   129
                /crosstool-ng/crosstool-ng-1.4.2.tar.bz2
info@1523
   130
    (OS X doesn't come with wget by default)
info@1523
   131
info@1523
   132
6) Expand it
info@1523
   133
    tar -xf crosstool-ng-1.4.2.tar.bz2
info@1523
   134
    cd crosstool-ng-1.4.2
info@1523
   135
info@1523
   136
7) Build it
info@1523
   137
    export PATH=/usr/local/bin:$PATH
info@1523
   138
info@1523
   139
    Make sure you do it like this.
info@1523
   140
        /usr/local/bin has to come in the path BEFORE anything else.
info@1523
   141
info@1523
   142
    ./configure --local
info@1523
   143
    make
info@1523
   144
info@1523
   145
8) Configure crosstool
info@1523
   146
    ./ct-ng menuconfig
info@1523
   147
info@1523
   148
At this point you should have a screen up similar to the Linux kernel config.
info@1523
   149
Now set up options. Leave options as default if I haven't mentioned them.
info@1523
   150
info@1523
   151
Paths and misc options:
info@1523
   152
    Enable Use obsolete features
info@1523
   153
    Enable Try features marked as EXPERIMENTAL
info@1523
   154
    Set prefix directory to:
info@1523
   155
        /Volumes/Crosstool/${CT_TARGET}
info@1523
   156
        (this tells it to install on the disk image you created)
info@1523
   157
    Number of parallel jobs: Multiply the number of cores you have times 2.
info@1523
   158
    That's what I generally do. So my dual core can do 4 jobs.
info@1523
   159
    Makes compiling the toolchain faster.
info@1523
   160
info@1523
   161
Target options:
info@1523
   162
    Target Architecture: ARM
info@1523
   163
    Use EABI: Do NOT check this. The default TS Debian filesystem is OABI.
info@1523
   164
        If you are doing an EABI one, you can set this to true (but may want
info@1523
   165
        to do a different version of gcc/glibc)
info@1523
   166
    Architecture level: armv4t
info@1523
   167
        armv4t is for the EP9302. other processors you would pick the
info@1523
   168
            right architecture here.
info@1523
   169
    Floating point: Hardware
info@1523
   170
info@1523
   171
    I believe this is correct even though it's not really using an FPU because
info@1523
   172
    the pre-EABI debian distro was compiled with hardfloat instructions so
info@1523
   173
    whenever you do a floating point instruction the kernel is actually
info@1523
   174
    trapping an illegal instruction error, makes for slow floating point...
info@1523
   175
    EABI is so much better.
info@1523
   176
info@1523
   177
    I know hardware is the default, but I just wanted to clarify that you need
info@1523
   178
    to choose hardware here. I'm pretty sure anyway.
info@1523
   179
info@1523
   180
Toolchain Options:
info@1523
   181
    Tuple's vendor string: whatever you want.
info@1523
   182
        It'll be arm-yourtuple-linux-gnu when you're finished.
info@1523
   183
info@1523
   184
Operating System:
info@1523
   185
    Target OS: linux
info@1523
   186
    Linux kernel version: 2.6.21.7 (best match for TS kernel!)
info@1523
   187
info@1523
   188
binutils:
info@1523
   189
    version: 2.19.1
info@1523
   190
C compiler:
info@1523
   191
    gcc
info@1523
   192
    version: 4.1.2
info@1523
   193
    choose C++ below, so you can compile C++!
info@1523
   194
C-library:
info@1523
   195
    glibc (NOT eglibc for this)
info@1523
   196
    glibc version: 2.3.6
info@1523
   197
    Threading implementation to use: linuxthreads
info@1523
   198
info@1523
   199
(note: nptl is better than linuxthreads, but it looks like nptl didn't support
info@1523
   200
       ARM back in glibc 2.3.6?
info@1523
   201
info@1523
   202
Exit and save config.
info@1523
   203
info@1523
   204
Now we need to add a patch. Looks like the configure script for glibc does not
info@1523
   205
like some of apple's binutils, so we need to patch it to skip the version tests
info@1523
   206
for as and ld. Stick this patch in crosstool-ng-1.4.2/patches/glibc/2.3.6 to
info@1523
   207
skip the version test for as and ld:
info@1523
   208
info@1523
   209
http://homepage.mac.com/macg3/300-glibc-2.3.6-configure-patch-OSX.patch
info@1523
   210
info@1523
   211
(or see below, at the end of this file)
info@1523
   212
info@1523
   213
---------
info@1523
   214
info@1523
   215
Okay, done setting up crosstool...now...
info@1523
   216
info@1523
   217
./ct-ng build
info@1523
   218
info@1523
   219
Sit back, relax, wait a while. Crosstool-ng will do the rest, automatically
info@1523
   220
downloading tarballs, patching them, installing them. Could take quite a long
info@1523
   221
time. The actual compiling took about 30 minutes on my older MacBook Pro. When
info@1523
   222
you're done you have a cross compiler on your disk image that you named
info@1523
   223
"Crosstool". Look in there and you're all set!
info@1523
   224
info@1523
   225
So whenever you want to use the cross compiler, you need to mount this disk
info@1523
   226
image. You could also create an actual partition on your computer that is
info@1523
   227
Mac OS X extended case-sensitive if you wish. Then you don't need the disk
info@1523
   228
image.
info@1523
   229
info@1523
   230
You can delete the CrosstoolCompile disk image. It was just used temporarily
info@1523
   231
while compiling everything.
info@1523
   232
info@1523
   233
Note that I'm pretty sure gcc 4.1.2 has a bug in assembly generation that will
info@1523
   234
cause Qt 4.5 to segfault. I'm fairly sure I saw this problem before with 4.1.2.
info@1523
   235
I know for a fact that gcc 4.3.3 has the bug. This bug report:
info@1523
   236
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39429 has the details. I adapted the
info@1523
   237
patch at the bottom to work with gcc 4.3.3. you might be able to apply it to
info@1523
   238
other gcc versions. Not sure. I think 4.0.4 does not have this bug so you might
info@1523
   239
even try compiling 4.0.4 instead of 4.1.2. Lots of options. Hope this helps,
info@1523
   240
I've struggled with this stuff a lot but it's so convenient to have a native
info@1523
   241
OS X toolchain!
info@1523
   242
info@1523
   243
info@1523
   244
Patch
info@1523
   245
-----
info@1523
   246
info@1523
   247
Here is the afore-mentioned patch:
info@1523
   248
info@1523
   249
---8<---
info@1523
   250
Mac OS X fails configuring because its included binutils kind of suck.
info@1523
   251
This patch makes the glibc 2.3.6 configure script ignore the
info@1523
   252
installed version of as and ld. It just makes the configure
info@1523
   253
script believe that it's as version 2.13 and ld 2.13.
info@1523
   254
info@1523
   255
Made on 2009-08-08 by Doug Brown
info@1523
   256
info@1523
   257
--- glibc-2.3.6/configure.orig	2009-08-08 10:40:10.000000000 -0700
info@1523
   258
+++ glibc-2.3.6/configure	2009-08-08 10:42:49.000000000 -0700
info@1523
   259
@@ -3916,10 +3916,7 @@ else
info@1523
   260
 echo $ECHO_N "checking version of $AS... $ECHO_C" >&6
info@1523
   261
   ac_prog_version=`$AS -v </dev/null 2>&1 | sed -n 's/^.*GNU assembler.* \([0-9]*\.[0-9.]*\).*$/\1/p'`
info@1523
   262
   case $ac_prog_version in
info@1523
   263
-    '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
info@1523
   264
-    2.1[3-9]*)
info@1523
   265
-       ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
info@1523
   266
-    *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
info@1523
   267
+    *) ac_prog_version="2.13, ok"; ac_verc_fail=no;;
info@1523
   268
 
info@1523
   269
   esac
info@1523
   270
   echo "$as_me:$LINENO: result: $ac_prog_version" >&5
info@1523
   271
@@ -3977,10 +3974,7 @@ else
info@1523
   272
 echo $ECHO_N "checking version of $LD... $ECHO_C" >&6
info@1523
   273
   ac_prog_version=`$LD --version 2>&1 | sed -n 's/^.*GNU ld.* \([0-9][0-9]*\.[0-9.]*\).*$/\1/p'`
info@1523
   274
   case $ac_prog_version in
info@1523
   275
-    '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
info@1523
   276
-    2.1[3-9]*)
info@1523
   277
-       ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
info@1523
   278
-    *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
info@1523
   279
+    *) ac_prog_version="2.13, ok"; ac_verc_fail=no;;
info@1523
   280
 
info@1523
   281
   esac
info@1523
   282
   echo "$as_me:$LINENO: result: $ac_prog_version" >&5
info@1523
   283
---8<---