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