Mercurial > hg > aboriginal
comparison build.sh @ 33:bf2e771f4ba5
Update build script. Now uses a config file (usage: ./build.sh arch), and
generates a tarball of the cross-compiler.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 11 Dec 2006 00:48:20 -0500 |
parents | 8b75dee28f40 |
children |
comparison
equal
deleted
inserted
replaced
32:877349490008 | 33:bf2e771f4ba5 |
---|---|
1 #!/bin/sh | 1 #!/bin/sh |
2 | 2 |
3 # Memo: How should I pass this in? | 3 # Memo: How should I pass this in? |
4 | 4 |
5 ARCH=armv4l | 5 ARCH="$(echo "$1" | sed 's@.*/@@')" |
6 CLEANUP=echo #rm -rf | 6 if [ ! -f sources/configs/"$1" ] |
7 | |
8 if [ $ARCH == armv4l ] | |
9 then | 7 then |
10 KARCH=arm | 8 echo "Usage: $0 ARCH" |
11 # GCC_FLAGS="--with-float=soft" | 9 echo "Supported architectures: $(cd sources/configs && ls)" |
10 exit 1 | |
12 fi | 11 fi |
13 | 12 |
14 if [ $ARCH = armv5l ] | 13 CLEANUP="rm -rf" |
15 then | |
16 KARCH=arm | |
17 GCC_FLAGS="--with-float=soft --without-fp --with-cpu=xscale" | |
18 # --target=armv5l-linux | |
19 fi | |
20 | |
21 if [ $ARCH == x86_64 ] | |
22 then | |
23 KARCH=$ARCH | |
24 GCC_FLAGS="-m64" | |
25 fi | |
26 | 14 |
27 function dienow() | 15 function dienow() |
28 { | 16 { |
29 echo "Exiting due to errors" | 17 echo "Exiting due to errors" |
30 exit 1 | 18 exit 1 |
49 # Extract package $1, use work directory $2 (or $1 if no $2), use source | 37 # Extract package $1, use work directory $2 (or $1 if no $2), use source |
50 # directory $3 (or $1 if no $3) | 38 # directory $3 (or $1 if no $3) |
51 | 39 |
52 function setupfor() | 40 function setupfor() |
53 { | 41 { |
42 FILE="${SOURCES}/${STAGE}/$1" | |
43 if [ -f "${FILE}".tar.bz2 ] | |
44 then | |
45 FILE="${FILE}".tar.bz2 | |
46 DECOMPRESS="j" | |
47 else | |
48 FILE="${FILE}".tar.gz | |
49 DECOMPRESS="z" | |
50 fi | |
54 echo "=== Building $1" | 51 echo "=== Building $1" |
55 echo -n "Extracting" | 52 echo -n "Extracting" |
56 cd "${WORK}" && | 53 cd "${WORK}" && |
57 { tar xvjf "${SOURCES}/${STAGE}/$1".tar.bz2 || dienow | 54 { tar xv${DECOMPRESS}f "$FILE" || dienow |
58 } | dotprogress | 55 } | dotprogress |
59 if [ -z "$2" ] | 56 if [ -z "$2" ] |
60 then | 57 then |
61 cd "$1"* || dienow | 58 cd "$1"* || dienow |
62 else | 59 else |
76 | 73 |
77 # Find/create directories | 74 # Find/create directories |
78 | 75 |
79 TOP=`pwd` | 76 TOP=`pwd` |
80 export SOURCES="${TOP}/sources" | 77 export SOURCES="${TOP}/sources" |
81 export CROSS="${TOP}/build/cross-compiler" | 78 export CROSS="${TOP}/build/cross-compiler-$ARCH" |
82 export WORK="${TOP}/build/temp" | 79 export WORK="${TOP}/build/temp" |
83 mkdir -p "${CROSS}" "${WORK}" | 80 mkdir -p "${CROSS}" "${WORK}" |
84 | 81 |
85 [ $? -ne 0 ] && dienow | 82 [ $? -ne 0 ] && dienow |
86 | 83 |
94 export CROSS_HOST=i686-pc-linux-gnu | 91 export CROSS_HOST=i686-pc-linux-gnu |
95 export CROSS_TARGET=${ARCH}-unknown-linux-gnu | 92 export CROSS_TARGET=${ARCH}-unknown-linux-gnu |
96 | 93 |
97 export STAGE=build-cross | 94 export STAGE=build-cross |
98 | 95 |
99 # Install the linux kernel headers. | 96 # Import the config for this arch. |
100 | 97 |
101 setupfor linux | 98 . sources/configs/"$ARCH" |
102 make headers_install ARCH="${KARCH}" INSTALL_HDR_PATH="${CROSS}" | |
103 | |
104 [ $? -ne 0 ] && dienow | |
105 | 99 |
106 # Build and install binutils | 100 # Build and install binutils |
107 | 101 |
108 setupfor binutils build-binutils | 102 setupfor binutils build-binutils |
109 "${CURSRC}/configure" --prefix="${CROSS}" --host=${CROSS_HOST} \ | 103 "${CURSRC}/configure" --prefix="${CROSS}" --host=${CROSS_HOST} \ |
110 --target=${CROSS_TARGET} --with-lib-path=lib --disable-nls \ | 104 --target=${CROSS_TARGET} --with-lib-path=lib --disable-nls \ |
111 --disable-shared --enable-64-bit-bfd --disable-multilib && | 105 --disable-shared --disable-multilib $BINUTILS_FLAGS && |
112 make configure-host && | 106 make configure-host && |
113 make && | 107 make && |
114 make install && | 108 make install && |
115 cd .. && | 109 cd .. && |
110 mkdir -p "${CROSS}/include" && | |
116 cp binutils-*/include/libiberty.h "${CROSS}/include" && | 111 cp binutils-*/include/libiberty.h "${CROSS}/include" && |
117 $CLEANUP binutils-* build-binutils | 112 $CLEANUP binutils-* build-binutils |
118 | 113 |
119 [ $? -ne 0 ] && dienow | 114 [ $? -ne 0 ] && dienow |
120 | 115 |
121 # Build and install gcc | 116 # Build and install gcc |
122 | 117 |
123 setupfor gcc-core build-gcc gcc- | 118 setupfor gcc-core build-gcc gcc- |
124 "${CURSRC}/configure" --prefix="${CROSS}" --host=${CROSS_HOST} \ | 119 "${CURSRC}/configure" --prefix="${CROSS}" --host=${CROSS_HOST} \ |
125 --target=${CROSS_TARGET} \ | 120 --target=${CROSS_TARGET} --disable-threads --enable-languages=c \ |
126 --disable-multilib --disable-nls --disable-shared $GCC_FLAGS \ | 121 --disable-multilib --disable-nls --disable-shared $GCC_FLAGS |
127 --disable-threads --enable-languages=c | |
128 #--with-local-prefix="${CROSS}" \ | 122 #--with-local-prefix="${CROSS}" \ |
129 # --enable-languages=c,c++ --enable-__cxa_atexit --enable-c99 \ | 123 # --enable-languages=c,c++ --enable-__cxa_atexit --enable-c99 \ |
130 # --enable-long-long --enable-threads=posix && | 124 # --enable-long-long --enable-threads=posix && |
131 make all-gcc && | 125 make all-gcc && |
132 make install-gcc && | 126 make install-gcc && |
145 mv "$GCCNAME" "${CROSS}"/bin/gcc-unwrapped && | 139 mv "$GCCNAME" "${CROSS}"/bin/gcc-unwrapped && |
146 gcc "${TOP}"/sources/toys/gcc-uClibc.c -Os -s -o "$GCCNAME" | 140 gcc "${TOP}"/sources/toys/gcc-uClibc.c -Os -s -o "$GCCNAME" |
147 | 141 |
148 [ $? -ne 0 ] && dienow | 142 [ $? -ne 0 ] && dienow |
149 | 143 |
144 # Install the linux kernel, and kernel headers. | |
145 | |
146 setupfor linux | |
147 # Configure kernel | |
148 ##mv "${WORK}"/config-linux .config && | |
149 ##(yes "" | make ARCH="${KARCH}" oldconfig) && | |
150 # Install Linux kernel headers (for use by uClibc). | |
151 make headers_install ARCH="${KARCH}" INSTALL_HDR_PATH="${CROSS}" && | |
152 # Build bootable kernel for target. | |
153 ##make ARCH="${KARCH}" CROSS_COMPILE="${CROSS_TARGET}"- && | |
154 ##cp "${KERNEL_PATH}" "${CROSS}"/zImage && | |
155 cd .. && | |
156 $CLEANUP linux-* | |
157 | |
158 [ $? -ne 0 ] && dienow | |
159 | |
150 # Build and install uClibc | 160 # Build and install uClibc |
151 | 161 |
152 setupfor uClibc | 162 setupfor uClibc |
153 | 163 cp "${WORK}"/config-uClibc .config && |
154 cp "${TOP}"/sources/configs/uClibc-config-"${KARCH}" .config && | |
155 (yes "" | make CROSS="${CROSS_TARGET}"- oldconfig) && | 164 (yes "" | make CROSS="${CROSS_TARGET}"- oldconfig) && |
156 make CROSS="${CROSS_TARGET}"- KERNEL_SOURCE="${CROSS}" && | 165 make CROSS="${CROSS_TARGET}"- KERNEL_SOURCE="${CROSS}" && |
157 #make CROSS="${CROSS_TARGET}"- utils && | 166 #make CROSS="${CROSS_TARGET}"- utils && |
158 # The kernel headers are already installed, but uClibc's install will try to | 167 # The kernel headers are already installed, but uClibc's install will try to |
159 # be "helpful" and copy them over themselves, at which point hilarity ensues. | 168 # be "helpful" and copy them over themselves, at which point hilarity ensues. |
169 ln -s "${CROSS}"/include/linux include/linux && | 178 ln -s "${CROSS}"/include/linux include/linux && |
170 ln -s "${CROSS}"/include/asm include/asm && | 179 ln -s "${CROSS}"/include/asm include/asm && |
171 ln -s "${CROSS}"/include/asm-generic include/asm-generic && | 180 ln -s "${CROSS}"/include/asm-generic include/asm-generic && |
172 make CROSS=${CROSS_TARGET}- RUNTIME_PREFIX="${CROSS}"/ install_utils && | 181 make CROSS=${CROSS_TARGET}- RUNTIME_PREFIX="${CROSS}"/ install_utils && |
173 cd .. && | 182 cd .. && |
174 $CLEANUP uClibc-* | 183 $CLEANUP uClibc* |
175 | 184 |
176 [ $? -ne 0 ] && dienow | 185 [ $? -ne 0 ] && dienow |
177 | 186 |
178 # A quick hello world program to test the cross-compiler out. | 187 # A quick hello world program to test the cross-compiler out. |
179 | 188 |
185 printf("Hello world!\n"); | 194 printf("Hello world!\n"); |
186 return 0; | 195 return 0; |
187 } | 196 } |
188 EOF | 197 EOF |
189 | 198 |
190 # Build something dynamic, then static, to verify header/library paths. | 199 # Build hello.c dynamic, then static, to verify header/library paths. |
191 | 200 |
192 "$GCCNAME" -Os "$WORK"/hello.c -o "$WORK"/hello && | 201 "$GCCNAME" -Os "$WORK"/hello.c -o "$WORK"/hello && |
193 "$GCCNAME" -Os -static "$WORK"/hello.c -o "$WORK"/hello && | 202 "$GCCNAME" -Os -static "$WORK"/hello.c -o "$WORK"/hello && |
194 [ x"$(qemu-${KARCH} "${WORK}"/hello)" == x"Hello world!" ] && | 203 [ x"$(qemu-"${KARCH}" "${WORK}"/hello)" == x"Hello world!" ] && |
195 echo Cross-toolchain seems to work. | 204 echo Cross-toolchain seems to work. |
196 | 205 |
197 [ $? -ne 0 ] && dienow | 206 [ $? -ne 0 ] && dienow |
198 | 207 |
208 # Change the FSF's crazy names to something reasonable. | |
209 | |
210 cd "${CROSS}"/bin && | |
211 for i in "${ARCH}"-* | |
212 do | |
213 strip "$i" | |
214 mv "$i" "${ARCH}"-"$(echo "$i" | sed 's/.*-//')" | |
215 done | |
216 | |
217 cat > "${CROSS}"/README << "EOF" && | |
218 Cross compiler for $ARCH | |
219 From http://landley.net/code/firmware | |
220 | |
221 To use: Add the \"bin\" directory to your \$PATH, and use \"$ARCH-gcc\" as | |
222 your compiler. | |
223 | |
224 The syntax used to build the Linux kernel is: | |
225 | |
226 make ARCH="${KARCH}" CROSS_COMPILE="${ARCH}"- | |
227 | |
228 EOF | |
229 | |
230 # Tar up the cross compiler. | |
231 cd "${TOP}" | |
232 tar cjvCf build cross-compiler-"${ARCH}".tar.bz2 cross-compiler-"${ARCH}" && | |
233 | |
234 [ $? -ne 0 ] && dienow |