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