Subject: Re: Cross-compiler-HOWTO
To: Allen Briggs <briggs@puma.bevd.blacksburg.va.us>
From: Andrew Cagney <cagney@highland.com.au>
List: tech-ports
Date: 02/08/1996 02:08:39
Excerpts from mail: 22-Jan-96 Re: Cross-compiler-HOWTO
Chris_G_Demetriou@NIAGAR (765)
> Actually, what _i_ would most like to see come out of this is:
> (1) a document which details how to cross-compile the system,
> or at least the kernel, and
Below are some of the notes from PSIM (PowerPC simulator) they explain
how to build NetBSD binaries hosted on Solaris/x86. As for the kernel,
it linked ....
BTW: I believe that the problems with make were recently fixed.
Unfortunatly the remote ftp server I use has been playing up. Oh and
some of the files I refer to won't be available until later today.
> (2) from people who've done cross-compiling to the port
> maintainers, a set of 'suggested changes' to makefiles,
> etc., to make it work. e.g. "change this compile rule
> to specify the cc that builds a native binary, change this
> compile rule to specify the cc that builds the
> cross-compiled bin," etc. I think a list of things
> that need to be done, and diffs for at least one port,
> would be most useful for getting Real Live Support
> for cross-compilation in the tree.
o I believe the problem building make has been fixed.
o The build has a chicken/egg problem with header files.
You will notice that in the below I hand install some .h
files to avoid problems.
o the makefiles insist on root and berkeley versions of
some commands (I get around this with wrapper
scripts - see below).
o the include directory wants to use pax and *not* follow
soft links. There is a patch to change that to both use
find and be a bit more tolerant towards strange directories.
Other than those there really are not that many problems. Probably the
only reall suggestion is to ensure that for all machine code library
functions there is both a matching C version and it is regularly tested
(I noticed in the kernel that many machine code functions could be
prototyped using C).
enjoy,
Andrew
BUILDING A BSD/UEA DEVELOPMENT ENVIRONMENT
Background:
For a UEA to be useful it needs a supporting run-time environment.
PSIM implements a runtime environment based on the NetBSD system call
interface.
More than any thing, this user level emulation was the first
implemented because I happened to have the NetBSD source code lying
lying around.
Preparation:
This requires the NetBSD-1.1 source tree online. It can either be
obtained vi ftp:
try http://www.netbsd.org or ftp://ftp.netbsd.org
Alternatively obtain one of the NetBSD cdrom's. Patches to this source
tree that fill out much of the PowerPC code are available in:
ftp://ftp.ci.com.au/pub/clayton
Fetch everything in that directory - diffs, tar archives and scripts.
In addition a patch to binutils is in:
ftp://ftp.ci.com.au/pub/psim/binutils-2.6+note.diff.gz
Finally you'll require a compiler and assembler/linker:
gcc-2.7.2.tar.gz
binutils-2.6.tar.gz
Method:
These notes are based on an installation performed on a Solaris2/x86
host. For other hosts and other configurations, the below should be
considered as a guideline only.
o Sanity check
I assume that you have already obtained the NetBSD-1.1 source
code and unpacked it into the directory bsd-src. While the
full NetBSD source tree may not be needed, things are easier
if it is all online.
$ cd .../scratch
$ ls -1
binutils-2.6.tar.gz
binutils-2.6.tar.gz
clayton-include-960203.diff.gz
clayton-lib-960203.diff.gz
clayton-lib-960203.tar.gz
clayton-sys-960203.diff.gz
clayton-sys-960203.tar.gz
clayton-utils-960203.tar.gz
clayton.chown.sh
clayton.install.sh
clayton.lorder.sh
clayton.make.sh
clayton.usr.bin.make.diff
gcc-2.7.2.tar.gz
gcc-2.7.2+sys-types.diff.gz
o Unpack the bsd source code (if you haven't already)
$ cd .../scratch
$ mkdir bsd-src
$ cd bsd-src
$ for d in /cdrom/bsdisc_12_95_disc2/NetBSD-1.1/source/*11
do
echo $d
cat $d/*.?? | gunzip | tar xf -
done
Flatten the directory structure a little.
$ mv usr/src/* .
$ rmdir usr/src usr
$ cd ..
o Unpack/build/install binutils
$ cd .../scratch
$ gunzip < binutils-2.6.tar.gz | tar xf -
$ cd binutils-2.6
Optionally apply the note patch
$ gunzip ../binutils-2.6+note.diff.gz | patch
Then continue with the build
$ ./configure --target=powerpc-unknown-eabi \
--prefix=/applications/psim
$ make
$ make install
$ cd ..
$ rm -rf binutils-2.6
This has the intended side effect of partially populating
the psim directory tree which makes follow on steps easier.
o Fill out the install directory with a few additions (if
install -d works, this can be simplified).
$ mkdir \
/applications/psim/bsd-root \
/applications/psim/bsd-root/usr \
/applications/psim/bsd-root/usr/share \
/applications/psim/bsd-root/usr/share/doc \
/applications/psim/bsd-root/usr/share/doc/psd \
/applications/psim/bsd-root/usr/share/doc/psd/19.curses \
/applications/psim/bsd-root/usr/include \
/applications/psim/bsd-root/usr/lib \
o Make the bsd and gnu include directories point to the same
location.
GCC expects include files to be in one location while the
bsd install expects them in a second. The link is in
the direction below because bsd's install also insists on
a directory (not a link) for its install destination.
$ ln -s ../bsd-root/usr/include \
/applications/psim/powerpc-unknown-eabi/include
o Build/install Berkeley make
In building Berkeley make from the NetBSD-1.1 source tree
a number of problems may be encountered.
These problems have been fixed in NetBSD-current (after
4/2/96 (ie start Feb)) you should probably obtain that
version of make. Alternatively, you can try following the
notes below that got make working on a Solaris-2.5/x86
host.
$ cd .../scratch
$ cd bsd-src/usr.bin/make
$ pwd
.../scratch/bsd-src/usr.bin/make
Copy/stub some additional include files that your host may not
have.
$ cp ../../include/ranlib.h ranlib.h
$ mkdir sys
$ cp ../../sys/sys/cdefs.h sys/cdefs.h
$ mkdir machine
$ touch machine/cdefs.h
Edit/fix some of the BSDisms. The patch file indicated
contains fixes I found when compiling on my host, your
host will probably differ.
$ gunzip < ../../../clayton.usr.bin.make.diff.gz | patch
Build it with some extra flags (again your flags will differ):
$ make -f Makefile.boot CC='gcc -g -DPOSIX'
With bmake built, install it into the target specific bin
directory:
$ cp bmake /applications/psim/powerpc-unknown-eabi/bin/make
$ cd ../../..
o Patch/install Berkeley make's include (mk) files.
$ cd .../share
$ cd bsd-src/share
$ tar cf - mk | ( cd /applications/psim/bsd-root/usr/share \
&& tar xf - )
$ cd ../..
o Set up a number of wrapper scripts for bmake so that it works.
In addition to needing BSD make the build process assumes
a number of BSD specific commands. To get around this
several wrapper scripts are available.
powerpc-unknown-eabi-make (clayton.make)
Front end to Berkeley make setting it up for a
cross compilation
/applications/psim/bin/powerpc-unknown-eabi-make
chown (clayton.chown)
Wrapper that does not do any thing.
Avoids the need to be root when installing.
/applications/psim/powerpc-unknown-eabi/bin
install (clayton.install)
Wrapper to strip away a number of bsd specific install
arguments.
/applications/psim/powerpc-unknown-eabi/bin/install
lorder (clayton.lorder)
Tweaked lorder script that will use nm etc from
binutils.
/applications/psim/powerpc-unknown-eabi/bin/lorder
o Apply the remaining patches for the BSD source tree
$ cd .../scratch
$ cd bsd-src
Diffs are applied using something like:
$ gunzip < ../clayton-include-960203.diff.gz | more
...
The patch to sys/dev/pci/ncr.c.rej might fail.
The tar archives have a different problem, you need
to remove the `src' prefix. I used
$ ln -s . src
$ gunzip < ../clayton-lib-960203.tar.gz | tar xtf -
...
So that src/xxx unpacked into ./xxx
$ cd ..
o Install the include files
$ cd .../scratch
$ cd bsd-src/include
$ powerpc-unknown-eabi-make install
$ cd ../..
o Install a few other include files.
As with building libnew, the bsd build process has
several include file problems.
$ cd .../scratch
$ cd bsd-src
$ cp gnu/lib/libg++/g++-include/values.h \
/applications/psim/powerpc-unknown-eabi/include
$ cp lib/libcurses/curses.h \
/applications/psim/powerpc-unknown-eabi/include
$ cd ..
o Build/install gcc
$ cd .../scratch
$ gunzip < gcc-2.7.2,tar.gz | tar xf -
$ cd gcc-2.7.2
GCC and BSD (for PowerPC) have a conflicting type
declaration. The patch below gets around this
problem:
$ gunzip < ../gcc-2.7.2+sys-types.diff.gz | patch
Other than that, assuming the include files installed
okay, the rest should be fine ....
$ ./configure --target=powerpc-unknown-eabi \
--prefix=/applications/psim
$ make CC=gcc
$ make CC=gcc install
$ cd ..
$ rm -rf gcc-2.7.2
o Build/install the Berkeley library:
$ cd .../scratch
$ cd bsd-src/lib
$ powerpc-unknown-eabi-make
$ powerpc-unknown-eabi-make install
$ cd ../..
If you encounter problems try the following: an include
file not yet installed; a directory not yet created;
running the hosts version of a program instead of a
bsd version.
o Build/run a simple BSD program
$ cd .../scratch
$ cd bsd-src/usr.bin/printenv
$ powerpc-unknown-eabi-make
$ powerpc-unknown-eabi-run printenv
.
.
.