cookutils diff cross @ rev 441
cross: sysroot method is now used (much better), eglibc replace glibc for ARM
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue May 29 08:03:41 2012 +0000 (2012-05-29) |
parents | eba46d355d8c |
children | 1be327c53ee7 |
line diff
1.1 --- a/cross Sat May 26 03:34:18 2012 +0200 1.2 +++ b/cross Tue May 29 08:03:41 2012 +0000 1.3 @@ -13,8 +13,9 @@ 1.4 # Handle --config=/path/to/cross.conf 1.5 [ "$config" ] && . $config 1.6 source=$WORK/source 1.7 +tools=$WORK/tools 1.8 +sysroot=$WORK/sysroot 1.9 logdir=$WORK/log 1.10 -install=$WORK/install 1.11 1.12 # Help and usage. 1.13 usage() { 1.14 @@ -36,7 +37,7 @@ 1.15 gcc-final Compile final GCC 1.16 compile Compile everything at once 1.17 clean Clean-up build environment 1.18 - clean-tools Clean: $PREFIX 1.19 + clean-tools Clean: $tools 1.20 gen-prebuilt Create an prebuilt toolchain archive 1.21 1.22 EOT 1.23 @@ -52,8 +53,8 @@ 1.24 Move this $ARCH cross compilation toolchain to /usr/cross then add tools 1.25 to your PATH environment and test the toolchain: 1.26 1.27 - # mv $ARCH /usr/cross 1.28 - # export PATH=\$PATH:/usr/cross/$ARCH/bin 1.29 + # mv $ARCH /cross 1.30 + # export PATH=\$PATH:/cross/$ARCH/tools/bin 1.31 1.32 # echo 'int main() { return 0; }' > test.c 1.33 # $TARGET-gcc -v -o test.out test.c 1.34 @@ -67,10 +68,13 @@ 1.35 1.36 # Make sure we have all directories. 1.37 init_compile() { 1.38 + unset CFLAGS CXXFLAGS 1.39 export LC_ALL=POSIX LANG=POSIX 1.40 - [ "$SYSROOT" ] || export PATH=$PATH:$PREFIX/bin 1.41 + export PATH=$PATH:$tools/bin 1.42 export CROSS_COMPILE=${TARGET}- 1.43 - mkdir -p $source $logdir $install 1.44 + mkdir -p $source $logdir $sysroot $tools 1.45 + echo "Tools prefix : --prefix=$tools " 1.46 + echo "Target sysroot : --with-sysroot=$sysroot" 1.47 cd $source 1.48 } 1.49 1.50 @@ -81,51 +85,6 @@ 1.51 [ -f "$LINUX_TARBALL" ] || wget $LINUX_WGET 1.52 [ -f "$GLIBC_TARBALL" ] || wget $GLIBC_WGET 1.53 [ -f "$GCC_TARBALL" ] || wget $GCC_WGET 1.54 - [ -f "$BUSYBOX_TARBALL" ] || wget $BUSYBOX_WGET 1.55 -} 1.56 - 1.57 -# Use sysroot or not ? 1.58 -check_sysroot() { 1.59 - if [ "$SYSROOT" ]; then 1.60 - PREFIX=/usr 1.61 - HDR_PATH=$SYSROOT/usr 1.62 - sysroot="--with-sysroot=$SYSROOT" 1.63 - echo "Configure: $sysroot" 1.64 - else 1.65 - HDR_PATH=$PREFIX/usr 1.66 - fi 1.67 -} 1.68 - 1.69 -# Work around to fix GCC include search path 1.70 -# 1.71 -# GCC include search path is: $PREFIX/$TARGET/include, so make sure it 1.72 -# is a symlink to default: $PREFIX/usr/include 1.73 -# 1.74 -# Glibc install headers in: $PREFIX/include, move them to usr/include 1.75 -# if needed. After when we cross compile packages with cook we have 1.76 -# to install build dependencies using --root=$CROSS_PREFIX and so 1.77 -# default include dir is: $PREFIX/usr/include ($PREFIX is the root 1.78 -# of our cross environment. 1.79 -# 1.80 -check_include() { 1.81 - cd $PREFIX 1.82 - echo "Checking: $PREFIX" 1.83 - if ! readlink include >/dev/null; then 1.84 - echo "Creating symlink: usr/include include" 1.85 - cp -a include usr && rm -rf include 1.86 - ln -s usr/include include 1.87 - fi 1.88 - cd $PREFIX/$TARGET 1.89 - echo "Checking: $PREFIX/$TARGET" 1.90 - if ! readlink include >/dev/null; then 1.91 - echo "Creating symlink: ../usr/include include" 1.92 - cp -a include ../usr && rm -rf include 1.93 - ln -s ../usr/include include 1.94 - fi 1.95 - if ! readlink lib >/dev/null; then 1.96 - echo "Creating symlink: ../lib lib" 1.97 - rm -rf lib && ln -s ../lib lib 1.98 - fi 1.99 } 1.100 1.101 # 1. Binutils 1.102 @@ -135,31 +94,29 @@ 1.103 echo "Extracting: $BINUTILS_TARBALL" 1.104 tar xjf $SRC/$BINUTILS_TARBALL 1.105 echo "Configure: $BINUTILS_ARGS" 1.106 - check_sysroot 1.107 cd binutils-$BINUTILS_VERSION 1.108 ./configure \ 1.109 - --prefix=$PREFIX \ 1.110 + --prefix=$tools \ 1.111 --target=$TARGET \ 1.112 --enable-plugins \ 1.113 --enable-threads \ 1.114 --enable-targets=$BUILD_SYSTEM \ 1.115 - $BINUTILS_ARGS $sysroot 1.116 + --with-sysroot=$sysroot \ 1.117 + $BINUTILS_ARGS 1.118 make || exit 1 1.119 make install 1.120 echo "cross: binutils compiled on: $(date)" 1.121 } 1.122 1.123 # 2. Kernel headers could use CROSS_COMPILE but gcc is not yet build. 1.124 -# NOTE: Compile GCC static first then linux-headers ? 1.125 linux_headers() { 1.126 init_compile 1.127 echo "Extracting: $LINUX_TARBALL" 1.128 tar xjf $SRC/$LINUX_TARBALL 1.129 - check_sysroot 1.130 cd linux-$LINUX_VERSION 1.131 make mrproper 1.132 make ARCH=$ARCH headers_check 1.133 - make ARCH=$ARCH headers_install INSTALL_HDR_PATH=$HDR_PATH 1.134 + make ARCH=$ARCH headers_install INSTALL_HDR_PATH=$sysroot/usr 1.135 } 1.136 1.137 # 3. GCC static (first pass) 1.138 @@ -168,32 +125,33 @@ 1.139 echo "Extracting: $GCC_TARBALL" 1.140 tar xjf $SRC/$GCC_TARBALL 1.141 echo "Configure: $GCC_STATIC_ARGS" 1.142 - check_sysroot 1.143 # Arch fixes and work around 1.144 case "$ARCH" in 1.145 x86_64) 1.146 # GCC wants Glib headers in cross environment (not tested 1.147 # with sysroot) Should we install glibc-headers before ? 1.148 - [ "$SYSROOT" ] || \ 1.149 - ln -s /usr/include $PREFIX/$TARGET/include ;; 1.150 + echo "Try with eglibc or install glibc-headers first" 1.151 + #rm -f $tools/$TARGET/include 1.152 + #ln -s /usr/include $tools/$TARGET/include 1.153 + ;; 1.154 esac 1.155 rm -rf gcc-static 1.156 mkdir gcc-static && cd gcc-static 1.157 ../gcc-$GCC_VERSION/configure \ 1.158 - --prefix=$PREFIX \ 1.159 - --libexec=$PREFIX/lib \ 1.160 + --prefix=$tools \ 1.161 + --libexec=$tools/lib \ 1.162 --target=$TARGET \ 1.163 --disable-shared \ 1.164 --disable-threads \ 1.165 + --disable-libgomp \ 1.166 + --disable-libmudflap \ 1.167 + --disable-libssp \ 1.168 --without-headers \ 1.169 --with-newlib \ 1.170 - $GCC_STATIC_ARGS $sysroot 1.171 + --with-sysroot=$sysroot \ 1.172 + $GCC_STATIC_ARGS 1.173 make all-gcc all-target-libgcc || exit 1 1.174 make install-gcc install-target-libgcc 1.175 - cd $PREFIX/lib/gcc/$TARGET/$GCC_VERSION 1.176 - echo "Creating symlink for static libgcc: libgcc_eh.a" 1.177 - rm -f libgcc_eh.a 1.178 - ln -s libgcc.a libgcc_eh.a 1.179 echo "cross: gcc-static compiled on: $(date)" 1.180 } 1.181 1.182 @@ -203,7 +161,6 @@ 1.183 echo "Extracting: $GLIBC_TARBALL" 1.184 tar xjf $SRC/$GLIBC_TARBALL 1.185 echo "Configure: $GLIBC_ARGS" 1.186 - [ "$continue" ] || rm -rf glibc-build 1.187 # Some arch may need glibc-ports and custom CFLAGS 1.188 case "$ARCH" in 1.189 arm) 1.190 @@ -218,33 +175,86 @@ 1.191 x86_64) 1.192 ccflags="-m64" ;; 1.193 esac 1.194 + # Disable linking to libgcc_eh 1.195 + cd glibc-$GLIBC_VERSION 1.196 + cp Makeconfig Makeconfig.orig 1.197 + sed -e 's/-lgcc_eh//g' Makeconfig.orig > Makeconfig 1.198 + cd .. 1.199 echo "CFLAGS: $CFLAGS" 1.200 + rm -rf glibc-build 1.201 mkdir -p glibc-build && cd glibc-build 1.202 BUILD_CC="gcc" \ 1.203 CC="${TARGET}-gcc $ccflags" \ 1.204 + AR="${TARGET}-ar" \ 1.205 + RANLIB="${TARGET}-ranlib" \ 1.206 libc_cv_forced_unwind=yes \ 1.207 libc_cv_c_cleanup=yes \ 1.208 ../glibc-$GLIBC_VERSION/configure \ 1.209 - --prefix=$PREFIX \ 1.210 - --libexec=$PREFIX/lib/glibc \ 1.211 + --prefix=/usr \ 1.212 + --libexec=/usr/lib/glibc \ 1.213 --host=$TARGET \ 1.214 - --with-headers=$PREFIX/usr/include \ 1.215 - --with-binutils=$PREFIX/bin \ 1.216 + --with-headers=$sysroot/usr/include \ 1.217 + --with-binutils=$tools/bin \ 1.218 --enable-kernel=2.6.32 \ 1.219 $GLIBC_ARGS 1.220 make || exit 1 1.221 - make install 1.222 + make install_root=$sysroot install 1.223 # Work around to let GCC find Glibc headers. 1.224 - if [ "$SYSROOT" ]; then 1.225 - cd $SYSROOT 1.226 - ln -s usr/include sys-include 1.227 - else 1.228 - check_include 1.229 - fi 1.230 - unset CFLAGS 1.231 + #cd $sysroot 1.232 + #ln -s usr/include sys-include 1.233 echo "cross: glibc compiled on: $(date)" 1.234 } 1.235 1.236 +# 4. Eglibc: always use --prefix=/usr 1.237 +eglibc() { 1.238 + init_compile 1.239 + rm -rf eglibc-build eglibc-$EGLIBC_VERSION 1.240 + echo "Extracting: $EGLIBC_TARBALL" 1.241 + tar xjf $SRC/$EGLIBC_TARBALL 1.242 + # Some arch may need glibc-ports and custom CFLAGS 1.243 + case "$ARCH" in 1.244 + arm) 1.245 + export CFLAGS="-march=armv6 -O2" 1.246 + if [ ! -d "$source/eglibc-ports-$EGLIBC_VERSION" ]; then 1.247 + echo "Cloning $EGLIBC_WGET/ports" 1.248 + svn co $EGLIBC_WGET/ports eglibc-ports-$EGLIBC_VERSION >/dev/null 1.249 + fi 1.250 + cp -a eglibc-ports-$EGLIBC_VERSION eglibc-$EGLIBC_VERSION/ports ;; 1.251 + x86_64) 1.252 + ccflags="-m64" ;; 1.253 + esac 1.254 + # Disable linking to libgcc_eh 1.255 + cd eglibc-$EGLIBC_VERSION 1.256 + cp Makeconfig Makeconfig.orig 1.257 + sed -e 's/-lgcc_eh//g' Makeconfig.orig > Makeconfig 1.258 + cd .. 1.259 + mkdir -p eglibc-build && cd eglibc-build 1.260 + # config.cache 1.261 + cat > config.cache << EOT 1.262 +libc_cv_forced_unwind=yes 1.263 +libc_cv_c_cleanup=yes 1.264 +libc_cv_gnu89_inline=yes 1.265 +EOT 1.266 + BUILD_CC="gcc" \ 1.267 + CC="${TARGET}-gcc $ccflags" \ 1.268 + AR="${TARGET}-ar" \ 1.269 + RANLIB="${TARGET}-ranlib" \ 1.270 + ../eglibc-$EGLIBC_VERSION/configure \ 1.271 + --prefix=/usr \ 1.272 + --libexec=/usr/lib/eglibc \ 1.273 + --host=$TARGET \ 1.274 + --with-headers=$sysroot/usr/include \ 1.275 + --with-binutils=$tools/bin \ 1.276 + --enable-kernel=2.6.32 \ 1.277 + --with-__thread \ 1.278 + --without-gd \ 1.279 + --without-cvs \ 1.280 + --cache-file=config.cache \ 1.281 + $EGLIBC_ARGS 1.282 + make || exit 1 1.283 + make install_root=$sysroot install 1.284 +} 1.285 + 1.286 # 5. GCC final 1.287 gcc_final() { 1.288 init_compile 1.289 @@ -253,12 +263,12 @@ 1.290 tar xjf $SRC/$GCC_TARBALL 1.291 fi 1.292 echo "Configure: $GCC_FINAL_ARGS" 1.293 - check_sysroot 1.294 - [ "$continue" ] || rm -rf gcc-build 1.295 + rm -rf gcc-build 1.296 mkdir -p gcc-build && cd gcc-build 1.297 + AR=ar \ 1.298 ../gcc-$GCC_VERSION/configure \ 1.299 - --prefix=$PREFIX \ 1.300 - --libexec=$PREFIX/lib \ 1.301 + --prefix=$tools \ 1.302 + --libexec=$tools/lib \ 1.303 --target=$TARGET \ 1.304 --enable-shared \ 1.305 --enable-c99 \ 1.306 @@ -268,11 +278,14 @@ 1.307 --enable-plugin \ 1.308 --disable-multilib \ 1.309 --disable-libssp \ 1.310 + --disable-checking \ 1.311 + --disable-werror \ 1.312 --with-pkgversion="SliTaz" \ 1.313 --with-bugurl="https://bugs.slitaz.org/" \ 1.314 $GCC_FINAL_ARGS $sysroot 1.315 - make || exit 1 1.316 - make install && 1.317 + make AS_FOR_TARGET="${TARGET}-as" \ 1.318 + LD_FOR_TARGET="${TARGET}-ld" || exit 1 1.319 + make install 1.320 echo "cross: GCC final compiled on: $(date)" 1.321 } 1.322 1.323 @@ -293,19 +306,16 @@ 1.324 Target arch : $ARCH 1.325 C Compiler : $CC 1.326 Build directory : $WORK 1.327 +Tools prefix : $tools/bin 1.328 +Arch sysroot : $sysroot 1.329 EOT 1.330 - if [ "$SYSROOT" ]; then 1.331 - PREFIX=/usr 1.332 - echo "Arch sysroot : $SYSROOT" 1.333 - else 1.334 - echo "Additional path : $PREFIX/bin" 1.335 - fi 1.336 separator && echo "" 1.337 echo "GCC version" && separator 1.338 - if [ -x "$PREFIX/bin/$CC" ]; then 1.339 + if [ -x "$tools/bin/$CC" ]; then 1.340 $CC -v 1.341 else 1.342 echo "No C compiler. To build a toolchain run: cross compile" 1.343 + echo "Missing: $tools/bin/$CC" 1.344 fi 1.345 separator && echo "" ;; 1.346 testsuite) 1.347 @@ -333,13 +343,7 @@ 1.348 fi 1.349 fi 1.350 done 1.351 - # See: check_include() 1.352 - if [ "$SYSROOT" ]; then 1.353 - echo "Using: --with-sysroot=$SYSROOT" 1.354 - echo "WARNING: not well tested and buggy" 1.355 - exit 0 1.356 - fi 1.357 - check_include ;; 1.358 + echo "Using: --with-sysroot=$sysroot" ;; 1.359 download) 1.360 download_src ;; 1.361 show-log) 1.362 @@ -358,6 +362,8 @@ 1.363 linux_headers 2>&1 | tee $logdir/linux-headers.log ;; 1.364 glibc) 1.365 glibc 2>&1 | tee $logdir/glibc.log ;; 1.366 + eglibc) 1.367 + eglibc 2>&1 | tee $logdir/eglibc.log ;; 1.368 gcc-final) 1.369 gcc_final 2>&1 | tee $logdir/gcc-final.log ;; 1.370 compile) 1.371 @@ -369,7 +375,10 @@ 1.372 binutils 2>&1 | tee $logdir/binutils.log 1.373 gcc_static 2>&1 | tee $logdir/gcc-static.log 1.374 linux_headers 2>&1 | tee $logdir/linux-headers.log 1.375 - glibc 2>&1 | tee $logdir/glibc.log 1.376 + case "$ARCH" in 1.377 + arm) eglibc 2>&1 | tee $logdir/eglibc.log ;; 1.378 + x86_64) glibc 2>&1 | tee $logdir/glibc.log ;; 1.379 + esac 1.380 gcc_final 2>&1 | tee $logdir/gcc-final.log 1.381 echo "" 1.382 echo "Compile end : $(date)" | tee -a $logdir/compile.log 1.383 @@ -381,50 +390,42 @@ 1.384 echo "" ;; 1.385 clean) 1.386 echo -n "Removing all source files..." 1.387 - rm -rf $WORK/source/* && status 1.388 - [ "$log" ] && rm -f $WORK/log/*.log 1.389 - echo "To clean chroot: rm -rf $PREFIX" ;; 1.390 + rm -rf $WORK/source && status 1.391 + [ "$log" ] && rm -f $WORK/log/*.log ;; 1.392 clean-tools) 1.393 # Remove crap :-) 1.394 init_compile 1.395 - echo "Cleaning : $PREFIX ($(du -sh $PREFIX | awk '{print $1}'))" 1.396 - for file in share/info share/man lib/*-gdb.py 1.397 + echo "Cleaning : $tools ($(du -sh $tools | awk '{print $1}'))" 1.398 + for file in share/info share/man share/local lib/*-gdb.py 1.399 do 1.400 echo -n "Removing : $file" 1.401 - rm -rf $PREFIX/$file && status 1.402 + rm -rf $tools/$file && status 1.403 done 1.404 echo -n "Stripping : shared libs and binaries" 1.405 - ${TARGET}-strip -s $PREFIX/lib/*.so* 2>/dev/null 1.406 - ${TARGET}-strip -s $PREFIX/bin/* 2>/dev/null 1.407 - ${TARGET}-strip -s $PREFIX/${TARGET}/bin/* 2>/dev/null 1.408 - ${TARGET}-strip -s $PREFIX/$TARGET/lib/gcc/$TARGET/*/cc1* 1.409 - ${TARGET}-strip -s $PREFIX/$TARGET/lib/gcc/$TARGET/*/lto* 1.410 + ${TARGET}-strip -s $sysroot/lib/*.so* 2>/dev/null 1.411 + strip -s $tools/bin/* 2>/dev/null 1.412 sleep 1 && status 1.413 - echo -n "Tools size : " && du -sh $PREFIX | awk '{print $1}' ;; 1.414 - gen-rootfs) 1.415 - echo "Use arm packages: basefile, boot-scripts, busybox and glibc-base" 1.416 - echo "Install them in a rootfs: tazpkg *-arm.tazpkg --root=/my/rootfs" ;; 1.417 + echo -n "Tools size : " && du -sh $tools | awk '{print $1}' ;; 1.418 gen-prebuilt) 1.419 # Create a prebuilt cross toolchain tarball. 1.420 init_compile 1.421 date=$(date "+%Y%m%d") 1.422 package="slitaz-cross-$ARCH-toolchain-$date" 1.423 tarball="$package.tar.bz2" 1.424 - cd /usr/cross 1.425 + cd /cross 1.426 mkdir $package || exit 1 1.427 echo "" 1.428 echo -n "Copying $ARCH to: $package" 1.429 cp -a $ARCH $package 1.430 - rm -rf $package/share $package/etc 1.431 + rm -rf $package/source $package/log 1.432 status 1.433 prebuilt_readme 1.434 echo -n "Creating prebuilt $ARCH toolchain tarball..." 1.435 tar cjf $tarball $package 1.436 status 1.437 - mv -f $tarball $WORK 1.438 rm -rf $package 1.439 - size=$(du -sh $WORK/$tarball | awk '{print $1}') 1.440 - echo "Tarball path: $WORK/$tarball" 1.441 + size=$(du -sh $tarball | awk '{print $1}') 1.442 + echo "Tarball path: $(pwd)/$tarball" 1.443 echo "Tarball size: $size" 1.444 echo "" ;; 1.445 *)