cookutils annotate cross @ rev 771
cooker.cgi: add recook button
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Fri Nov 13 12:33:57 2015 +0100 (2015-11-13) |
parents | f2cd25cd9120 |
children | 3f0ca4492ec7 |
rev | line source |
---|---|
pankso@361 | 1 #!/bin/sh |
pankso@361 | 2 # |
pankso@361 | 3 # Cross - Help build a cross toolchain on SliTaz. |
pankso@361 | 4 # |
al@728 | 5 # Copyright 2012-2015 (C) SliTaz GNU/Linux - BSD License |
pankso@361 | 6 # Author: Christophe Lincoln <pankso@slitaz.org> |
pankso@361 | 7 # |
al@728 | 8 |
pankso@361 | 9 . /lib/libtaz.sh |
pankso@370 | 10 |
pankso@370 | 11 [ -f "/etc/slitaz/cross.conf" ] && . /etc/slitaz/cross.conf |
pankso@370 | 12 [ -f "cross.conf" ] && . ./cross.conf |
pankso@361 | 13 |
al@728 | 14 |
pankso@374 | 15 # Handle --config=/path/to/cross.conf |
al@728 | 16 |
pankso@374 | 17 [ "$config" ] && . $config |
al@728 | 18 source="$WORK/source" |
al@728 | 19 tools="$WORK/tools" |
al@728 | 20 sysroot="$WORK/sysroot" |
al@728 | 21 logdir="$WORK/log" |
al@728 | 22 |
pankso@374 | 23 |
pankso@649 | 24 # Cross-tools tarballs |
al@728 | 25 |
pankso@649 | 26 binutils_tarball="binutils-$BINUTILS_VERSION.tar.bz2" |
pankso@649 | 27 linux_tarball="linux-$LINUX_VERSION.tar.xz" |
pankso@649 | 28 glibc_tarball="glibc-$GLIBC_VERSION.tar.bz2" |
pankso@649 | 29 eglibc_tarball="eglibc-$EGLIBC_VERSION.tar.bz2" |
pankso@649 | 30 gcc_tarball="gcc-$GCC_VERSION.tar.bz2" |
pankso@654 | 31 libtool_tarball="libtool-$LIBTOOL_VERSION.tar.gz" |
pankso@649 | 32 |
al@728 | 33 |
pankso@649 | 34 # Cross-tools URLs |
al@728 | 35 |
pankso@649 | 36 binutils_wget="http://ftp.gnu.org/gnu/binutils/$binutils_tarball" |
pankso@649 | 37 linux_wget="http://www.kernel.org/pub/linux/kernel/v3.x/$linux_tarball" |
pankso@649 | 38 glibc_wget="http://ftp.gnu.org/gnu/libc/$glibc_tarball" |
pankso@681 | 39 eglibc_wget="http://mirror.slitaz.org/arm/src/$eglibc_tarball" |
pankso@681 | 40 eglibc_svn="svn://svn.eglibc.org/branches/eglibc-2_14" |
pankso@649 | 41 gcc_wget="http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/$gcc_tarball" |
pankso@654 | 42 libtool_wget="ftp://sunsite.cnlab-switch.ch/mirror/gnu/libtool/$libtool_tarball" |
pankso@649 | 43 |
al@728 | 44 |
pankso@361 | 45 # Help and usage. |
al@728 | 46 |
pankso@361 | 47 usage() { |
al@728 | 48 cat <<EOT |
pankso@361 | 49 |
pankso@361 | 50 Usage: $(basename $0) command --option |
pankso@361 | 51 |
pankso@361 | 52 Commands: |
paul@495 | 53 howto Man[like] page and howto |
paul@382 | 54 info Display cross-tools info |
pankso@361 | 55 testsuite Execute a small testsuite |
pankso@654 | 56 [arch]-setup Setup build host environment |
pankso@361 | 57 download Download necessary sources |
pankso@654 | 58 show-log Show a package compile log |
pankso@361 | 59 binutils Compile Binutils |
pankso@421 | 60 linux-headers Install Kernel headers |
pankso@361 | 61 gcc-static Compile GCC static |
pankso@654 | 62 glibc Compile GNU Glibc library |
pankso@654 | 63 eglibc Compile EGlibc libc library |
pankso@361 | 64 gcc-final Compile final GCC |
pankso@361 | 65 compile Compile everything at once |
pankso@654 | 66 libtool Cross GNU Libtool (test in receipt LIBTOOL=) |
pankso@419 | 67 clean Clean-up build environment |
pankso@441 | 68 clean-tools Clean: $tools |
paul@455 | 69 gen-prebuilt Create a prebuilt toolchain archive |
pankso@361 | 70 |
pankso@361 | 71 EOT |
pankso@361 | 72 } |
pankso@361 | 73 |
al@728 | 74 |
pankso@420 | 75 # Prebuilt README |
al@728 | 76 |
pankso@420 | 77 prebuilt_readme() { |
al@728 | 78 echo -n 'Creating toolchain README...' |
al@728 | 79 cat >> $package/README <<EOT |
pankso@420 | 80 |
pankso@420 | 81 SliTaz Prebuilt $ARCH cross toolchain |
pankso@420 | 82 ================================================================================ |
pankso@420 | 83 Move this $ARCH cross compilation toolchain to /usr/cross then add tools |
pankso@420 | 84 to your PATH environment and test the toolchain: |
pankso@420 | 85 |
pankso@441 | 86 # mv $ARCH /cross |
pankso@441 | 87 # export PATH=\$PATH:/cross/$ARCH/tools/bin |
pankso@420 | 88 |
pankso@420 | 89 # echo 'int main() { return 0; }' > test.c |
pankso@420 | 90 # $TARGET-gcc -v -o test.out test.c |
pankso@420 | 91 # readelf -h test.out |
pankso@420 | 92 |
pankso@420 | 93 ================================================================================ |
pankso@420 | 94 |
pankso@420 | 95 EOT |
pankso@420 | 96 status |
pankso@420 | 97 } |
pankso@420 | 98 |
al@728 | 99 |
pankso@361 | 100 # Make sure we have all directories. |
al@728 | 101 |
pankso@361 | 102 init_compile() { |
pankso@441 | 103 unset CFLAGS CXXFLAGS |
pankso@361 | 104 export LC_ALL=POSIX LANG=POSIX |
pankso@441 | 105 export PATH=$PATH:$tools/bin |
pankso@400 | 106 export CROSS_COMPILE=${TARGET}- |
pankso@441 | 107 mkdir -p $source $logdir $sysroot $tools |
pankso@441 | 108 echo "Tools prefix : --prefix=$tools " |
pankso@441 | 109 echo "Target sysroot : --with-sysroot=$sysroot" |
pankso@361 | 110 cd $source |
pankso@361 | 111 } |
pankso@361 | 112 |
al@728 | 113 |
pankso@651 | 114 # Some arch may need custom CFLAGS to build Glibc/Eglibc |
al@728 | 115 |
pankso@651 | 116 init_cflags() { |
pankso@651 | 117 case "$ARCH" in |
pankso@653 | 118 arm|armv6) export CFLAGS="-O2 -march=armv6" ;; |
al@728 | 119 armv6hf) export CFLAGS="-O2 -march=armv6j" ;; |
al@728 | 120 armv7) export CFLAGS="-Os -march=armv7-a" ;; |
pankso@651 | 121 esac |
pankso@651 | 122 } |
pankso@651 | 123 |
al@728 | 124 |
pankso@361 | 125 # Get source if not yet in $SRC. |
al@728 | 126 |
pankso@361 | 127 download_src() { |
al@728 | 128 mkdir -p $SRC; cd $SRC |
pankso@649 | 129 [ -f "$binutils_tarball" ] || wget $binutils_wget |
al@728 | 130 [ -f "$linux_tarball" ] || wget --no-check-certificate $linux_wget |
al@728 | 131 [ -f "$glibc_tarball" ] || wget $glibc_wget |
al@728 | 132 [ -f "$eglibc_tarball" ] || wget $eglibc_wget |
al@728 | 133 [ -f "$gcc_tarball" ] || wget $gcc_wget |
al@728 | 134 [ -f "$libtool_tarball" ] || wget $libtool_wget |
pankso@403 | 135 } |
pankso@403 | 136 |
al@728 | 137 |
pankso@361 | 138 # 1. Binutils |
al@728 | 139 |
pankso@361 | 140 binutils() { |
pankso@408 | 141 init_compile |
pankso@411 | 142 rm -rf binutils-$BINUTILS_VERSION |
pankso@649 | 143 echo "Extracting: $binutils_tarball" |
al@728 | 144 tar -xjf $SRC/$binutils_tarball |
pankso@421 | 145 echo "Configure: $BINUTILS_ARGS" |
pankso@361 | 146 cd binutils-$BINUTILS_VERSION |
pankso@361 | 147 ./configure \ |
pankso@441 | 148 --prefix=$tools \ |
pankso@361 | 149 --target=$TARGET \ |
pankso@440 | 150 --enable-plugins \ |
pankso@440 | 151 --enable-threads \ |
pankso@361 | 152 --enable-targets=$BUILD_SYSTEM \ |
pankso@441 | 153 --with-sysroot=$sysroot \ |
pankso@442 | 154 $BINUTILS_ARGS && |
pankso@361 | 155 make || exit 1 |
pankso@361 | 156 make install |
pankso@421 | 157 echo "cross: binutils compiled on: $(date)" |
pankso@361 | 158 } |
pankso@361 | 159 |
al@728 | 160 |
paul@455 | 161 # 2. Kernel headers could use CROSS_COMPILE but gcc is not yet built. |
al@728 | 162 |
pankso@421 | 163 linux_headers() { |
pankso@421 | 164 init_compile |
pankso@451 | 165 if [ ! -d "linux-$LINUX_VERSION" ]; then |
pankso@649 | 166 echo "Extracting: $linux_tarball" |
al@728 | 167 tar -xJf $SRC/$linux_tarball |
pankso@451 | 168 fi |
pankso@649 | 169 case "$ARCH" in |
al@728 | 170 armv6hf) KARCH='arm' ;; |
al@728 | 171 *) KARCH="$ARCH" ;; |
pankso@649 | 172 esac |
pankso@451 | 173 rm -rf linux-headers |
pankso@421 | 174 cd linux-$LINUX_VERSION |
pankso@649 | 175 make CROSS_COMPILE="" mrproper |
pankso@649 | 176 make ARCH=$KARCH headers_check |
pankso@649 | 177 make ARCH=$KARCH headers_install \ |
pankso@450 | 178 INSTALL_HDR_PATH=$source/linux-headers |
pankso@453 | 179 rm $source/linux-headers/include/.*install* |
pankso@450 | 180 echo "Copying headers to: $sysroot/usr" |
pankso@681 | 181 mkdir -p $sysroot/usr |
pankso@450 | 182 cp -a $source/linux-headers/* $sysroot/usr |
pankso@421 | 183 } |
pankso@421 | 184 |
al@728 | 185 |
pankso@447 | 186 # 2.1 Glibc headers needed to compile x86_64 gcc-static. |
al@728 | 187 |
pankso@447 | 188 glibc_headers() { |
pankso@447 | 189 init_compile |
pankso@649 | 190 echo "Extracting: $glibc_tarball" |
al@728 | 191 tar -xjf $SRC/$glibc_tarball |
pankso@447 | 192 rm -rf glibc-headers |
al@728 | 193 mkdir glibc-headers; cd glibc-headers |
pankso@450 | 194 libc_cv_forced_unwind=yes \ |
pankso@450 | 195 libc_cv_c_cleanup=yes \ |
pankso@447 | 196 ../glibc-$GLIBC_VERSION/configure \ |
pankso@447 | 197 --prefix=/usr \ |
pankso@447 | 198 --host=$TARGET \ |
pankso@447 | 199 --with-headers=$sysroot/usr/include \ |
pankso@447 | 200 --without-cvs \ |
pankso@447 | 201 --disable-sanity-checks \ |
pankso@447 | 202 --enable-kernel=2.6.32 && |
pankso@447 | 203 make -k install-headers install_root=$sysroot |
pankso@448 | 204 # Fixes |
pankso@448 | 205 mkdir -p $sysroot/usr/include/gnu |
pankso@448 | 206 touch $sysroot/usr/include/gnu/stubs.h |
al@728 | 207 |
erjo@680 | 208 # Fixe error: bits/stdio_lim.h not found |
erjo@680 | 209 #cp bits/stdio_lim.h $sysroot/usr/include/bits |
erjo@680 | 210 cp /usr/include/bits/stdio_lim.h $sysroot/usr/include/bits |
pankso@447 | 211 } |
pankso@447 | 212 |
al@728 | 213 |
pankso@421 | 214 # 3. GCC static (first pass) |
al@728 | 215 |
pankso@361 | 216 gcc_static() { |
pankso@408 | 217 init_compile |
pankso@649 | 218 echo "Extracting: $gcc_tarball" |
al@728 | 219 tar -xjf $SRC/$gcc_tarball |
pankso@421 | 220 echo "Configure: $GCC_STATIC_ARGS" |
pankso@361 | 221 rm -rf gcc-static |
al@728 | 222 mkdir gcc-static; cd gcc-static |
pankso@361 | 223 ../gcc-$GCC_VERSION/configure \ |
pankso@441 | 224 --prefix=$tools \ |
pankso@441 | 225 --libexec=$tools/lib \ |
pankso@361 | 226 --target=$TARGET \ |
pankso@361 | 227 --disable-shared \ |
pankso@361 | 228 --disable-threads \ |
pankso@441 | 229 --disable-libgomp \ |
pankso@441 | 230 --disable-libmudflap \ |
pankso@441 | 231 --disable-libssp \ |
pankso@361 | 232 --without-headers \ |
pankso@361 | 233 --with-newlib \ |
pankso@441 | 234 --with-sysroot=$sysroot \ |
pankso@442 | 235 $GCC_STATIC_ARGS && |
pankso@361 | 236 make all-gcc all-target-libgcc || exit 1 |
pankso@361 | 237 make install-gcc install-target-libgcc |
pankso@421 | 238 echo "cross: gcc-static compiled on: $(date)" |
pankso@403 | 239 } |
pankso@403 | 240 |
al@728 | 241 |
pankso@651 | 242 # 4. GNU Glibc: TODO Improve ARM support |
al@728 | 243 |
pankso@361 | 244 glibc() { |
pankso@408 | 245 init_compile |
pankso@649 | 246 echo "Extracting: $glibc_tarball" |
al@728 | 247 tar -xjf $SRC/$glibc_tarball |
pankso@421 | 248 echo "Configure: $GLIBC_ARGS" |
pankso@400 | 249 # Some arch may need glibc-ports and custom CFLAGS |
pankso@403 | 250 case "$ARCH" in |
pankso@650 | 251 arm*) |
al@728 | 252 export CFLAGS='-march=armv6 -O2' |
pankso@362 | 253 [ -f "$SRC/glibc-ports-$GLIBC_VERSION.tar.bz2" ] || wget \ |
pankso@362 | 254 http://ftp.gnu.org/gnu/libc/glibc-ports-$GLIBC_VERSION.tar.bz2 \ |
pankso@362 | 255 -O $SRC/glibc-ports-$GLIBC_VERSION.tar.bz2 || exit 1 |
pankso@361 | 256 echo "Extracting: glibc-ports-$GLIBC_VERSION.tar.bz2" |
pankso@361 | 257 rm -rf glibc-$GLIBC_VERSION/ports |
al@728 | 258 tar -xjf $SRC/glibc-ports-$GLIBC_VERSION.tar.bz2 |
pankso@449 | 259 mv glibc-ports-$GLIBC_VERSION glibc-$GLIBC_VERSION/ports |
al@728 | 260 libexec='/usr/lib/glibc' ;; |
pankso@418 | 261 x86_64) |
pankso@653 | 262 #export CFLAGS="-02 -march=generic -pipe" |
al@728 | 263 ccflags='-m64' |
al@728 | 264 libexec='/usr/lib64/glibc' ;; |
pankso@361 | 265 esac |
pankso@441 | 266 # Disable linking to libgcc_eh |
pankso@441 | 267 cd glibc-$GLIBC_VERSION |
pankso@441 | 268 cp Makeconfig Makeconfig.orig |
pankso@441 | 269 sed -e 's/-lgcc_eh//g' Makeconfig.orig > Makeconfig |
pankso@441 | 270 cd .. |
pankso@421 | 271 echo "CFLAGS: $CFLAGS" |
pankso@441 | 272 rm -rf glibc-build |
al@728 | 273 mkdir -p glibc-build; cd glibc-build |
pankso@365 | 274 BUILD_CC="gcc" \ |
pankso@418 | 275 CC="${TARGET}-gcc $ccflags" \ |
pankso@441 | 276 AR="${TARGET}-ar" \ |
pankso@441 | 277 RANLIB="${TARGET}-ranlib" \ |
pankso@361 | 278 libc_cv_forced_unwind=yes \ |
pankso@361 | 279 libc_cv_c_cleanup=yes \ |
pankso@361 | 280 ../glibc-$GLIBC_VERSION/configure \ |
pankso@441 | 281 --prefix=/usr \ |
pankso@449 | 282 --libexec=$libexec \ |
pankso@361 | 283 --host=$TARGET \ |
pankso@441 | 284 --with-headers=$sysroot/usr/include \ |
pankso@441 | 285 --with-binutils=$tools/bin \ |
pankso@425 | 286 --enable-kernel=2.6.32 \ |
pankso@442 | 287 $GLIBC_ARGS && |
pankso@361 | 288 make || exit 1 |
pankso@441 | 289 make install_root=$sysroot install |
pankso@454 | 290 # Symlink lib64 to lib |
pankso@454 | 291 case "$ARCH" in |
pankso@454 | 292 x86_64) |
pankso@454 | 293 rm -f $sysroot/lib $sysroot/usr/lib |
al@728 | 294 cd $sysroot; ln -s lib64 lib |
al@728 | 295 cd usr; ln -s lib64 lib ;; |
pankso@454 | 296 esac |
pankso@421 | 297 echo "cross: glibc compiled on: $(date)" |
pankso@361 | 298 } |
pankso@361 | 299 |
al@728 | 300 |
pankso@649 | 301 # 4. eglibc: always use --prefix=/usr |
al@728 | 302 |
pankso@441 | 303 eglibc() { |
pankso@441 | 304 init_compile |
pankso@651 | 305 init_cflags |
pankso@441 | 306 rm -rf eglibc-build eglibc-$EGLIBC_VERSION |
pankso@681 | 307 if [ ! -f "$SRC/$eglibc_tarball" ]; then |
pankso@681 | 308 echo "Missing: $SRC/$eglibc_tarball" |
pankso@681 | 309 exit 1 |
pankso@681 | 310 fi |
pankso@649 | 311 echo "Extracting: $eglibc_tarball" |
al@728 | 312 tar -xjf $SRC/$eglibc_tarball || exit 1 |
pankso@650 | 313 case "$ARCH" in |
pankso@650 | 314 arm*) |
pankso@441 | 315 if [ ! -d "$source/eglibc-ports-$EGLIBC_VERSION" ]; then |
pankso@681 | 316 echo "Cloning $eglibc_svn/ports" |
pankso@681 | 317 svn co $eglibc_svn/ports eglibc-ports-$EGLIBC_VERSION >/dev/null |
pankso@441 | 318 fi |
pankso@449 | 319 cp -a eglibc-ports-$EGLIBC_VERSION eglibc-$EGLIBC_VERSION/ports |
al@728 | 320 libexec='/usr/lib/eglibc' ;; |
pankso@441 | 321 x86_64) |
pankso@449 | 322 #export CFLAGS="-march=nocona -O2 -pipe" |
al@728 | 323 ccflags='-m64' |
al@728 | 324 libexec='/usr/lib64/eglibc' ;; |
pankso@441 | 325 esac |
pankso@441 | 326 # Disable linking to libgcc_eh |
pankso@441 | 327 cd eglibc-$EGLIBC_VERSION |
pankso@441 | 328 cp Makeconfig Makeconfig.orig |
pankso@441 | 329 sed -e 's/-lgcc_eh//g' Makeconfig.orig > Makeconfig |
pankso@441 | 330 cd .. |
pankso@651 | 331 echo "CFLAGS: $CFLAGS" |
al@728 | 332 mkdir -p eglibc-build; cd eglibc-build |
pankso@441 | 333 # config.cache |
al@728 | 334 cat > config.cache <<EOT |
pankso@441 | 335 libc_cv_forced_unwind=yes |
pankso@441 | 336 libc_cv_c_cleanup=yes |
pankso@441 | 337 libc_cv_gnu89_inline=yes |
pankso@441 | 338 EOT |
al@728 | 339 BUILD_CC='gcc' \ |
pankso@441 | 340 CC="${TARGET}-gcc $ccflags" \ |
pankso@441 | 341 AR="${TARGET}-ar" \ |
pankso@441 | 342 RANLIB="${TARGET}-ranlib" \ |
pankso@441 | 343 ../eglibc-$EGLIBC_VERSION/configure \ |
pankso@441 | 344 --prefix=/usr \ |
pankso@449 | 345 --libexec=$libexec \ |
pankso@441 | 346 --host=$TARGET \ |
pankso@441 | 347 --with-headers=$sysroot/usr/include \ |
pankso@441 | 348 --with-binutils=$tools/bin \ |
pankso@441 | 349 --enable-kernel=2.6.32 \ |
pankso@441 | 350 --with-__thread \ |
pankso@441 | 351 --without-gd \ |
pankso@441 | 352 --without-cvs \ |
pankso@441 | 353 --cache-file=config.cache \ |
pankso@442 | 354 $EGLIBC_ARGS && |
pankso@441 | 355 make || exit 1 |
pankso@681 | 356 make install_root=$sysroot install || exit 1 |
pankso@681 | 357 # Sep files for packaging |
pankso@681 | 358 make install_root=$source/eglibc-install install || exit 1 |
pankso@641 | 359 echo "cross: eglibc compiled on: $(date)" |
pankso@441 | 360 } |
pankso@441 | 361 |
al@728 | 362 |
pankso@361 | 363 # 5. GCC final |
al@728 | 364 |
pankso@361 | 365 gcc_final() { |
pankso@408 | 366 init_compile |
pankso@361 | 367 if [ ! -d "gcc-$GCC_VERSION" ]; then |
pankso@649 | 368 echo "Extracting: $gcc_tarball" |
al@728 | 369 tar -xjf $SRC/$gcc_tarball |
pankso@361 | 370 fi |
pankso@421 | 371 echo "Configure: $GCC_FINAL_ARGS" |
pankso@441 | 372 rm -rf gcc-build |
al@728 | 373 mkdir -p gcc-build; cd gcc-build |
pankso@441 | 374 AR=ar \ |
pankso@361 | 375 ../gcc-$GCC_VERSION/configure \ |
pankso@441 | 376 --prefix=$tools \ |
pankso@441 | 377 --libexec=$tools/lib \ |
pankso@361 | 378 --target=$TARGET \ |
pankso@361 | 379 --enable-shared \ |
pankso@361 | 380 --enable-c99 \ |
pankso@361 | 381 --enable-long-long \ |
pankso@361 | 382 --enable-__cxa_atexit \ |
pankso@440 | 383 --with-system-zlib \ |
pankso@440 | 384 --enable-plugin \ |
pankso@440 | 385 --disable-multilib \ |
pankso@440 | 386 --disable-libssp \ |
pankso@441 | 387 --disable-checking \ |
pankso@441 | 388 --disable-werror \ |
pankso@400 | 389 --with-pkgversion="SliTaz" \ |
pankso@648 | 390 --with-bugurl="http://bugs.slitaz.org/" \ |
pankso@442 | 391 --with-sysroot=$sysroot \ |
pankso@442 | 392 $GCC_FINAL_ARGS && |
pankso@441 | 393 make AS_FOR_TARGET="${TARGET}-as" \ |
pankso@441 | 394 LD_FOR_TARGET="${TARGET}-ld" || exit 1 |
pankso@441 | 395 make install |
pankso@421 | 396 echo "cross: GCC final compiled on: $(date)" |
pankso@361 | 397 } |
pankso@361 | 398 |
al@728 | 399 |
pankso@654 | 400 # A cross libtool should avoid some shared libs path/format bugs |
al@728 | 401 |
pankso@654 | 402 cross_libtool() { |
pankso@654 | 403 init_compile |
pankso@654 | 404 [ "$clean" ] && rm -rf libtool-${LIBTOOL_VERSION} |
pankso@654 | 405 if [ ! -d "libtool-$LIBTOOL_VERSION" ]; then |
pankso@654 | 406 echo "Extracting: $libtool_tarball" |
al@728 | 407 tar -xzf $SRC/$libtool_tarball |
pankso@654 | 408 fi |
pankso@654 | 409 cd libtool-${LIBTOOL_VERSION} |
pankso@654 | 410 ./configure \ |
pankso@654 | 411 --prefix=$tools \ |
pankso@654 | 412 --host=${TARGET} \ |
pankso@654 | 413 --program-prefix=${TARGET}- && |
pankso@654 | 414 make || exit 1 |
pankso@654 | 415 make install |
pankso@654 | 416 echo "cross: Cross libtool compiled on: $(date)" |
pankso@654 | 417 } |
pankso@654 | 418 |
al@728 | 419 |
pankso@361 | 420 # |
pankso@361 | 421 # Commands |
pankso@361 | 422 # |
pankso@361 | 423 |
pankso@361 | 424 case "$1" in |
pankso@361 | 425 howto|man) |
al@728 | 426 doc='/usr/share/doc/cookutils/cross.txt' |
pankso@361 | 427 [ -f "$doc" ] && less -E $doc ;; |
al@728 | 428 |
pankso@361 | 429 info) |
pankso@361 | 430 init_compile |
pankso@651 | 431 init_cflags |
pankso@361 | 432 CC=${TARGET}-gcc |
al@728 | 433 echo -e '\nCross Toolchain information'; separator |
pankso@374 | 434 [ "$config" ] && echo "Config file : $config" |
al@728 | 435 cat <<EOT |
pankso@374 | 436 Target arch : $ARCH |
pankso@374 | 437 C Compiler : $CC |
pankso@651 | 438 CFLAGS : $CFLAGS |
pankso@374 | 439 Build directory : $WORK |
pankso@441 | 440 Tools prefix : $tools/bin |
pankso@441 | 441 Arch sysroot : $sysroot |
pankso@361 | 442 EOT |
al@728 | 443 separator; newline |
al@728 | 444 echo 'GCC version'; separator |
pankso@441 | 445 if [ -x "$tools/bin/$CC" ]; then |
pankso@374 | 446 $CC -v |
pankso@374 | 447 else |
al@728 | 448 echo 'No C compiler. To build a toolchain run: cross compile' |
pankso@441 | 449 echo "Missing: $tools/bin/$CC" |
pankso@374 | 450 fi |
al@728 | 451 separator; newline ;; |
al@728 | 452 |
pankso@361 | 453 testsuite) |
pankso@361 | 454 init_compile |
pankso@361 | 455 echo "[COMPILING] $TARGET-gcc -v -Wall -o test.out test.c" \ |
pankso@361 | 456 | tee $logdir/testsuite.log |
pankso@361 | 457 echo 'int main() { return 0; }' > test.c |
pankso@361 | 458 $TARGET-gcc -v -Wall -o test.out test.c 2>&1 | tee -a $logdir/testsuite.log |
pankso@361 | 459 if [ -x /usr/bin/file ]; then |
pankso@361 | 460 echo -e "\n[CHECKING] file test.out" | tee -a $logdir/testsuite.log |
pankso@361 | 461 file test.out | tee -a $logdir/testsuite.log |
pankso@361 | 462 fi |
pankso@361 | 463 echo -e "\n[CHECKING] readelf -h test.out" | tee -a $logdir/testsuite.log |
pankso@361 | 464 readelf -h test.out | tee -a $logdir/testsuite.log ;; |
al@728 | 465 |
pankso@649 | 466 *setup) |
al@728 | 467 data='/usr/share/cross' |
pankso@649 | 468 arch=${1%-setup} |
al@728 | 469 [ "$arch" == 'setup' ] && arch="arm" |
al@728 | 470 |
al@728 | 471 newline; echo 'Checking: build system packages' |
pankso@421 | 472 for pkg in slitaz-toolchain mpfr mpfr-dev gmp gmp-dev mpc-library \ |
pankso@421 | 473 gawk autoconf; do |
pankso@361 | 474 if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then |
pankso@361 | 475 echo "Missing packages: $pkg" |
pankso@421 | 476 if [ -x /usr/sbin/spk-add ]; then |
pankso@421 | 477 spk-add $pkg |
pankso@421 | 478 else |
pankso@421 | 479 tazpkg -gi $pkg |
pankso@421 | 480 fi |
pankso@361 | 481 fi |
pankso@421 | 482 done |
pankso@649 | 483 echo "Getting $arch cross.conf" |
pankso@649 | 484 cp -f ${data}/cross-${arch}.conf /etc/slitaz/cross.conf |
pankso@649 | 485 cook ${arch}-setup |
pankso@649 | 486 newline ;; |
al@728 | 487 |
pankso@361 | 488 download) |
pankso@361 | 489 download_src ;; |
al@728 | 490 |
pankso@361 | 491 show-log) |
pankso@361 | 492 pkg=$2 |
pankso@371 | 493 log=$logdir/$pkg.log |
pankso@371 | 494 if [ ! -f "$log" ]; then |
al@728 | 495 echo "No log file found for: $pkg" |
al@728 | 496 exit 1 |
pankso@371 | 497 fi |
pankso@371 | 498 less -E $log ;; |
al@728 | 499 |
pankso@361 | 500 binutils) |
pankso@412 | 501 rm -f $logdir/binutils.log |
pankso@361 | 502 binutils 2>&1 | tee $logdir/binutils.log ;; |
al@728 | 503 |
pankso@447 | 504 linux-headers) |
pankso@447 | 505 linux_headers 2>&1 | tee $logdir/linux-headers.log ;; |
al@728 | 506 |
pankso@447 | 507 glibc-headers) |
pankso@447 | 508 glibc_headers 2>&1 | tee $logdir/glibc-headers.log ;; |
al@728 | 509 |
pankso@403 | 510 gcc-static) |
pankso@403 | 511 gcc_static 2>&1 | tee $logdir/gcc-static.log ;; |
al@728 | 512 |
pankso@361 | 513 glibc) |
pankso@361 | 514 glibc 2>&1 | tee $logdir/glibc.log ;; |
al@728 | 515 |
pankso@441 | 516 eglibc) |
pankso@441 | 517 eglibc 2>&1 | tee $logdir/eglibc.log ;; |
al@728 | 518 |
pankso@361 | 519 gcc-final) |
pankso@361 | 520 gcc_final 2>&1 | tee $logdir/gcc-final.log ;; |
al@728 | 521 |
pankso@361 | 522 compile) |
pankso@400 | 523 # Compile the full toolchain. |
pankso@400 | 524 time=$(date +%s) |
pankso@361 | 525 init_compile |
pankso@361 | 526 echo "Compile start: $(date)" | tee $logdir/compile.log |
pankso@361 | 527 download_src |
pankso@361 | 528 binutils 2>&1 | tee $logdir/binutils.log |
pankso@447 | 529 case "$ARCH" in |
pankso@447 | 530 x86_64) glibc_headers 2>&1 | tee $logdir/glibc-headers.log ;; |
pankso@447 | 531 esac |
pankso@652 | 532 linux_headers 2>&1 | tee $logdir/linux-headers.log |
pankso@403 | 533 gcc_static 2>&1 | tee $logdir/gcc-static.log |
pankso@441 | 534 case "$ARCH" in |
al@728 | 535 arm*) eglibc 2>&1 | tee $logdir/eglibc.log ;; |
pankso@441 | 536 x86_64) glibc 2>&1 | tee $logdir/glibc.log ;; |
pankso@441 | 537 esac |
pankso@361 | 538 gcc_final 2>&1 | tee $logdir/gcc-final.log |
al@728 | 539 newline |
pankso@365 | 540 echo "Compile end : $(date)" | tee -a $logdir/compile.log |
pankso@400 | 541 time=$(($(date +%s) - $time)) |
pankso@400 | 542 sec=$time |
pankso@400 | 543 div=$(( ($time + 30) / 60)) |
pankso@400 | 544 [ "$div" != 0 ] && min="~ ${div}m" |
pankso@401 | 545 echo "Build time : ${sec}s $min" | tee -a $logdir/compile.log |
pankso@361 | 546 echo "" ;; |
al@728 | 547 |
pankso@654 | 548 libtool) |
pankso@654 | 549 cross_libtool 2>&1 | tee $logdir/libtool.log ;; |
al@728 | 550 |
pankso@655 | 551 libhack) |
pankso@655 | 552 # Some libxx.la files have libdir='/usr/lib' and make packages |
paul@684 | 553 # cross compilation fail. Some receipts may have got hacked to force |
paul@684 | 554 # use of libs in sysroot but 'cross libhack' should be preferred. |
pankso@655 | 555 echo "Libdir: $sysroot/usr/lib" |
al@728 | 556 for la in $(fgrep -l libdir= $sysroot/usr/lib/*.la 2>/dev/null); do |
pankso@655 | 557 if fgrep -q "libdir='/usr/lib'" ${la}; then |
pankso@655 | 558 echo "Cross fixing: $(basename $la)" |
pankso@655 | 559 sed -i s"#libdir=.*#libdir='/cross/$ARCH/sysroot/usr/lib'#" ${la} |
pankso@655 | 560 fi |
pankso@655 | 561 done ;; |
al@728 | 562 |
pankso@416 | 563 clean) |
al@728 | 564 echo -n 'Removing all source files...' |
al@728 | 565 rm -rf $WORK/source; status |
pankso@441 | 566 [ "$log" ] && rm -f $WORK/log/*.log ;; |
al@728 | 567 |
pankso@371 | 568 clean-tools) |
pankso@371 | 569 # Remove crap :-) |
pankso@371 | 570 init_compile |
pankso@441 | 571 echo "Cleaning : $tools ($(du -sh $tools | awk '{print $1}'))" |
al@728 | 572 for file in share/info share/man share/local; do |
pankso@440 | 573 echo -n "Removing : $file" |
al@728 | 574 rm -rf $tools/$file; status |
pankso@371 | 575 done |
pankso@419 | 576 echo -n "Stripping : shared libs and binaries" |
al@728 | 577 find $tools/bin -type f -exec strip -s '{}' 2>/dev/null \; |
al@728 | 578 find $tools/lib -name cc1* -exec strip -s '{}' 2>/dev/null \; |
al@728 | 579 find $tools/lib -name lto* -exec strip -s '{}' 2>/dev/null \; |
pankso@444 | 580 find $sysroot -name "*.so*" -exec ${TARGET}-strip -s '{}' 2>/dev/null \; |
al@728 | 581 sleep 1; status |
al@728 | 582 echo -n "Tools size : "; du -sh $tools | awk '{print $1}' ;; |
al@728 | 583 |
pankso@416 | 584 gen-prebuilt) |
pankso@420 | 585 # Create a prebuilt cross toolchain tarball. |
pankso@416 | 586 init_compile |
pankso@420 | 587 date=$(date "+%Y%m%d") |
pankso@443 | 588 package="slitaz-$ARCH-toolchain-$date" |
pankso@419 | 589 tarball="$package.tar.bz2" |
pankso@441 | 590 cd /cross |
pankso@443 | 591 mkdir -p $package/$ARCH || exit 1 |
al@728 | 592 newline |
pankso@419 | 593 echo -n "Copying $ARCH to: $package" |
pankso@443 | 594 cp -a $ARCH/tools $package/$ARCH |
pankso@443 | 595 cp -a $ARCH/sysroot $package/$ARCH |
pankso@419 | 596 status |
pankso@420 | 597 prebuilt_readme |
pankso@416 | 598 echo -n "Creating prebuilt $ARCH toolchain tarball..." |
al@728 | 599 tar -cjf $tarball $package |
pankso@416 | 600 status |
pankso@419 | 601 rm -rf $package |
pankso@441 | 602 size=$(du -sh $tarball | awk '{print $1}') |
pankso@441 | 603 echo "Tarball path: $(pwd)/$tarball" |
pankso@419 | 604 echo "Tarball size: $size" |
al@728 | 605 newline ;; |
al@728 | 606 |
pankso@361 | 607 *) |
pankso@361 | 608 usage ;; |
pankso@361 | 609 esac |
pankso@361 | 610 |