cookutils view cross @ rev 366

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