Ticket #1739: build_developer_tools.sh

File build_developer_tools.sh, 3.5 KB (added by nielx, 11 years ago)

Build script for the legacy gcc

Line 
1#!/bin/sh
2
3# This script creates a 'develop' directory that can be used from Haiku
4
5set -x
6
7#
8# 1. Check command line arguments
9#
10
11if [ $# \< 2 ]; then
12    echo Usage: $0 '<haiku trunkdir> <buildtools dir> [ <haiku output dir> ]' >&2
13    exit 1
14fi
15
16#
17# 2. Set up environment
18#
19
20haikuSourceDir=$1
21buildToolsDir=$2/legacy
22
23if [ $# \< 3 ]; then
24    haikuOutputDir=$haikuSourceDir/generated
25else
26    haikuOutputDir=$3
27fi
28
29if [ ! -d $haikuSourceDir ]; then
30    echo "No such directory: \"$haikuSourceDir\"" >&2
31    exit 1
32fi
33
34if [ ! -d $buildToolsDir ]; then
35    echo "No such directory: \"$buildToolsDir\"" >&2
36    exit 1
37fi
38
39# create the output dir
40mkdir -p $haikuOutputDir || exit 1
41
42# get absolute paths
43currentDir=$(pwd)
44
45cd $haikuSourceDir
46haikuSourceDir=$(pwd)
47cd $currentDir
48
49cd $buildToolsDir
50buildToolsDir=$(pwd)
51cd $currentDir
52
53cd $haikuOutputDir
54haikuOutputDir=$(pwd)
55
56# create the object and installation directories for the cross compilation tools
57installDir=$haikuOutputDir/developer-tools
58objDir=$haikuOutputDir/developer-tools-build
59binutilsObjDir=$objDir/binutils
60gccObjDir=$objDir/gcc
61
62rm -rf $installDir $objDir
63mkdir -p $installDir $objDir $binutilsObjDir $gccObjDir $tmpIncludeDir \
64    $tmpLibDir || exit 1
65
66#
67# 3. Copy necessities
68#
69
70cd $haikuOutputDir/objects/haiku/x86/release/system/glue/arch/x86
71cp crti.o crtn.o ../../../../../../../../cross-tools/i586-pc-beos/lib
72cd $currentDir
73
74# Copy init_term_dyn.o and start_dyn.o
75cd $haikuOutputDir/objects/haiku/x86/release/system/glue
76cp init_term_dyn.o start_dyn.o ../../../../../../cross-tools/i586-pc-beos/lib
77cd $currentDir
78
79# Copy system libs
80cd $haikuOutputDir/objects/haiku/x86/release
81cp system/libroot/libroot.so ../../../../cross-tools/lib/gcc-lib/i586-pc-beos/2.95.3-beos-060710
82cd $currentDir
83
84# Copy Haiku POSIX headers and their dependencies
85copy_headers()
86{
87    sourceDir=$1
88    targetDir=$2
89
90    headers="$(find $sourceDir -name \*\.h | grep -v /.svn)"
91    headers="$(echo $headers | sed -e s@$sourceDir/@@g)"
92    for f in $headers; do
93        headerTargetDir=$targetDir/$(dirname $f)
94        mkdir -p $headerTargetDir
95        cp $sourceDir/$f $headerTargetDir
96    done
97}
98
99copy_headers $haikuSourceDir/headers/os $haikuOutputDir/cross-tools/i586-pc-beos/sys-include/be
100copy_headers $haikuSourceDir/headers/posix $haikuOutputDir/cross-tools/i586-pc-beos/sys-include/posix
101
102#
103# 4. Build binutils
104#
105cd $binutilsObjDir
106
107PATH=$haikuOutputDir/cross-tools/bin:$PATH 
108
109$buildToolsDir/binutils/configure --prefix=$installDir --host=i586-pc-beos --build=i486-linux-gnu --target=i586-pc-beos --disable-nls --enable-shared=yes --disable-werror || exit 1
110
111make || exit 1
112
113make install || exit 1
114
115#
116# 5. Build gcc
117#
118
119# configure gcc
120cd $gccObjDir
121CFLAGS="-O2" CXXFLAGS="-O2" $buildToolsDir/gcc/configure --prefix=$installDir \
122    --host=i586-pc-beos --build=i486-linux-gnu --target=i586-pc-beos --disable-nls \
123    --enable-shared=yes --enable-languages=c,c++ || exit 1
124
125# hack the Makefile to avoid trouble with stuff we don't need anyway
126sedExpr=
127for toRemove in libiberty libio libjava libobjc libstdc++; do
128    sedExpr="$sedExpr -e 's@^\(TARGET_CONFIGDIRS =.*\)$toRemove\(.*\)@\1\2@'"
129done
130echo sedExpr: $sedExpr
131mv Makefile Makefile.bak || exit 1
132eval "sed $sedExpr Makefile.bak > Makefile" || exit 1
133rm Makefile.bak
134
135# make gcc
136make || {
137    echo "ERROR: Building gcc failed." >&2
138    exit 1
139}
140
141# install gcc
142make install-gcc-cross || {
143    echo "ERROR: Installing the cross compiler failed." >&2
144    exit 1
145}
146
147#
148# 6. Copy headers into the developer-tools
149#
150
151copy_headers $haikuSourceDir/headers/os $installDir/i586-pc-beos/sys-include/be
152copy_headers $haikuSourceDir/headers/posix $installDir/i586-pc-beos/sys-include/posix