# HG changeset patch # User Christophe Lincoln # Date 1337395673 -7200 # Node ID 71450d322f7bb044e68449c75d6240534e062e9f # Parent 9c322a61167d2ee9dd93d9d975a974734d45da36 cook, cross, *.conf: improve cross compilation and small clean diff -r 9c322a61167d -r 71450d322f7b cook --- a/cook Wed May 16 11:55:25 2012 +0200 +++ b/cook Sat May 19 04:47:53 2012 +0200 @@ -17,9 +17,6 @@ broken="$CACHE/broken" blocked="$CACHE/blocked" -# Old style compatibility -SOURCES_REPOSITORY=$SRC - # # Functions # @@ -319,8 +316,7 @@ # Copy all generic files (locale, pixmaps, .desktop). We use standard paths, # so some packages need to copy these files with the receipt and genpkg_rules. -copy_generic_files() -{ +copy_generic_files() { # $LOCALE is set in cook.conf if [ "$LOCALE" ]; then if [ -d "$install/usr/share/locale" ]; then @@ -373,8 +369,7 @@ # Find and strip : --strip-all (-s) or --strip-debug on static libs as well # as removing uneeded files like in Python packages. Cross compiled binaries # must be stripped with cross-tools aka $ARCH-slitaz-*-strip -strip_package() -{ +strip_package() { case "$ARCH" in arm|x86_64) export STRIP=${HOST_SYSTEM}-strip ;; *) export STRIP=strip ;; @@ -442,9 +437,9 @@ echo "cook: $ARCH sysroot: $SYSROOT" else echo "cook: adding /usr/cross/$ARCH/bin to PATH" - export PATH=$PATH:/usr/cross/$ARCH/bin + export PATH=$PATH:$CROSS_PREFIX/bin fi - export CROSS_COMPILE=$HOST_SYSTEM- + export CROSS_COMPILE=${HOST_SYSTEM}- echo "cook: using cross-tools: $CROSS_COMPILE" export CC=${HOST_SYSTEM}-gcc export CXX=${HOST_SYSTEM}-g++ @@ -452,9 +447,7 @@ export AS=${HOST_SYSTEM}-as export RANLIB=${HOST_SYSTEM}-ranlib export LD=${HOST_SYSTEM}-ld - export STRIP=${HOST_SYSTEM}-strip - #export PKGCONFIG=${HOST_SYSTEM}-pkg-config - ;; + export STRIP=${HOST_SYSTEM}-strip ;; esac [ "$QA" ] && receipt_quality @@ -775,8 +768,7 @@ fi } -tac() -{ +tac() { sed '1!G;h;$!d' $1 } @@ -895,7 +887,7 @@ # Use setup pkgs from cross.conf or cook.conf. When cross compiling # ARCH-setup or 'cross check-env' should be used before: cook setup case "$ARCH" in - arm) + arm|x86_64) if [ ! -x "/usr/bin/cross" ]; then gettext "ERROR: cross is not installed"; echo exit 1 @@ -905,7 +897,7 @@ esac for pkg in $SETUP_PKGS; do if [ "$forced" ]; then - tazpkg get-install $pkg --forced + tazpkg -gi $pkg --forced else [ -d "$INSTALLED/$pkg" ] || tazpkg get-install $pkg fi @@ -938,7 +930,7 @@ arch=${1%-setup} check_root echo "" - gettext "Setting up your cross environment"; echo + boldify $(gettext "Setting up your cross environment") separator init_db_files sed -i \ @@ -959,22 +951,22 @@ /etc/slitaz/cook.conf ;; esac . /etc/slitaz/cook.conf - echo "Target arch : $ARCH" - echo "Configure args: $CONFIGURE_ARGS" + echo "Target arch : $ARCH" + echo "Configure args : $CONFIGURE_ARGS" if [ "$SYSROOT" ]; then - echo "Arch sysroot: $SYSROOT" + echo "Arch sysroot : $SYSROOT" CC=/usr/bin/${HOST_SYSTEM}-gcc else - echo "Path: /usr/cross/$ARCH/bin" + echo "Additional path : /usr/cross/$ARCH/bin" CC=/usr/cross/$ARCH/bin/${HOST_SYSTEM}-gcc fi if [ -x $CC ]; then - echo "Cross compiler: ${HOST_SYSTEM}-gcc" + echo "Cross compiler : ${HOST_SYSTEM}-gcc" else - echo "WARNING: C compiler is missing: ${HOST_SYSTEM}-gcc" + colorize "C compiler is missing: ${HOST_SYSTEM}-gcc" 36 echo "Run 'cross compile' to cook a toolchain" fi - echo "" ;; + separator && echo "" ;; test) # Test a cook environment. echo "Cook test: testing the cook environment" | log diff -r 9c322a61167d -r 71450d322f7b cook.conf --- a/cook.conf Wed May 16 11:55:25 2012 +0200 +++ b/cook.conf Sat May 19 04:47:53 2012 +0200 @@ -43,9 +43,14 @@ BUILD_SYSTEM="$ARCH-slitaz-linux" HOST_SYSTEM="$ARCH-slitaz-linux" -# Cross compilation settings. Cross sysroot is used by cross-tools to -# set the system. SliTaz standard is to point sysroot to the directory -# of the cross toolchain. Example: SYSROOT="/usr/$HOST_SYSTEM" +# Cross compilation settings. Prefix is use by cook to export PATH so it +# can use the cross-tools in $CROSS_PREFIX/bin. +CROSS_PREFIX=/usr/cross/$ARCH + +# Sysroot is used by cross-tools to set the system. SliTaz standard is +# to point sysroot to the directory of the cross toolchain. The default +# is to use cross with: --prefix=/usr/cross/$ARCH and no --with-sysroot= +# Example: SYSROOT="/usr/$HOST_SYSTEM" SYSROOT="" # SliTaz optimisation flags - Wide compatibility & optimized for ARCH. @@ -89,3 +94,4 @@ # Old way/tazwok compatibility. BUILD_HOST="$HOST_SYSTEM" +SOURCES_REPOSITORY=$SRC diff -r 9c322a61167d -r 71450d322f7b cooker --- a/cooker Wed May 16 11:55:25 2012 +0200 +++ b/cooker Sat May 19 04:47:53 2012 +0200 @@ -295,13 +295,10 @@ [ "$2" ] || hours=2 if [ ! -f "$crontabs" ]; then mkdir -p /var/spool/cron/crontabs - echo "# Run SliTaz Cooker every $hours hours" > $crontabs - echo "0 */$hours * * * /usr/bin/cooker" >> $crontabs - /etc/init.d/crond start fi if ! fgrep -q /usr/bin/cooker $crontabs; then echo "# Run SliTaz Cooker every $hours hours" > $crontabs - echo "0 */$hours * * * /usr/bin/cooker" >> $crontabs + echo "0 */$hours * * * /usr/bin/cooker --output=html" >> $crontabs killall crond 2>/dev/null && /etc/init.d/crond start fi ;; check-cron) diff -r 9c322a61167d -r 71450d322f7b cross --- a/cross Wed May 16 11:55:25 2012 +0200 +++ b/cross Sat May 19 04:47:53 2012 +0200 @@ -26,12 +26,12 @@ howto Man alike and howto info Display cross-tools info testsuite Execute a small testsuite - check-env Check build host tools + check Check build host environment download Download necessary sources show-log Show a compile log binutils Compile Binutils + linux-headers Install Kernel headers gcc-static Compile GCC static - linux-headers Install Kernel headers glibc Compile GNU Glibc gcc-final Compile final GCC busybox Cross compile Busybox @@ -78,11 +78,12 @@ # Get source if not yet in $SRC. download_src() { mkdir -p $SRC && cd $SRC - [ -f "binutils-$BINUTILS_VERSION.tar.bz2" ] || wget $BINUTILS_WGET - [ -f "linux-$LINUX_VERSION.tar.bz2" ] || wget $LINUX_WGET - [ -f "glibc-$GLIBC_VERSION.tar.bz2" ] || wget $GLIBC_WGET - [ -f "gcc-$GCC_VERSION.tar.bz2" ] || wget $GCC_WGET - [ -f "busybox-$BUSYBOX_VERSION.tar.bz2" ] || wget $BUSYBOX_WGET + [ -f "$BINUTILS_TARBALL" ] || wget $BINUTILS_WGET + [ -f "$LINUX_TARBALL" ] || wget $LINUX_WGET + [ -f "$GLIBC_TARBALL" ] || wget $GLIBC_WGET + [ -f "$GCC_TARBALL" ] || wget $GCC_WGET + [ -f "$BUSYBOX_TARBALL" ] || wget $BUSYBOX_WGET + [ -f "$PKGCONFIG_TARBALL" ] || wget $PKGCONFIG_WGET } # Use sysroot or not ? @@ -91,9 +92,41 @@ PREFIX=/usr HDR_PATH=$SYSROOT/usr sysroot="--with-sysroot=$SYSROOT" - echo "Configure : $sysroot" + echo "Configure: $sysroot" else - HDR_PATH=$PREFIX + HDR_PATH=$PREFIX/usr + fi +} + +# Work around to fix GCC include search path +# +# GCC include search path is: $PREFIX/$TARGET/include, so make sure it +# is a symlink to default: $PREFIX/usr/include +# +# Glibc install headers in: $PREFIX/include, move them to usr/include +# if needed. After when we cross compile packages with cook we have +# to install build dependencies using --root=$CROSS_PREFIX and so +# default include dir is: $PREFIX/usr/include ($PREFIX is the root +# of our cross environment. +# +check_include() { + cd $PREFIX + echo "Checking: $PREFIX" + if ! readlink include >/dev/null; then + echo "Creating symlink: usr/include include" + cp -a include usr && rm -rf include + ln -s usr/include include + fi + cd $PREFIX/$TARGET + echo "Checking: $PREFIX/$TARGET" + if ! readlink include >/dev/null; then + echo "Creating symlink: ../usr/include include" + cp -a include ../usr && rm -rf include + ln -s ../usr/include include + fi + if ! readlink lib >/dev/null; then + echo "Creating symlink: ../lib lib" + rm -rf lib && ln -s ../lib lib fi } @@ -101,10 +134,10 @@ binutils() { init_compile rm -rf binutils-$BINUTILS_VERSION - echo "Extracting: binutils-$BINUTILS_VERSION.tar.bz2" - tar xjf $SRC/binutils-$BINUTILS_VERSION.tar.bz2 + echo "Extracting: $BINUTILS_TARBALL" + tar xjf $SRC/$BINUTILS_TARBALL : ${BINUTILS_ARGS=--enable-shared} - echo "Configure : $BINUTILS_ARGS" + echo "Configure: $BINUTILS_ARGS" check_sysroot cd binutils-$BINUTILS_VERSION ./configure \ @@ -114,15 +147,28 @@ $BINUTILS_ARGS $sysroot make || exit 1 make install - #echo "cross: binutils compiled on: $(date)" + echo "cross: binutils compiled on: $(date)" } -# 2. GCC static (first pass) +# 2. Kernel headers could use CROSS_COMPILE but gcc is not yet build. +# NOTE: Compile GCC static first then linux-headers ? +linux_headers() { + init_compile + echo "Extracting: $LINUX_TARBALL" + tar xjf $SRC/$LINUX_TARBALL + check_sysroot + cd linux-$LINUX_VERSION + make mrproper + make ARCH=$ARCH headers_check + make ARCH=$ARCH headers_install INSTALL_HDR_PATH=$HDR_PATH +} + +# 3. GCC static (first pass) gcc_static() { init_compile - echo "Extracting: gcc-$GCC_VERSION.tar.bz2" - tar xjf $SRC/gcc-$GCC_VERSION.tar.bz2 - echo "Configure : $GCC_STATIC_ARGS" + echo "Extracting: $GCC_TARBALL" + tar xjf $SRC/$GCC_TARBALL + echo "Configure: $GCC_STATIC_ARGS" check_sysroot # Arch fixes and work around case "$ARCH" in @@ -147,28 +193,17 @@ make install-gcc install-target-libgcc cd $PREFIX/lib/gcc/$TARGET/$GCC_VERSION echo "Creating symlink for static libgcc: libgcc_eh.a" - rm -f libgcc_eh.a && ln -s libgcc.a libgcc_eh.a -} - -# 3. Kernel headers use static GCC -linux_headers() { - init_compile - echo "Extracting: linux-$LINUX_VERSION.tar.bz2" - tar xjf $SRC/linux-$LINUX_VERSION.tar.bz2 - check_sysroot - cd linux-$LINUX_VERSION - make mrproper - make ARCH=$ARCH headers_check - make ARCH=$ARCH headers_install \ - INSTALL_HDR_PATH=$HDR_PATH + rm -f libgcc_eh.a + ln -s libgcc.a libgcc_eh.a + echo "cross: gcc-static compiled on: $(date)" } # 4. GNU Glibc glibc() { init_compile - echo "Extracting: glibc-$GLIBC_VERSION.tar.bz2" - tar xjf $SRC/glibc-$GLIBC_VERSION.tar.bz2 - echo "Configure : $GLIBC_ARGS" + echo "Extracting: $GLIBC_TARBALL" + tar xjf $SRC/$GLIBC_TARBALL + echo "Configure: $GLIBC_ARGS" [ "$continue" ] || rm -rf glibc-build # Some arch may need glibc-ports and custom CFLAGS case "$ARCH" in @@ -184,7 +219,7 @@ x86_64) ccflags="-m64" ;; esac - #echo "CFLAGS: $CFLAGS" + echo "CFLAGS: $CFLAGS" mkdir -p glibc-build && cd glibc-build BUILD_CC="gcc" \ CC="${TARGET}-gcc $ccflags" \ @@ -194,7 +229,7 @@ --prefix=$PREFIX \ --libexec=$PREFIX/lib/glibc \ --host=$TARGET \ - --with-headers=$PREFIX/include \ + --with-headers=$PREFIX/usr/include \ --with-binutils=$PREFIX/bin \ $GLIBC_ARGS make || exit 1 @@ -204,25 +239,23 @@ cd $SYSROOT ln -s usr/include sys-include else - cd $PREFIX/$TARGET - rm -rf lib include - ln -s ../lib lib - ln -s ../include include + check_include fi - #unset CFLAGS + unset CFLAGS + echo "cross: glibc compiled on: $(date)" } # 5. GCC final gcc_final() { init_compile if [ ! -d "gcc-$GCC_VERSION" ]; then - echo "Extracting: gcc-$GCC_VERSION.tar.bz2" - tar xjf $SRC/gcc-$GCC_VERSION.tar.bz2 + echo "Extracting: $GCC_TARBALL" + tar xjf $SRC/$GCC_TARBALL fi - echo "Configure : $GCC_FINAL_ARGS" + echo "Configure: $GCC_FINAL_ARGS" check_sysroot - rm -rf gcc-build - mkdir gcc-build && cd gcc-build + [ "$continue" ] || rm -rf gcc-build + mkdir -p gcc-build && cd gcc-build ../gcc-$GCC_VERSION/configure \ --prefix=$PREFIX \ --libexec=$PREFIX/lib \ @@ -234,15 +267,16 @@ --with-pkgversion="SliTaz" \ $GCC_FINAL_ARGS $sysroot make || exit 1 - make install + make install && + echo "cross: GCC final compiled on: $(date)" } # Build Busybox to we can create prebuilt tiny rootfs image and boot # from NFS ? cross_busybox() { init_compile - echo "Extracting: busybox-$BUSYBOX_VERSION.tar.bz2" - tar xjf $SRC/busybox-$BUSYBOX_VERSION.tar.bz2 + echo "Extracting: $BUSYBOX_TARBALL" + tar xjf $SRC/$BUSYBOX_TARBALL cd busybox-$BUSYBOX_VERSION # CROSS_COMPILE is exported via init_compile. make defconfig @@ -250,7 +284,8 @@ make install chmod 4755 _install/bin/busybox readelf -h _install/bin/busybox - echo "Busybox install path: $(pwd)/_install" + echo "cross: busybox install path: $(pwd)/_install" + echo "cross: busybox compiled on: $(date)" } # @@ -297,14 +332,26 @@ fi echo -e "\n[CHECKING] readelf -h test.out" | tee -a $logdir/testsuite.log readelf -h test.out | tee -a $logdir/testsuite.log ;; - check-env) - for pkg in mpfr mpfr-dev gmp gmp-dev mpc-library gawk autoconf - do + check) + echo "Checking: build system packages" + for pkg in slitaz-toolchain mpfr mpfr-dev gmp gmp-dev mpc-library \ + gawk autoconf; do if [ ! -d "/var/lib/tazpkg/installed/$pkg" ]; then echo "Missing packages: $pkg" - [ "$install" ] && tazpkg -gi $pkg + if [ -x /usr/sbin/spk-add ]; then + spk-add $pkg + else + tazpkg -gi $pkg + fi fi - done ;; + done + # See: check_include() + if [ "$SYSROOT" ]; then + echo "Using: --with-sysroot=$SYSROOT" + echo "WARNING: not well tested and buggy" + exit 0 + fi + check_include ;; download) download_src ;; show-log) diff -r 9c322a61167d -r 71450d322f7b cross.conf --- a/cross.conf Wed May 16 11:55:25 2012 +0200 +++ b/cross.conf Sat May 19 04:47:53 2012 +0200 @@ -16,17 +16,24 @@ # Cross-tools versions BINUTILS_VERSION="2.22" -LINUX_VERSION="2.6.35.13" +LINUX_VERSION="3.2.14" GLIBC_VERSION="2.13" GCC_VERSION="4.6.3" BUSYBOX_VERSION="1.20.0" +# Cross-tools tarballs +BINUTILS_TARBALL="binutils-$BINUTILS_VERSION.tar.bz2" +LINUX_TARBALL="linux-$LINUX_VERSION.tar.bz2" +GLIBC_TARBALL="glibc-$GLIBC_VERSION.tar.bz2" +GCC_TARBALL="gcc-$GCC_VERSION.tar.bz2" +BUSYBOX_TARBALL="busybox-$BUSYBOX_VERSION.tar.bz2" + # Cross tools urls -BINUTILS_WGET="http://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.bz2" -LINUX_WGET="http://www.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.35/linux-$LINUX_VERSION.tar.bz2" -GLIBC_WGET="http://ftp.gnu.org/gnu/libc/glibc-$GLIBC_VERSION.tar.bz2" -GCC_WGET="http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.bz2" -BUSYBOX_WGET="http://busybox.net/downloads/busybox-$BUSYBOX_VERSION.tar.bz2" +BINUTILS_WGET="http://ftp.gnu.org/gnu/binutils/$BINUTILS_TARBALL" +LINUX_WGET="http://www.kernel.org/pub/linux/kernel/v3.x/$LINUX_TARBALL" +GLIBC_WGET="http://ftp.gnu.org/gnu/libc/$GLIBC_TARBALL" +GCC_WGET="http://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/$GCC_TARBALL" +BUSYBOX_WGET="http://busybox.net/downloads/$BUSYBOX_TARBALL" # Peer package configure arguments # x86_64: BINUTILS_ARGS="--disable-multilib --enable-64-bit-bfd" diff -r 9c322a61167d -r 71450d322f7b doc/cross.txt --- a/doc/cross.txt Wed May 16 11:55:25 2012 +0200 +++ b/doc/cross.txt Sat May 19 04:47:53 2012 +0200 @@ -12,7 +12,6 @@ OPTIONS --log clean: Will also clean log files - --install check-env: Install needed packages --config= Use specified configuration file HOWTO: @@ -37,12 +36,13 @@ # cd cookutils # make install-cross - Setup the build environment and compile a cross toolchain - ------------------------------------------------------------- + Setup the build environment, get source and compile a cross toolchain + --------------------------------------------------------------------- # cook arm-setup # cook setup (vi/nano /etc/slitaz/cross.conf) - # cross check-env --install + # cross check + # cross download # cross compile Test the cross toolchain