cookutils view cross @ rev 365

cross: small fix
author Christophe Lincoln <pankso@slitaz.org>
date Thu May 10 02:08:29 2012 +0200 (2012-05-10)
parents 1f0ff5d5fdd8
children 23aed475bdf2
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 [ -f "$SRC/glibc-ports-$GLIBC_VERSION.tar.bz2" ] || wget \
122 http://ftp.gnu.org/gnu/libc/glibc-ports-$GLIBC_VERSION.tar.bz2 \
123 -O $SRC/glibc-ports-$GLIBC_VERSION.tar.bz2 || exit 1
124 echo "Extracting: glibc-ports-$GLIBC_VERSION.tar.bz2"
125 rm -rf glibc-$GLIBC_VERSION/ports
126 tar xjf $SRC/glibc-ports-$GLIBC_VERSION.tar.bz2
127 mv glibc-ports-$GLIBC_VERSION glibc-$GLIBC_VERSION/ports ;;
128 x86_64)
129 archopts="" ;;
130 esac
131 mkdir -p glibc-build && cd glibc-build
132 BUILD_CC="gcc" \
133 CC="$PREFIX/bin/$TARGET-gcc" \
134 libc_cv_forced_unwind=yes \
135 libc_cv_c_cleanup=yes \
136 ../glibc-$GLIBC_VERSION/configure \
137 --prefix=$PREFIX \
138 --host=$TARGET \
139 --with-headers=$PREFIX/include \
140 --with-binutils=$PREFIX/bin \
141 --enable-add-ons
142 make || exit 1
143 make install
144 cd $PREFIX/$TARGET
145 rm -rf lib include
146 ln -s ../lib lib
147 ln -s ../include include
148 }
150 # 5. GCC final
151 gcc_final() {
152 if [ ! -d "gcc-$GCC_VERSION" ]; then
153 echo "Extracting: gcc-$GCC_VERSION.tar.bz2"
154 tar xjf $SRC/gcc-$GCC_VERSION.tar.bz2
155 fi
156 # Peer arch options
157 case $ARCH in
158 arm) archopts="" ;;
159 x86_64) archopts="" ;;
160 esac
161 rm -rf gcc-build
162 mkdir gcc-build && cd gcc-build
163 ../gcc-$GCC_VERSION/configure \
164 --prefix=$PREFIX \
165 --target=$TARGET \
166 --enable-shared \
167 --enable-languages=c,c++ \
168 --enable-c99 \
169 --enable-long-long \
170 --enable-__cxa_atexit \
171 --with-pkgversion="SliTaz"
172 make || exit 1
173 make install
174 }
176 # Build Busybox to we can create prebuild tiny rootfs image and boot
177 # from NFS ?
178 cross_busybox() {
179 echo "Extracting: busybox-$BUSYBOX_VERSION.tar.bz2"
180 tar xjf $SRC/busybox-$BUSYBOX_VERSION.tar.bz2
181 cd busybox-$BUSYBOX_VERSION
182 # CROSS_COMPILE is exported via init_compile, but be sure.
183 make CROSS_COMPILE=$TARGET- defconfig
184 make CROSS_COMPILE=$TARGET- || exit 1
185 make CROSS_COMPILE=$TARGET- install
186 chmod 4755 _install/bin/busybox
187 readelf -h _install/bin/busybox
188 }
190 #
191 # Commands
192 #
194 case "$1" in
195 howto|man)
196 doc=/usr/share/doc/cookutils/cross.txt
197 [ -f "$doc" ] && less -E $doc ;;
198 info)
199 init_compile
200 CC=${TARGET}-gcc
201 echo -e "\nCross Toolchain iformation" && separator
202 cat << EOT
203 Target arch : $ARCH
204 C Compiler : $CC
205 Additonal path: /usr/cross/$ARCH/bin
206 EOT
207 separator && echo ""
208 echo "GCC version" && separator
209 $CC -v
210 separator && echo "" ;;
211 testsuite)
212 init_compile
213 echo "[COMPILING] $TARGET-gcc -v -Wall -o test.out test.c" \
214 | tee $logdir/testsuite.log
215 echo 'int main() { return 0; }' > test.c
216 $TARGET-gcc -v -Wall -o test.out test.c 2>&1 | tee -a $logdir/testsuite.log
217 if [ -x /usr/bin/file ]; then
218 echo -e "\n[CHECKING] file test.out" | tee -a $logdir/testsuite.log
219 file test.out | tee -a $logdir/testsuite.log
220 fi
221 echo -e "\n[CHECKING] readelf -h test.out" | tee -a $logdir/testsuite.log
222 readelf -h test.out | tee -a $logdir/testsuite.log ;;
223 check-env)
224 for pkg in mpfr mpfr-dev gmp gmp-dev mpc-library gawk autoconf
225 do
226 if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then
227 echo "Missing packages: $pkg"
228 [ "$install" ] && tazpkg -gi $pkg
229 fi
230 done ;;
231 download)
232 download_src ;;
233 clean)
234 echo -n "Remove all source files..."
235 rm -rf $WORK/source/* && status
236 [ "$log" ] && rm -f $WORK/log/*.log
237 echo "To clean chroot: rm -rf $PREFIX" ;;
238 show-log)
239 pkg=$2
240 less -E $logdir/$pkg.log ;;
241 binutils)
242 init_compile
243 rm -f $logdir/binutils.log
244 binutils 2>&1 | tee $logdir/binutils.log ;;
245 linux-headers)
246 init_compile
247 linux_headers 2>&1 | tee $logdir/linux-headers.log ;;
248 gcc-static)
249 init_compile
250 gcc_static 2>&1 | tee $logdir/gcc-static.log ;;
251 glibc)
252 init_compile
253 glibc 2>&1 | tee $logdir/glibc.log ;;
254 gcc-final)
255 init_compile
256 gcc_final 2>&1 | tee $logdir/gcc-final.log ;;
257 busybox)
258 init_compile
259 cross_busybox 2>&1 | tee $logdir/busybox.log ;;
260 compile)
261 init_compile
262 echo "Compile start: $(date)" | tee $logdir/compile.log
263 download_src
264 binutils 2>&1 | tee $logdir/binutils.log
265 linux_headers 2>&1 | tee $logdir/linux-headers.log
266 gcc_static 2>&1 | tee $logdir/gcc-static.log
267 glibc 2>&1 | tee $logdir/glibc.log
268 gcc_final 2>&1 | tee $logdir/gcc-final.log
269 echo ""
270 echo "Compile end : $(date)" | tee -a $logdir/compile.log
271 echo "" ;;
272 *)
273 usage ;;
274 esac