build_cross_tools_gcc4 revision 6724a1930dfdfd0f764f3169410c3d46272d4685
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 [ $(uname) = "FreeBSD" ]; then make="gmake"; else make="make"; fi
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
49binutilsSourceDir=$buildToolsDir/binutils
50gccSourceDir=$buildToolsDir/gcc
51
52
53# get gcc version
54gccVersion=$(grep "const char version_string" $gccSourceDir/gcc/version.c \
55	| sed -e 's@.*"\(.*\)".*@\1@')
56
57if [ -z "$gccVersion" ]; then
58	echo "Failed to find out gcc version." >&2
59	exit 1
60fi
61
62
63# create the object and installation directories for the cross compilation tools
64installDir=$haikuOutputDir/cross-tools
65objDir=$haikuOutputDir/cross-tools-build
66binutilsObjDir=$objDir/binutils
67gccObjDir=$objDir/gcc
68tmpIncludeDir=$objDir/sysincludes
69tmpLibDir=$objDir/syslibs
70
71rm -rf $installDir $objDir
72
73mkdir -p $installDir $objDir $binutilsObjDir $gccObjDir $tmpIncludeDir \
74	$tmpLibDir || exit 1
75mkdir -p $installDir/lib/gcc/i586-pc-beos/$gccVersion
76
77# build binutils
78cd $binutilsObjDir
79CFLAGS="-O2" CXXFLAGS="-O2" $binutilsSourceDir/configure \
80	--prefix=$installDir --target=i586-pc-beos --disable-nls \
81	--enable-shared=yes || exit 1
82$make || exit 1
83$make install || exit 1
84
85export PATH=$PATH:$installDir/bin
86
87
88# build gcc
89
90# prepare the include files
91copy_headers()
92{
93	sourceDir=$1
94	targetDir=$2
95
96	headers="$(find $sourceDir -name \*\.h | grep -v /.svn)"
97	headers="$(echo $headers | sed -e s@$sourceDir/@@g)"
98	for f in $headers; do
99		headerTargetDir=$targetDir/$(dirname $f)
100		mkdir -p $headerTargetDir
101		cp $sourceDir/$f $headerTargetDir
102	done
103}
104
105copy_headers $haikuSourceDir/headers/os $tmpIncludeDir/be
106copy_headers $haikuSourceDir/headers/posix $tmpIncludeDir/posix
107
108# configure gcc
109cd $gccObjDir
110CFLAGS="-O2" CXXFLAGS="-O2" $gccSourceDir/configure --prefix=$installDir \
111	--target=i586-pc-beos --disable-nls --enable-shared=yes \
112	--enable-languages=c,c++ --with-headers=$tmpIncludeDir \
113	--with-libs=$tmpLibDir || exit 1
114
115# make gcc
116$make || {
117	echo "ERROR: Building gcc failed." >&2
118	exit 1
119}
120
121# install gcc
122$make install || {
123	echo "ERROR: Installing the cross compiler failed." >&2
124	exit 1
125}
126
127# cleanup
128
129# remove the system headers from the installation dir
130# Only the ones from the source tree should be used.
131sysIncludeDir=$installDir/i586-pc-beos/sys-include
132rm -rf $sysIncludeDir/be $sysIncludeDir/posix
133
134# remove the objects dir
135rm -rf $objDir
136
137
138echo "binutils and gcc for cross compilation have been built successfully!"
139