#!/bin/sh # GCC package build script # Copyright 2008 Gilbert Ashley # This script has been heavily modified from an old version # of the Slackware gcc.SlackBuild VERSION=4.4.3 CPP_SO_VERSION=6.0.13 ARCH=${ARCH:-i586} TARGET=$ARCH-kiss-linux BUILD=3 # uncomment this to build and run the tests # GCCCHECK=1 if [ "$ARCH" = "i386" ]; then CFLAGS="-O2 -march=i386 -mcpu=i686" LIBDIRSUFFIX="" elif [ "$ARCH" = "i486" ]; then CFLAGS="-O2 -march=i486 -mtune=i686" LIBDIRSUFFIX="" elif [ "$ARCH" = "i586" ]; then CFLAGS="-O2 -march=i586 -mtune=i686" LIBDIRSUFFIX="" elif [ "$ARCH" = "i686" ]; then CFLAGS="-O2 -march=i686" LIBDIRSUFFIX="" elif [ "$ARCH" = "s390" ]; then CFLAGS="-O2" LIBDIRSUFFIX="" elif [ "$ARCH" = "x86_64" ]; then CFLAGS="-O2 -fPIC" LIBDIRSUFFIX="64" fi CWD=`pwd` # Temporary build location. TMP=$CWD/gcc-Project # This is the main DESTDIR target: PKG1=$TMP/package-gcc # This package content is split out from PKG1 PKG2=$TMP/package-gcc-g++ # This package is for the cxxlibs (libstdc++) PKG3=$TMP/package-cxxlibs # This package is for the libgcc items (libgcc_s.so, mudflap, etc and cpp) PKG4=$TMP/package-libgcc unpack_sources() { # Clear the build locations: if [ -d $TMP ]; then rm -rf $TMP fi mkdir -p $PKG{1,2}/usr/share/doc/gcc_$VERSION cd $TMP echo "Unpacking sources" tar xvf $CWD/gcc-$VERSION.tar.xz &> /dev/null } patch_sources() { ( cd $TMP/gcc-$VERSION patch -p1 < $CWD/gcc-no_fixincludes.diff echo "Correcting permissions in source " chown -R root:root . find . -perm 777 -exec chmod 755 {} \; find . -perm 775 -exec chmod 755 {} \; find . -perm 754 -exec chmod 755 {} \; find . -perm 664 -exec chmod 644 {} \; ) } build_sources() { # build gcc ( cd $TMP mkdir gcc.build.lnx ; cd gcc.build.lnx ; if [ "$ARCH" != "x86_64" ]; then GCC_ARCHOPTS="--with-arch=$ARCH" else GCC_ARCHOPTS="--disable-multilib" fi ../gcc-${VERSION}/configure --prefix=/usr \ --libdir=/usr/lib${LIBDIRSUFFIX} \ --enable-shared \ --enable-bootstrap \ --enable-languages=c,c++ \ --enable-threads=posix \ --enable-checking=release \ --with-system-zlib \ --with-python-dir=/lib${LIBDIRSUFFIX}/python2.6/site-packages \ --disable-libunwind-exceptions \ --enable-__cxa_atexit \ --enable-libssp \ --with-gnu-ld \ ${GCC_ARCHOPTS} \ --build=${TARGET} \ --target=${TARGET} \ --host=${TARGET} # Start the build: make -j3 bootstrap make -j3 info # Set GCCCHECK=something to run the tests if [ ! -z $GCCCHECK ]; then make -j3 check fi # keep a log ) 2>&1 | tee $TMP/gcc.build.log } install_docs() { ( cd $TMP/gcc-$VERSION mkdir -p $PKG1/usr/share/doc/gcc_$VERSION # Only the most recent ChangeLog... shouldn't be too big. :) cp -a \ COPYING COPYING.LIB ChangeLog INSTALL MAINTAINERS README* \ $PKG1/usr/share/doc/gcc_$VERSION cp -a $CWD/gcc.build $PKG1/usr/share/doc/gcc_$VERSION mkdir -p $PKG1/usr/share/doc/gcc_${VERSION}/gcc ( cd gcc cp -a ABOUT* COPYING* LANG* README* \ $PKG1/usr/share/doc/gcc_$VERSION/gcc ) mkdir -p $PKG2/usr/share/doc/gcc_${VERSION}/libstdc++-v3 ( cd libstdc++-v3 cp -a README $PKG2/usr/share/doc/gcc_${VERSION}/libstdc++-v3 cp -a doc/html/faq.html $PKG2/usr/share/doc/gcc_${VERSION}/libstdc++-v3/faq.html cp $CWD/gcc.build $PKG2/usr/share/doc/gcc_${VERSION}/libstdc++-v3 ) ) } install_sources() { cd $TMP/gcc.build.lnx make install DESTDIR=$PKG1 make -i install-info DESTDIR=$PKG1 # Be sure the "specs" file is installed. if [[ ! -r $PKG1/usr/lib${LIBDIRSUFFIX}/gcc/${TARGET}/${VERSION}/specs ]] ; then cat stage1-gcc/specs > $PKG1/usr/lib${LIBDIRSUFFIX}/gcc/${TARGET}/${VERSION}/specs fi # Make our 64bit gcc look for 32bit gcc binaries in ./32 subdirectory: if [[ "$ARCH" = "x86_64" ]] ; then sed -i 's#;.\(:../lib !m64 m32;\)$#;32\1#' \ $PKG1/usr/lib${LIBDIRSUFFIX}/gcc/${TARGET}/${VERSION}/specs fi #chmod 755 $PKG1/usr/lib/libgcc_s.so.1 # gcc-4.x has some new shared libs ( cd $PKG1/usr/lib${LIBDIRSUFFIX} chmod 755 libgcc_s.so.1 libmudflap.so.0.0.0 \ libmudflapth.so.0.0.0 libssp.so.0.0.0 \ libgomp.so.1.0.0 libstdc++.so.${CPP_SO_VERSION} chmod 644 *.la ) # This is provided by binutils, so delete it here: rm -f $PKG1/usr/lib${LIBDIRSUFFIX}/libiberty.a # just in case rm -f $PKG1/usr/lib/libiberty.a } # the real work starts here: ##### this block can commented out and skipped ##### to avoid a complete re-compile if [[ -z $SKIP_REBUILD ]] ; then unpack_sources patch_sources build_sources else rm -rf $PKG1 $PKG2 $PKG3 $PKG4 mkdir -p $PKG1 $PKG2 $PKG3 $PKG4 fi ##### install_docs install_sources # process the package content and build the packages echo "Processing package content in PKG1:" echo $PKG1 # Strip out unneeded stuff from the libraries and binaries: ( cd $PKG1 echo "Stripping bins and libs" strip --strip-unneeded usr/bin/* 2> /dev/null find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null find . -name "*.a" | xargs file | grep "archive" | cut -f 1 -d : | xargs strip --strip-debug ) # Fix stuff up: ( cd $PKG1 mkdir -p lib cd lib ln -sf /usr/bin/cpp . ) ( cd $PKG1/usr/bin # create cognizant links to main executables -first gcc mv gcc gcc_$VERSION ln -sf gcc_$VERSION gcc ln -sf gcc cc ln -sf gcc_$VERSION ${TARGET}-gcc ln -sf gcc_$VERSION ${TARGET}-gcc_$VERSION # now the g++ mv g++ g++-gcc_$VERSION ln -sf g++-gcc_$VERSION g++ ln -sf g++ c++ ln -sf g++-gcc_$VERSION ${TARGET}-c++ ln -sf g++-gcc_$VERSION ${TARGET}-g++ ) ( cd $PKG1/usr/man gzip -9 */* cd man1 ln -sf gcc.1.gz cc.1.gz ln -sf g++.1.gz c++.1.gz ) mkdir -p $PKG1/usr/share mv $PKG1/usr/man $PKG1/usr/share/man ( cd $PKG1/usr/info rm dir gzip -9 * ) mv $PKG1/usr/info $PKG1/usr/share/info mkdir -p $PKG{1,2,3,4}/install # Install the descriptions (and doinst.sh for cxxlibs): ( cd $CWD cat pkg-desc.gcc > $PKG1/install/pkg-desc cat pkg-desc.gcc-g++ > $PKG2/install/pkg-desc cat pkg-desc.cxxlibs > $PKG3/install/pkg-desc cat pkg-desc.libgcc > $PKG4/install/pkg-desc # doinst.sh stub adds our target to ld.so.conf cat doinst.sh-cxxlibs > $PKG2/install/doinst.sh cat doinst.sh-cxxlibs > $PKG3/install/doinst.sh ) # Filter all .la files (thanks much to Mark Post for the sed script): ( cd $TMP for file in `find . -type f -name "*.la"` ; do cat $file | sed -e 's%-L/gcc-[[:graph:]]* % %g' > $TMP/tmp-la-file cat $TMP/tmp-la-file > $file done rm $TMP/tmp-la-file ) # remove include-fixed headers. The README in this dir admits that they # can be wrongly corrected and I found it to be so. So, remove evrything that # is not from the kernel or sys skip() { ( cd $PKG1/usr/lib${LIBDIRSUFFIX}/gcc/${TARGET}/$VERSION/include-fixed find * -type d ! -name linux -exec rm -rf {} \; &> /dev/null find * -maxdepth 0 -type f ! -name README -a ! -name features.h \ -a ! -name limits.h -a ! -name syslimits.h -exec rm -f {} \; &> /dev/null ) rm -f $PKG1/usr/lib${LIBDIRSUFFIX}/gcc/${TARGET}/$VERSION/install-tools/include/limits.h } # Now move the g++ components into their own package tree echo "Moving g++ components to PKG2:" echo $PKG2 # gcc-g++: ( cd $PKG2 mkdir -p usr/bin mv $PKG1/usr/bin/*++* usr/bin mkdir -p usr/include mv $PKG1/usr/include/c++ usr/include # get rid of pre-compiled headers and save 35-40MB on g++ package! (for old compilers gcc-3.4.6) rm -rf usr/include/c++/$VERSION/${TARGET}/bits/stdc++.h.gch # move cxx libs and create links mkdir usr/lib${LIBDIRSUFFIX} mv $PKG1/usr/lib${LIBDIRSUFFIX}/*++* usr/lib${LIBDIRSUFFIX} ( cd usr/lib${LIBDIRSUFFIX} ; ln -sf libstdc++.so.${CPP_SO_VERSION} libstdc++.so.6 ) ( cd usr/lib${LIBDIRSUFFIX} ; ln -sf libstdc++.so.${CPP_SO_VERSION} libstdc++.so ) mkdir -p usr/${TARGET}/lib ( cd usr/${TARGET}/lib ; ln -sf ../../lib/libstdc++.so.${CPP_SO_VERSION} libstdc++.so.${CPP_SO_VERSION} ) ( cd usr/${TARGET}/lib ; ln -sf ../../lib/libstdc++.so.${CPP_SO_VERSION} libstdc++.so.6 ) ( cd usr/${TARGET}/lib ; ln -sf ../../lib/libstdc++.so.${CPP_SO_VERSION} libstdc++.so ) # link the static libs and libtool files also ( cd usr/${TARGET}/lib ; ln -sf ../../lib/libstdc++.a libstdc++.a ) ( cd usr/${TARGET}/lib ; ln -sf ../../lib/libstdc++.la libstdc++.la ) ( cd usr/${TARGET}/lib ; ln -sf ../../lib/libsupc++.a libsupc++.a ) ( cd usr/${TARGET}/lib ; ln -sf ../../lib/libstdc++.la libsupc++.la ) mkdir -p usr/libexec/gcc/${TARGET}/$VERSION mv $PKG1/usr/libexec/gcc/${TARGET}/$VERSION/cc1plus usr/libexec/gcc/${TARGET}/$VERSION/cc1plus mkdir -p usr/share/man/man1 mv $PKG1/usr/share/man/man1/*++* usr/share/man/man1 ) echo "Copying cxxlibs content to PKG3:" echo $PKG3 # copy the content for the cxxlibs package mkdir -p $PKG3/usr/lib${LIBDIRSUFFIX} cp -a $PKG2/usr/lib${LIBDIRSUFFIX}/libstdc++.so.${CPP_SO_VERSION} $PKG3/usr/lib${LIBDIRSUFFIX} chown 755 $PKG3/usr/lib${LIBDIRSUFFIX}/libstdc++.so.${CPP_SO_VERSION} ( cd $PKG3/usr/lib${LIBDIRSUFFIX} ; ln -sf libstdc++.so.${CPP_SO_VERSION} libstdc++.so.6 ) ( cd $PKG3/usr/lib${LIBDIRSUFFIX} ; ln -sf libstdc++.so.${CPP_SO_VERSION} libstdc++.so ) mkdir -p $PKG3/usr/${TARGET}/lib${LIBDIRSUFFIX} ( cd $PKG3/usr/${TARGET}/lib${LIBDIRSUFFIX} ; ln -sf ../../lib/libstdc++.so.${CPP_SO_VERSION} libstdc++.so.${CPP_SO_VERSION} ) ( cd $PKG3/usr/${TARGET}/lib${LIBDIRSUFFIX} ; ln -sf ../../lib/libstdc++.so.${CPP_SO_VERSION} libstdc++.so.6 ) ( cd $PKG3/usr/${TARGET}/lib${LIBDIRSUFFIX} ; ln -sf ../../lib/libstdc++.so.${CPP_SO_VERSION} libstdc++.so ) echo "Copying libgcc content to PKG4:" echo $PKG4 # copy the content for libgcc package mkdir -p $PKG4/usr/{bin,lib${LIBDIRSUFFIX}} # cp $PKG1/usr/lib/libgcc_s.so.1 $PKG4/usr/lib cp -a $PKG1/usr/lib${LIBDIRSUFFIX}/*.so* $PKG4/usr/lib${LIBDIRSUFFIX} chmod 755 $PKG4/usr/lib${LIBDIRSUFFIX}/libgcc_s.so.1 cp $PKG1/usr/bin/cpp $PKG4/usr/bin # mkdir -p $PKG4/lib # ( cd $PKG4/lib ; ln -sf ../usr/bin/cpp cpp ) ( cd $PKG4/usr/lib${LIBDIRSUFFIX} ; ln -sf ../bin/cpp cpp ) echo "Creating final packages in TMP:" echo $TMP # now make the packages ( cd $PKG1 tpkg-make $TMP/gcc_$VERSION-$ARCH-$BUILD$PASS.tpkg ) ( cd $PKG2 tpkg-make $TMP/gcc-g++_$VERSION-$ARCH-$BUILD$PASS.tpkg ) ( cd $PKG3 tpkg-make $TMP/cxxlibs-${CPP_SO_VERSION}_${VERSION}-$ARCH-$BUILD$PASS.tpkg ) ( cd $PKG4 tpkg-make $TMP/libgcc_$VERSION-$ARCH-$BUILD$PASS.tpkg ) echo echo "GCC package build complete!" echo