diff --git a/helpers/chroot.sh b/helpers/chroot.sh index fd7633625bb..77f0653c6c4 100644 --- a/helpers/chroot.sh +++ b/helpers/chroot.sh @@ -36,7 +36,7 @@ else fi REQDIRS="bin sbin tmp var sys proc dev xbps xbps_builddir \ - xbps_destdir xbps_srcdistdir" + xbps_destdir xbps_srcdistdir xbps_crossdir" for f in ${REQDIRS}; do [ ! -d $XBPS_MASTERDIR/$f ] && mkdir -p $XBPS_MASTERDIR/$f done @@ -52,6 +52,11 @@ echo "XBPS_CXXFLAGS=\"\$XBPS_CFLAGS\"" >> $XBPS_MASTERDIR/etc/xbps.conf if [ -n "$XBPS_MAKEJOBS" ]; then echo "XBPS_MAKEJOBS=$XBPS_MAKEJOBS" >> $XBPS_MASTERDIR/etc/xbps.conf fi +if [ -n "$XBPS_CROSS_TARGET" -a -d "$XBPS_CROSS_DIR" ]; then + echo "XBPS_CROSS_TARGET=$XBPS_CROSS_TARGET" >> \ + $XBPS_MASTERDIR/etc/xbps.conf + echo "XBPS_CROSS_DIR=/xbps_crossdir" >> $XBPS_MASTERDIR/etc/xbps.conf +fi rebuild_ldso_cache() { @@ -88,6 +93,11 @@ mount_chroot_fs() local cnt= REQFS="sys proc dev xbps xbps_builddir xbps_destdir xbps_srcdistdir" + if [ -d "$XBPS_CROSS_DIR" ]; then + local cross=yes + REQFS="$REQFS xbps_crossdir" + fi + for f in ${REQFS}; do if [ ! -f $XBPS_MASTERDIR/.${f}_mount_bind_done ]; then echo -n "=> Mounting $f in chroot... " @@ -97,6 +107,9 @@ mount_chroot_fs() xbps_builddir) blah=$XBPS_BUILDDIR;; xbps_destdir) blah=$XBPS_DESTDIR;; xbps_srcdistdir) blah=$XBPS_SRCDISTDIR;; + xbps_crossdir) + [ -n $cross ] && blah=$XBPS_CROSS_DIR + ;; *) blah=/$f;; esac mount --bind $blah $XBPS_MASTERDIR/$f diff --git a/helpers/cross-compilation.sh b/helpers/cross-compilation.sh new file mode 100644 index 00000000000..8d6ac87c9c0 --- /dev/null +++ b/helpers/cross-compilation.sh @@ -0,0 +1,39 @@ +# +# This helper sets some required vars to be able to cross build +# packages on xbps. The target is specified in the configuration file +# and will be read any time the cross compilation flag is used. +# +[ -z "$XBPS_CROSS_TARGET" -o ! -d $XBPS_CROSS_DIR/bin ] && return 1 + +# Check if all required bins are there. +for bin in gcc g++ cpp ar as ranlib ld strip; do + if [ ! -x $XBPS_CROSS_DIR/bin/$XBPS_CROSS_TARGET-${bin} ]; then + msg_error "cross-compilation: cannot find ${bin}, aborting." + fi +done + +SAVE_PATH="$PATH" + +cross_compile_setvars() +{ + export CC=$XBPS_CROSS_TARGET-gcc + export CXX=$XBPS_CROSS_TARGET-g++ + export CPP=$XBPS_CROSS_TARGET-cpp + export AR=$XBPS_CROSS_TARGET-ar + export AS=$XBPS_CROSS_TARGET-as + export RANLIB=$XBPS_CROSS_TARGET-ranlib + export LD=$XBPS_CROSS_TARGET-ld + export STRIP=$XBPS_CROSS_TARGET-strip + export PATH="$XBPS_CROSS_DIR/bin:$PATH" +} + +cross_compile_unsetvars() +{ + unset CC CXX CPP AR AS RANLIB LD STRIP PATH + export PATH="$SAVE_PATH" +} + +if [ "$build_style" = "gnu_configure" ]; then + configure_args="--build=$XBPS_CROSS_HOST --host=$XBPS_CROSS_TARGET" + configure_args="$configure_args --target=$XBPS_CROSS_TARGET" +fi diff --git a/templates/glibc32.tmpl b/templates/glibc32.tmpl new file mode 100644 index 00000000000..2a92637924e --- /dev/null +++ b/templates/glibc32.tmpl @@ -0,0 +1,80 @@ +# Template file for 'glibc32' +pkgname=glibc32 +version=2.8 +wrksrc="libc" +distfiles="ftp://ftp.archlinux.org/other/glibc/glibc-2.8_20080828.tar.bz2" +build_style=gnu_configure +configure_script="../configure" +configure_env="BUILD_CC=$XBPS_CROSS_TARGET-gcc" +configure_args="--with-tls -disable-profile --with-__thread + --enable-kernel=2.6.16 --enable-add-ons --without-gd --enable-bind-now + --without-cvs --without-selinux --prefix=/usr --libdir=/usr/lib32 + --with-headers=/usr/include --cache-file=config.cache + --infodir=/usr/share/info" +make_install_target="install_root=$XBPS_DESTDIR/$pkgname-$version install" +short_desc="The GNU C library (32 bits)" +maintainer="Juan RP " +checksum=f5756668f201e093cae0404e59dcf8c43ccc07757fd0a7455298ed89126c366a +long_desc=" + The GNU C Library is the standard system C library for all GNU systems, + and is an important part of what makes up a GNU system. It provides the + system API for all programs written in C and C-compatible languages such + as C++ and Objective C; the runtime facilities of other programming + languages use the C library to access the underlying operating system. + + This version is only for 64 bits systems." + +cross_compiler=yes +base_package=yes +build_depends="perl-5.10.0" + +pre_configure() +{ + # We must configure it in another directory. + mkdir -p $wrksrc/build_obj && cd $wrksrc/build_obj + wrksrc=$wrksrc/build_obj + echo "slibdir=/lib32" > $wrksrc/configparms + echo "CFLAGS+=-march=${XBPS_CROSS_TARGET%%-*} -mtune=generic" \ + >> $wrksrc/configparms + echo "libc_cv_forced_unwind=yes" > config.cache + echo "libc_cv_c_cleanup=yes" >> config.cache +} + +pre_install() +{ + # Pre-create /lib32 and /usr/lib32 directories. + for f in lib32 usr/lib32; do + [ ! -d $XBPS_MASTERDIR/$f ] && mkdir -p $XBPS_MASTERDIR/$f + done +} + +post_install() +{ + local destdir=$XBPS_DESTDIR/$pkgname-$version + local tmpdir=$XBPS_BUILDDIR/$pkgname-tmp + + mkdir -p $tmpdir/usr/include/gnu + mkdir -p $tmpdir/usr/include/sys + + # Remove all headers except the ones required for 32bits stuff. + mv -v $destdir/include/gnu/stubs-32.h $tmpdir/usr/include/gnu + mv -v $destdir/include/sys/elf.h $tmpdir/usr/include/sys + mv -v $destdir/include/sys/vm86.h $tmpdir/usr/include/sys + + rm -rf $destdir/include + mkdir -p $destdir/usr/include + mv -v $tmpdir/usr/include/* $destdir/usr/include + + # Remove bins and unneeded stuff for compat32. + [ -d $destdir/xbps_destdir ] && rm -rf $destdir/xbps_destdir + rm -rf $destdir/sbin $destdir/bin $destdir/usr/sbin $destdir/usr/bin + rm -rf $destdir/share $destdir/libexec $destdir/etc + mv -v $destdir/lib/gconv $destdir/usr/lib32 + + # Remove wrong symlinks in shared libs and move them to /lib32. + find $destdir/lib -type l -print|xargs rm -v + mv -v $destdir/lib/* $destdir/lib32 + cd $destdir/lib && ln -s ../lib32/ld-linux.so.2 ld-linux.so.2 + + rm -rf $tmpdir +} diff --git a/xbps.conf b/xbps.conf index 59d388c075c..36336d0fa47 100644 --- a/xbps.conf +++ b/xbps.conf @@ -39,3 +39,9 @@ XBPS_CXXFLAGS="$XBPS_CFLAGS" # Number of jobs when running GNU or BSD make style packages. # #XBPS_MAKEJOBS=4 + +# +# Cross compilation stuff. +# +#XBPS_CROSS_TARGET=i686-pc-linux-gnu +#XBPS_CROSS_DIR=/storage/mktoolchain/$XBPS_CROSS_TARGET diff --git a/xbps.sh b/xbps.sh index 180693abfcc..bb179114934 100755 --- a/xbps.sh +++ b/xbps.sh @@ -32,6 +32,7 @@ trap "echo && exit 1" INT QUIT : ${progname:=$(basename $0)} : ${fetch_cmd:=wget} : ${xbps_machine:=$(uname -m)} +: ${XBPS_CROSS_HOST:=$xbps_machine-pc-linux-gnu} usage() { @@ -235,7 +236,7 @@ reset_tmpl_vars() postinstall_helpers make_install_target version \ tar_override_cmd xml_entries sgml_entries \ build_depends libtool_fixup_la_stage no_fixup_libtool \ - disable_parallel_build run_depends \ + disable_parallel_build run_depends cross_compiler \ XBPS_EXTRACT_DONE XBPS_CONFIGURE_DONE \ XBPS_BUILD_DONE XBPS_INSTALL_DONE" @@ -685,6 +686,17 @@ configure_src_phase() # Apply patches if requested by template file [ ! -f $XBPS_APPLYPATCHES_DONE ] && apply_tmpl_patches + # cross compilation vars. + if [ -n "$cross_compiler" ]; then + . $XBPS_HELPERSDIR/cross-compilation.sh + cross_compile_setvars + else + if [ "$build_style" = "gnu_configure" ]; then + configure_args="$configure_args --host=${xbps_machine}-pc-linux-gnu" + configure_args="$configure_args --build=${xbps_machine}-pc-linux-gnu" + fi + fi + # Run pre_configure helpers. run_func pre_configure @@ -712,8 +724,6 @@ configure_src_phase() # if [ "$build_style" = "gnu_configure" ]; then ${configure_script} \ - --host=${xbps_machine}-linux-gnu \ - --build=${xbps_machine}-linux-gnu \ --prefix=${_prefix} --sysconfdir=/etc \ --infodir=$XBPS_DESTDIR/$pkgname-$version/usr/share/info \ --mandir=$XBPS_DESTDIR/$pkgname-$version/usr/share/man \ @@ -755,6 +765,9 @@ configure_src_phase() unset eval ${f%=*} done + # unset cross compiler vars. + [ -n "$cross_compiler" ] && cross_compile_unsetvars + unset_build_vars touch -f $XBPS_CONFIGURE_DONE @@ -784,6 +797,12 @@ build_src_phase() cd $wrksrc || exit 1 + # cross compilation vars. + if [ -n "$cross_compiler" ]; then + . $XBPS_HELPERSDIR/cross-compilation.sh + cross_compile_setvars + fi + [ -z "$make_cmd" ] && make_cmd=/usr/bin/make # @@ -821,6 +840,10 @@ build_src_phase() -o "$libtool_fixup_la_stage" = "postbuild" ]; then libtool_fixup_la_files fi + + # unset cross compiler vars. + [ -n "$cross_compiler" ] && cross_compile_unsetvars + unset_build_vars touch -f $XBPS_BUILD_DONE @@ -848,6 +871,12 @@ install_src_phase() msg_normal "Running install phase for: $pkgname-$version." + # cross compilation vars. + if [ -n "$cross_compiler" ]; then + . $XBPS_HELPERSDIR/cross-compilation.sh + cross_compile_setvars + fi + if [ "$build_style" = "custom-install" ]; then run_func do_install else @@ -859,6 +888,9 @@ install_src_phase() # run_func post_install + # unset cross compiler vars. + [ -n "$cross_compiler" ] && cross_compile_unsetvars + msg_normal "Installed $pkgname-$version into $XBPS_DESTDIR." touch -f $XBPS_INSTALL_DONE