cookutils view cross @ rev 370

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