cookutils view cross @ rev 361

Add cross (let have a cross toolchain builder)
author Christophe Lincoln <pankso@slitaz.org>
date Wed May 09 22:15:39 2012 +0200 (2012-05-09)
parents
children e60f4a6df297
line source
1 #!/bin/sh
2 #
3 # Cross - Help build a cross toolchain on SliTaz.
4 #
5 # Copyright 2012 (C) SliTaz GNU/Linux - BSD License
6 # Author: Christophe Lincoln <pankso@slitaz.org>
7 #
8 . /lib/libtaz.sh
9 . cross.conf || exit 1
11 # Help and usage.
12 usage() {
13 cat << EOT
15 Usage: $(basename $0) command --option
17 Commands:
18 howto Man alike and howto
19 info Dispaly cross-tools info
20 testsuite Execute a small testsuite
21 check-env Check build host tools
22 download Download necessary sources
23 clean Clean-up environment
24 show-log Show a compile log
25 binutils Compile Binutils
26 gcc-static Compile GCC static
27 linux-headers Install Kernel headers
28 glibc Compile GNU Glibc
29 gcc-final Compile final GCC
30 busybox Cross compile Busybox
31 compile Compile everything at once
33 EOT
34 }
36 # Make sure we have all directories.
37 init_compile() {
38 export LC_ALL=POSIX LANG=POSIX
39 export PATH=$PATH:$PREFIX/bin
40 export CROSS_COMPILE=$TARGET-
41 source=$WORK/source
42 logdir=$WORK/log
43 mkdir -p $source $logdir $install
44 cd $source
45 }
47 # Get source if not yet in $SRC.
48 download_src() {
49 mkdir -p $SRC && cd $SRC
50 [ -f "binutils-$BINUTILS_VERSION.tar.bz2" ] || wget $BINUTILS_WGET
51 [ -f "linux-$LINUX_VERSION.tar.bz2" ] || wget $LINUX_WGET
52 [ -f "glibc-$GLIBC_VERSION.tar.bz2" ] || wget $GLIBC_WGET
53 [ -f "gcc-$GCC_VERSION.tar.bz2" ] || wget $GCC_WGET
54 [ -f "busybox-$BUSYBOX_VERSION.tar.bz2" ] || wget $BUSYBOX_WGET
55 }
57 # 1. Binutils
58 binutils() {
59 echo "Extracting: binutils-$BINUTILS_VERSION.tar.bz2"
60 tar xjf $SRC/binutils-$BINUTILS_VERSION.tar.bz2
61 # Peer arch options --disable-werror
62 case $ARCH in
63 arm) archopts="" ;;
64 x86_64) archopts="" ;;
65 esac
66 cd binutils-$BINUTILS_VERSION
67 ./configure \
68 --prefix=$PREFIX \
69 --target=$TARGET \
70 --enable-targets=$BUILD_SYSTEM \
71 --enable-shared $archopts
72 make || exit 1
73 make install
74 }
76 # 2. Kernel headers
77 linux_headers() {
78 echo "Extracting: linux-$LINUX_VERSION.tar.bz2"
79 tar xjf $SRC/linux-$LINUX_VERSION.tar.bz2
80 cd linux-$LINUX_VERSION
81 make mrproper
82 make ARCH=$ARCH headers_check
83 make ARCH=$ARCH headers_install \
84 INSTALL_HDR_PATH=$PREFIX
85 }
87 # 3. GCC static (first pass)
88 gcc_static() {
89 echo "Extracting: gcc-$GCC_VERSION.tar.bz2"
90 tar xjf $SRC/gcc-$GCC_VERSION.tar.bz2
91 # Peer arch options
92 case $ARCH in
93 arm) archopts="" ;;
94 x86_64) archopts="" ;;
95 esac
96 rm -rf gcc-static
97 mkdir gcc-static && cd gcc-static
98 ../gcc-$GCC_VERSION/configure \
99 --prefix=$PREFIX \
100 --target=$TARGET \
101 --disable-shared \
102 --disable-threads \
103 --without-headers \
104 --with-newlib \
105 --enable-languages=c
106 make all-gcc all-target-libgcc || exit 1
107 make install-gcc install-target-libgcc
108 cd $PREFIX/lib/gcc/$TARGET/$GCC_VERSION
109 ln -s libgcc.a libgcc_eh.a
110 }
112 # 4. GNU Glibc
113 glibc() {
114 echo "Extracting: glibc-$GLIBC_VERSION.tar.bz2"
115 tar xjf $SRC/glibc-$GLIBC_VERSION.tar.bz2
116 [ "$continue" ] || rm -rf glibc-build
117 # Peer arch options
118 case $ARCH in
119 arm)
120 archopts=""
121 echo "Extracting: glibc-ports-$GLIBC_VERSION.tar.bz2"
122 rm -rf glibc-$GLIBC_VERSION/ports
123 tar xjf $SRC/glibc-ports-$GLIBC_VERSION.tar.bz2
124 mv glibc-ports-$GLIBC_VERSION glibc-$GLIBC_VERSION/ports ;;
125 x86_64)
126 archopts="" ;;
127 esac
128 mkdir -p glibc-build && cd glibc-build
129 BUILD_CC="gcc"
130 CC="$PREFIX/bin/$TARGET-gcc" \
131 libc_cv_forced_unwind=yes \
132 libc_cv_c_cleanup=yes \
133 ../glibc-$GLIBC_VERSION/configure \
134 --prefix=$PREFIX \
135 --host=$TARGET \
136 --with-headers=$PREFIX/include \
137 --with-binutils=$PREFIX/bin \
138 --enable-add-ons
139 make || exit 1
140 make install
141 cd $PREFIX/$TARGET
142 rm -rf lib include
143 ln -s ../lib lib
144 ln -s ../include include
145 }
147 # 5. GCC final
148 gcc_final() {
149 if [ ! -d "gcc-$GCC_VERSION" ]; then
150 echo "Extracting: gcc-$GCC_VERSION.tar.bz2"
151 tar xjf $SRC/gcc-$GCC_VERSION.tar.bz2
152 fi
153 # Peer arch options
154 case $ARCH in
155 arm) archopts="" ;;
156 x86_64) archopts="" ;;
157 esac
158 rm -rf gcc-build
159 mkdir gcc-build && cd gcc-build
160 ../gcc-$GCC_VERSION/configure \
161 --prefix=$PREFIX \
162 --target=$TARGET \
163 --enable-shared \
164 --enable-languages=c,c++ \
165 --enable-c99 \
166 --enable-long-long \
167 --enable-__cxa_atexit \
168 --with-pkgversion="SliTaz"
169 make || exit 1
170 make install
171 }
173 # Build Busybox to we can create prebuild tiny rootfs image and boot
174 # from NFS ?
175 cross_busybox() {
176 echo "Extracting: busybox-$BUSYBOX_VERSION.tar.bz2"
177 tar xjf $SRC/busybox-$BUSYBOX_VERSION.tar.bz2
178 cd busybox-$BUSYBOX_VERSION
179 # CROSS_COMPILE is exported via init_compile, but be sure.
180 make CROSS_COMPILE=$TARGET- defconfig
181 make CROSS_COMPILE=$TARGET- || exit 1
182 make CROSS_COMPILE=$TARGET- install
183 chmod 4755 _install/bin/busybox
184 readelf -h _install/bin/busybox
185 }
187 #
188 # Commands
189 #
191 case "$1" in
192 howto|man)
193 doc=/usr/share/doc/cookutils/cross.txt
194 [ -f "$doc" ] && less -E $doc ;;
195 info)
196 init_compile
197 CC=${TARGET}-gcc
198 echo -e "\nCross Toolchain iformation" && separator
199 cat << EOT
200 Target arch : $ARCH
201 C Compiler : $CC
202 Additonal path: /usr/cross/$ARCH/bin
203 EOT
204 separator && echo ""
205 echo "GCC version" && separator
206 $CC -v
207 separator && echo "" ;;
208 testsuite)
209 init_compile
210 echo "[COMPILING] $TARGET-gcc -v -Wall -o test.out test.c" \
211 | tee $logdir/testsuite.log
212 echo 'int main() { return 0; }' > test.c
213 $TARGET-gcc -v -Wall -o test.out test.c 2>&1 | tee -a $logdir/testsuite.log
214 if [ -x /usr/bin/file ]; then
215 echo -e "\n[CHECKING] file test.out" | tee -a $logdir/testsuite.log
216 file test.out | tee -a $logdir/testsuite.log
217 fi
218 echo -e "\n[CHECKING] readelf -h test.out" | tee -a $logdir/testsuite.log
219 readelf -h test.out | tee -a $logdir/testsuite.log ;;
220 check-host)
221 for pkg in mpfr mpfr-dev gmp gmp-dev mpc-library gawk autoconf
222 do
223 if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then
224 echo "Missing packages: $pkg"
225 [ "$install" ] && tazpkg -gi $pkg
226 fi
227 done ;;
228 download)
229 download_src ;;
230 clean)
231 echo -n "Remove all source files..."
232 rm -rf $WORK/source/* && status
233 [ "$log" ] && rm -f $WORK/log/*.log
234 echo "To clean chroot: rm -rf $PREFIX" ;;
235 show-log)
236 pkg=$2
237 less -E $logdir/$pkg.log ;;
238 binutils)
239 init_compile
240 rm -f $logdir/binutils.log
241 binutils 2>&1 | tee $logdir/binutils.log ;;
242 linux-headers)
243 init_compile
244 linux_headers 2>&1 | tee $logdir/$logdir/linux-headers.log ;;
245 gcc-static)
246 init_compile
247 gcc_static 2>&1 | tee $logdir/gcc-static.log ;;
248 glibc)
249 init_compile
250 glibc 2>&1 | tee $logdir/glibc.log ;;
251 gcc-final)
252 init_compile
253 gcc_final 2>&1 | tee $logdir/gcc-final.log ;;
254 busybox)
255 init_compile
256 cross_busybox 2>&1 | tee $logdir/busybox.log ;;
257 compile)
258 init_compile
259 echo "Compile start: $(date)" | tee $logdir/compile.log
260 download_src
261 binutils 2>&1 | tee $logdir/binutils.log
262 linux_headers 2>&1 | tee $logdir/linux-headers.log
263 gcc_static 2>&1 | tee $logdir/gcc-static.log
264 glibc 2>&1 | tee $logdir/glibc.log
265 gcc_final 2>&1 | tee $logdir/gcc-final.log
266 echo ""
267 echo "Compile end: $(date)" | tee -a $logdir/compile.log
268 echo "" ;;
269 *)
270 usage ;;
271 esac