xref: /haiku/build/scripts/build_cross_tools (revision a4f6a81235ca2522c01f532de13cad9b729d4029)
1#!/bin/sh
2
3# parameters <haiku sourcedir> <buildtools dir> [ <haiku output dir> ]
4
5# get and check the parameters
6if [ $# \< 2 ]; then
7	echo Usage: $0 '<haiku sourcedir> <buildtools dir> [ <haiku output dir> ]' >&2
8	exit 1
9fi
10
11haikuSourceDir=$1
12buildToolsDir=$2/legacy
13
14if [ $# \< 3 ]; then
15	haikuOutputDir=$haikuSourceDir/generated
16else
17	haikuOutputDir=$3
18fi
19
20if [ ! -d $haikuSourceDir ]; then
21	echo "No such directory: \"$haikuSourceDir\"" >&2
22	exit 1
23fi
24
25if [ ! -d $buildToolsDir ]; then
26	echo "No such directory: \"$buildToolsDir\"" >&2
27	exit 1
28fi
29
30
31# create the output dir
32mkdir -p $haikuOutputDir || exit 1
33
34
35# get absolute paths
36currentDir=$(pwd)
37
38cd $haikuSourceDir
39haikuSourceDir=$(pwd)
40cd $currentDir
41
42cd $buildToolsDir
43buildToolsDir=$(pwd)
44cd $currentDir
45
46cd $haikuOutputDir
47haikuOutputDir=$(pwd)
48
49
50# create the object and installation directories for the cross compilation tools
51installDir=$haikuOutputDir/cross-tools
52objDir=$haikuOutputDir/cross-tools-build
53binutilsObjDir=$objDir/binutils
54gccObjDir=$objDir/gcc
55tmpIncludeDir=$objDir/sysincludes
56tmpLibDir=$objDir/syslibs
57
58rm -rf $installDir $objDir
59
60mkdir -p $installDir $objDir $binutilsObjDir $gccObjDir $tmpIncludeDir \
61	$tmpLibDir || exit 1
62mkdir -p $installDir/lib/gcc-lib/i586-pc-beos/2.95.3-beos-041202
63
64
65# build binutils
66cd $binutilsObjDir
67CFLAGS="-O2" CXXFLAGS="-O2" $buildToolsDir/binutils/configure \
68	--prefix=$installDir --target=i586-pc-beos --disable-nls \
69	--enable-shared=yes || exit 1
70make || exit 1
71make install || exit 1
72
73export PATH=$PATH:$installDir/bin
74
75
76# build gcc
77
78# prepare the include files
79copy_headers()
80{
81	sourceDir=$1
82	targetDir=$2
83
84	headers="$(find $sourceDir -name \*\.h | grep -v /.svn)"
85	headers="$(echo $headers | sed -e s@$sourceDir/@@g)"
86	for f in $headers; do
87		headerTargetDir=$targetDir/$(dirname $f)
88		mkdir -p $headerTargetDir
89		cp $sourceDir/$f $headerTargetDir
90	done
91}
92
93copy_headers $haikuSourceDir/headers/os $tmpIncludeDir/be
94copy_headers $haikuSourceDir/headers/posix $tmpIncludeDir/posix
95
96# configure gcc
97cd $gccObjDir
98CFLAGS="-O2" CXXFLAGS="-O2" $buildToolsDir/gcc/configure --prefix=$installDir \
99	--target=i586-pc-beos --disable-nls --enable-shared=yes \
100	--enable-languages=c,c++ --with-headers=$tmpIncludeDir \
101	--with-libs=$tmpLibDir || exit 1
102
103# hack the Makefile to avoid trouble with stuff we don't need anyway
104sedExpr=
105for toRemove in libiberty libio libjava libobjc libstdc++; do
106	sedExpr="$sedExpr -e 's@^\(TARGET_CONFIGDIRS =.*\)$toRemove\(.*\)@\1\2@'"
107done
108echo sedExpr: $sedExpr
109mv Makefile Makefile.bak || exit 1
110eval "sed $sedExpr Makefile.bak > Makefile" || exit 1
111rm Makefile.bak
112
113# make gcc
114make cross || {
115	echo "ERROR: Building gcc failed." >&2
116	exit 1
117}
118
119# install gcc
120make install-gcc-cross || {
121	echo "ERROR: Installing the cross compiler failed." >&2
122	exit 1
123}
124
125
126# cleanup
127
128# remove the system headers from the installation dir
129# Only the ones from the source tree should be used.
130sysIncludeDir=$installDir/i586-pc-beos/sys-include
131rm -rf $sysIncludeDir/be $sysIncludeDir/posix
132
133# remove the objects dir
134rm -rf $objDir
135
136
137echo "binutils and gcc for cross compilation have been built successfully!"
138
139