#!/bin/bash # GCC package build script (written by volkerdi@slackware.com) # # Copyright 2003, 2004 Slackware Linux, Inc., Concord, California, USA # Copyright 2005, 2006, 2007 Patrick J. Volkerding, Sebeka, Minnesota, USA # All rights reserved. # # Redistribution and use of this script, with or without modification, is # permitted provided that the following conditions are met: # # 1. Redistributions of this script must retain the above copyright # notice, this list of conditions and the following disclaimer. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # # Modified by Stuart Winter for ARMedslack. # 30-May-04 # Notes: # [1] Some parts of the gcc suite do not work for ARM so they are currently # missing; this isn't an oversight on my part - they simply don't work! ;-) # Record toolchain & other info for the build log: slackbuildinfo # Determine the CFLAGS for the known architectures. If you specify -mtune=xscale # for ARM then the build breaks. case $PORTARCH in arm) export SLKCFLAGS="-O2 -march=armv3 -mtune=xscale" export ARCH_CONFARGS="--without-fp --with-softfloat-support=internal" ;; # export ARCH_CONFARGS="--disable-tls" ;; powerpc) export SLKCFLAGS="-O2" ;; sparc) export SLKCFLAGS="-O2" ;; i486) export SLKCFLAGS="-O2 -march=i686" ;; esac # We only use the slack-desc files from the Slackware source tree. CWD=$SLACKSOURCE/d/gcc if [ ! -d "$CWD" ]; then echo "ERROR: Cannot find original Slackware source dir $CWD" echo " you would miss the slack-desc files." exit 1 fi PORTCWD=$PWD # The new toolchain's name: TARGET=$ARCH-slackware-linux # Temporary build location. This should *NOT* be a directory # path a non-root user could create later... # grr - this got annoying actually - deleting /gcc-foo -- and # nobody should have write access to /root. # export TMP=/gcc-$(mcookie) rm -rf $TMP/build-$PACKAGE-* export TMPBUILD=$TMP/build-$PACKAGE-$(mcookie) export PKG=$TMP/package-$PACKAGE rm -rf $TMP/package-gcc* # clear other gcc named packages mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD # This is the main DESTDIR target: PKG1=$TMP/package-gcc # These are the directories to build other packages in: PKG2=$TMP/package-gcc-g++ PKG3=$TMP/package-gcc-gfortran PKG4=$TMP/package-gcc-gnat PKG5=$TMP/package-gcc-java PKG6=$TMP/package-gcc-objc PKG7=$TMP/package-gcc-g++-gch # Create doc dirs: mkdir -p $PKG{1,2,3,4,5,6,7}/usr/doc/gcc-$VERSION # Extract source: tar jxvvf $CWD/gcc-$VERSION.tar.bz2 # Extract the Debian patch set: ( cd gcc-$VERSION # We take some ARM patches from here: DEBIANDIFF=30 # previous was 21 zcat $PORTCWD/sources/gcc-*-$DEBIANDIFF.diff.gz | patch -p1 || failpatch # Apply ARM patches: patch -p1 --fuzz=20 --verbose < debian/patches/arm-gij.dpatch || failpatch patch -p1 --fuzz=20 --verbose < debian/patches/arm-libffi.dpatch || failpatch patch -p0 --fuzz=20 --verbose < debian/patches/arm-pragma-pack.dpatch || failpatch # patch -p1 --fuzz=20 --verbose < debian/patches/arm-tune.dpatch || failpatch # Fix perms/owners slackhousekeeping ) # install docs ( cd gcc-$VERSION mkdir -p $PKG1/usr/doc/gcc-$VERSION # Only the most recent ChangeLog... shouldn't be too big. :) cp -favv \ BUGS COPYING COPYING.LIB ChangeLog \ ChangeLog.tree-ssa FAQ INSTALL \ LAST_UPDATED MAINTAINERS NEWS \ README* *.html \ $PKG1/usr/doc/gcc-$VERSION mkdir -p $PKG1/usr/doc/gcc-${VERSION}/gcc ( cd gcc cp -favv \ ABOUT* COPYING* LANG* ONEWS README* SERVICE \ $PKG1/usr/doc/gcc-$VERSION/gcc mkdir -p $PKG3/usr/doc/gcc-${VERSION}/gcc/fortran ( cd fortran cp -favv \ ChangeLog \ $PKG3/usr/doc/gcc-$VERSION/gcc/fortran/ChangeLog ) mkdir -p $PKG4/usr/doc/gcc-${VERSION}/gcc/ada ( cd ada cp -favv \ ChangeLog ChangeLog.tree-ssa \ $PKG4/usr/doc/gcc-$VERSION/gcc/ada ) mkdir -p $PKG5/usr/doc/gcc-${VERSION}/gcc/java ( cd java cp -favv \ ChangeLog ChangeLog.tree-ssa \ $PKG5/usr/doc/gcc-${VERSION}/gcc/java ) mkdir -p $PKG6/usr/doc/gcc-${VERSION}/gcc/objc ( cd objc cp -favv \ ChangeLog README \ $PKG6/usr/doc/gcc-${VERSION}/gcc/objc ) ) mkdir -p $PKG3/usr/doc/gcc-${VERSION}/libgfortran ( cd libgfortran cp -favv \ ChangeLog \ $PKG3/usr/doc/gcc-${VERSION}/libgfortran/ChangeLog ) mkdir -p $PKG3/usr/doc/gcc-${VERSION}/libada ( cd libada cp -favv \ ChangeLog \ $PKG3/usr/doc/gcc-${VERSION}/libada ) mkdir -p $PKG5/usr/doc/gcc-${VERSION}/fastjar ( cd fastjar cp -favv \ AUTHORS CHANGES COPYING ChangeLog INSTALL \ NEWS README \ $PKG5/usr/doc/gcc-${VERSION}/fastjar ) mkdir -p $PKG5/usr/doc/gcc-${VERSION}/libffi ( cd libffi cp -favv \ ChangeLog ChangeLog.libgcj ChangeLog.v1 \ LICENSE README \ $PKG5/usr/doc/gcc-${VERSION}/libffi ) mkdir -p $PKG5/usr/doc/gcc-${VERSION}/libjava ( cd libjava cp -favv \ COPYING ChangeLog HACKING LIBGCJ_LICENSE \ NEWS README THANKS \ $PKG5/usr/doc/gcc-${VERSION}/libjava ) mkdir -p $PKG1/usr/doc/gcc-${VERSION}/libmudflap ( cd libmudflap cp -favv \ ChangeLog \ $PKG1/usr/doc/gcc-${VERSION}/libmudflap ) mkdir -p $PKG6/usr/doc/gcc-${VERSION}/libobjc ( cd libobjc cp -favv \ ChangeLog README README.threads THREADS THREADS.MACH \ $PKG6/usr/doc/gcc-${VERSION}/libobjc ) mkdir -p $PKG2/usr/doc/gcc-${VERSION}/libstdc++-v3 ( cd libstdc++-v3 cp -favv \ ChangeLog README \ $PKG2/usr/doc/gcc-${VERSION}/libstdc++-v3 cp -favv \ docs/html/faq/index.html \ $PKG2/usr/doc/gcc-${VERSION}/libstdc++-v3/faq.html ) ) # build gcc mkdir gcc.build.lnx cd gcc.build.lnx BOOT_CFLAGS="$SLKCFLAGS" \ STAGE1_CFLAGS="$SLKCFLAGS" \ CFLAGS="$SLKCFLAGS" \ CXXFLAGS="$SLKCFLAGS" \ LIBCFLAGS="$SLKCFLAGS" \ LIBCXXFLAGS="$SLKCFLAGS" \ GCJFLAGS="$SLKCFLAGS" \ TARGET=$ARCH-slackware-linux \ ../gcc-$VERSION/configure $ARCH_CONFARGS \ --prefix=/usr \ --enable-shared \ --enable-languages=c,c++,fortran,objc \ --enable-threads=posix \ --enable-__cxa_atexit \ --disable-checking \ --with-gnu-ld \ --verbose \ --host=$TARGET \ --build=$TARGET \ --target=$TARGET || failconfig # Unknown arch used in --with-arch=arm # --with-arch=$ARCH \ # # ADA nor Java doesn't exist on ARM # although Java used to build with gcc 3.4. Oh well. # --enable-languages=ada,c,c++,fortran,java,objc \ # Start the build: # BOOT_CFLAGS="$SLKCFLAGS -fno-stack-protector" \ # STAGE1_CFLAGS="$SLKCFLAGS -fno-stack-protector" \ make -j2 \ BOOT_CFLAGS="$SLKCFLAGS" \ STAGE1_CFLAGS="$SLKCFLAGS" \ CFLAGS="$SLKCFLAGS" \ CXXFLAGS="$SLKCFLAGS" \ LIBCFLAGS="$SLKCFLAGS" \ LIBCXXFLAGS="$SLKCFLAGS" \ GCJFLAGS="$SLKCFLAGS" \ bootstrap || failmake # gnat does not work on ARM, but it doesn't mean we can't try and build it. # We'll just delete the 812byte .tgz we make later :-) # One day we'll find that it works and we will rejoice. ( cd gcc # make gnatlib GNATLIBCFLAGS="-g $SLKCFLAGS" make gnatlib GNATLIBCFLAGS="$SLKCFLAGS" # make -j2 gnatlib # This wants a shared -ladd2line? #make gnatlib-shared CFLAGS="$SLKCFLAGS" \ CXXFLAGS="$SLKCFLAGS" \ make gnattools ) # Build info pages: make info # Set GCCCHECK=something to run the tests if [ ! -z $GCCCHECK ]; then make check fi # To begin, install the whole thing into one package. We split up later. make install DESTDIR=$PKG1 # Be sure the "specs" file is installed. There was an issue with that on 4.1.1: if [ ! -r $PKG1/usr/lib/gcc/${ARCH}-slackware-linux/${VERSION}/specs ]; then echo "************************************************************************" echo "************************* MISSING SPECS FILE ***************************" echo "************************************************************************" echo "************************************************************************" set -x cat gcc/stage2/specs > $PKG1/usr/lib/gcc/${ARCH}-slackware-linux/${VERSION}/specs set +x fi make -i install-info DESTDIR=$PKG1 # make ada.install-common DESTDIR=$PKG1 # make install-gnatlib DESTDIR=$PKG1 chmod 755 $PKG1/usr/lib/libgcc_s.so.1 # This is provided by binutils, so delete it here: rm -f $PKG1/usr/lib/libiberty.a # Strip out unneeded stuff from the libraries and binaries: ( cd $PKG1 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 ) # Most people debug their own code (not the libraries), so we'll strip these. # It cuts the size down quite a bit. find $PKG1 -name "*.a" | xargs file | grep "archive" | cut -f 1 -d : | xargs strip -g # Fix stuff up: ( cd $PKG1 slackgzpages -i mkdir -p lib cd lib ln -sf /usr/bin/cpp . ) ( cd $PKG1/usr/bin mv g++ g++-gcc-$VERSION mv gcc gcc-$VERSION mv ${TARGET}-gfortran gfortran-gcc-$VERSION ln -sf g++-gcc-$VERSION g++ ln -sf gcc-$VERSION gcc ln -sf g++ c++ ln -sf gcc cc ln -sf gcc-$VERSION ${TARGET}-gcc ln -sf gcc-$VERSION ${TARGET}-gcc-$VERSION ln -sf gcj ${TARGET}-gcj ln -sf gcjh ${TARGET}-gcjh ln -sf g++-gcc-$VERSION ${TARGET}-c++ ln -sf g++-gcc-$VERSION ${TARGET}-g++ ln -sf gfortran-gcc-$VERSION gfortran ln -sf gfortran-gcc-$VERSION ${TARGET}-gfortran ln -sf gfortran-gcc-$VERSION ${TARGET}-gfortran-$VERSION ln -sf gfortran-gcc-$VERSION ${TARGET}-g95 ln -sf gfortran g95 ln -sf gfortran f95 ln -sf gfortran-gcc-$VERSION ${TARGET}-g77 ln -sf gfortran g77 ln -sf gfortran f77 ) # This is something I added in myself - it's not in the real gcc.SlackBuild # # Break these hard links: # rm -f $ARCH-slackware-linux-gcc gcc # ln -fs $ARCH-slackware-linux-gcc-$VERSION $ARCH-slackware-linux-gcc # ln -fs $ARCH-slackware-linux-gcc-$VERSION gcc # # g++ # rm -f g++ c++ $ARCH-slackware-linux-c++ # ln -fs $ARCH-slackware-linux-g++ g++ # ln -fs $ARCH-slackware-linux-g++ c++ # ln -fs $ARCH-slackware-linux-g++ $ARCH-slackware-linux-c++ ) ( cd $PKG1/usr/man/man1 ln -sf g++.1.gz c++.1.gz ln -sf gcc.1.gz cc.1.gz ) mkdir -p $PKG{1,2,3,4,5,6,7}/install # Install the descriptions: ( cd $CWD install -m644 slack-desc.gcc $PKG1/install/slack-desc install -m644 slack-desc.gcc-g++ $PKG2/install/slack-desc install -m644 slack-desc.gcc-gfortran $PKG3/install/slack-desc install -m644 slack-desc.gcc-gnat $PKG4/install/slack-desc install -m644 slack-desc.gcc-java $PKG5/install/slack-desc install -m644 slack-desc.gcc-objc $PKG6/install/slack-desc ) # OK, time to split the big package where needed: # 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 mkdir -p usr/lib mv $PKG1/usr/lib/*++* usr/lib mkdir -p usr/libexec/gcc/$TARGET/$VERSION mv $PKG1/usr/libexec/gcc/$TARGET/$VERSION/cc1plus usr/libexec/gcc/$TARGET/$VERSION/cc1plus mkdir -p usr/man/man1 mv $PKG1/usr/man/man1/*++* usr/man/man1 ) # gcc-gfortran: ( cd $PKG3 mkdir -p usr/bin mv $PKG1/usr/bin/*gfortran* usr/bin mv $PKG1/usr/bin/*95* usr/bin mv $PKG1/usr/bin/*77* usr/bin # Doesn't this seem like a logical idea? ( cd usr/bin ; ln -sf gfortran-gcc-${VERSION} fortran ) mkdir -p usr/info mv $PKG1/usr/info/gfortran* usr/info mkdir -p usr/lib mv $PKG1/usr/lib/libgfortran* usr/lib mkdir -p usr/libexec/gcc/$TARGET/$VERSION mv $PKG1/usr/libexec/gcc/$TARGET/$VERSION/f951 usr/libexec/gcc/$TARGET/$VERSION/f951 mkdir -p usr/man/man1 mv $PKG1/usr/man/man1/gfortran* usr/man/man1 ) # gcc-gnat: ( cd $PKG4 mkdir -p usr/bin mv $PKG1/usr/bin/gnat* usr/bin mv $PKG1/usr/bin/gpr* usr/bin mkdir -p usr/info mv $PKG1/usr/info/gnat* usr/info mkdir -p usr/share mv $PKG1/usr/share/gnat usr/share mkdir -p usr/libexec/gcc/$TARGET/$VERSION mv $PKG1/usr/libexec/gcc/$TARGET/$VERSION/gnat1 usr/libexec/gcc/$TARGET/$VERSION mkdir -p usr/lib/gcc/$TARGET/$VERSION mv $PKG1/usr/lib/gcc/$TARGET/$VERSION/adainclude usr/lib/gcc/$TARGET/$VERSION mv $PKG1/usr/lib/gcc/$TARGET/$VERSION/adalib usr/lib/gcc/$TARGET/$VERSION ) # gcc-java: ( cd $PKG5 mkdir -p usr/bin mv $PKG1/usr/bin/addr2name.awk usr/bin mv $PKG1/usr/bin/fastjar usr/bin mv $PKG1/usr/bin/*gcj* usr/bin mv $PKG1/usr/bin/gij usr/bin mv $PKG1/usr/bin/gjnih usr/bin mv $PKG1/usr/bin/grepjar usr/bin mv $PKG1/usr/bin/grmic usr/bin mv $PKG1/usr/bin/grmiregistry usr/bin mv $PKG1/usr/bin/jar usr/bin mv $PKG1/usr/bin/jcf-dump usr/bin mv $PKG1/usr/bin/jv-* usr/bin mv $PKG1/usr/bin/rmi* usr/bin mkdir -p usr/include mv $PKG1/usr/include/ffi.h usr/include mkdir -p usr/lib/gcc/$TARGET/$VERSION/include mv $PKG1/usr/lib/gcc/$TARGET/$VERSION/include/jawt.h usr/lib/gcc/$TARGET/$VERSION/include mv $PKG1/usr/lib/gcc/$TARGET/$VERSION/include/jawt_md.h usr/lib/gcc/$TARGET/$VERSION/include mv $PKG1/usr/lib/gcc/$TARGET/$VERSION/include/jni.h usr/lib/gcc/$TARGET/$VERSION/include mv $PKG1/usr/lib/gcc/$TARGET/$VERSION/include/jvmpi.h usr/lib/gcc/$TARGET/$VERSION/include mv $PKG1/usr/lib/gcc/$TARGET/$VERSION/include/libffi usr/lib/gcc/$TARGET/$VERSION/include mkdir -p usr/info mv $PKG1/usr/info/gcj.* usr/info mv $PKG1/usr/info/fastjar.* usr/info mkdir -p usr/lib mv $PKG1/usr/lib/libffi* usr/lib strip -g usr/lib/libffi.a mv $PKG1/usr/lib/gcj* usr/lib mv $PKG1/usr/lib/libgcj* usr/lib strip -g usr/lib/libgcj.a mv $PKG1/usr/lib/libgij* usr/lib strip -g usr/lib/libgij.a mv $PKG1/usr/lib/lib-org* usr/lib mv $PKG1/usr/lib/security usr/lib mkdir -p usr/lib/pkgconfig mv $PKG1/usr/lib/pkgconfig/libgcj.pc usr/lib/pkgconfig rmdir $PKG1/usr/lib/pkgconfig 2> /dev/null mkdir -p usr/libexec/gcc/$TARGET/$VERSION mv $PKG1/usr/libexec/gcc/$TARGET/$VERSION/jc1 usr/libexec/gcc/$TARGET/$VERSION mv $PKG1/usr/libexec/gcc/$TARGET/$VERSION/jvgenmain usr/libexec/gcc/$TARGET/$VERSION mkdir -p usr/lib/gcc/$TARGET/$VERSION/include mv $PKG1/usr/lib/gcc/$TARGET/$VERSION/include/gcj usr/lib/gcc/$TARGET/$VERSION/include mkdir -p usr/man/man1 mv $PKG1/usr/man/man1/fastjar.1.gz usr/man/man1 mv $PKG1/usr/man/man1/gcj.1.gz usr/man/man1 mv $PKG1/usr/man/man1/gcjh.1.gz usr/man/man1 mv $PKG1/usr/man/man1/gcj-dbtool.1.gz usr/man/man1 mv $PKG1/usr/man/man1/gij.1.gz usr/man/man1 mv $PKG1/usr/man/man1/gjnih.1.gz usr/man/man1 mv $PKG1/usr/man/man1/grmic.1.gz usr/man/man1 mv $PKG1/usr/man/man1/grmiregistry.1.gz usr/man/man1 mv $PKG1/usr/man/man1/jcf-dump.1.gz usr/man/man1 mv $PKG1/usr/man/man1/jv-convert.1.gz usr/man/man1 mv $PKG1/usr/man/man1/jv-scan.1.gz usr/man/man1 mkdir -p usr/share mv $PKG1/usr/share/java usr/share ) # gcc-objc: ( cd $PKG6 mkdir -p usr/lib mv $PKG1/usr/lib/libobjc* usr/lib mkdir -p usr/libexec/gcc/$TARGET/$VERSION mv $PKG1/usr/libexec/gcc/$TARGET/$VERSION/cc1obj usr/libexec/gcc/$TARGET/$VERSION mkdir -p usr/lib/gcc/$TARGET/$VERSION/include mv $PKG1/usr/lib/gcc/$TARGET/$VERSION/include/objc usr/lib/gcc/$TARGET/$VERSION/include ) ## NOTE: Thought about this, because the precompiled headers are so large. ## Probably easier to keep everything together, though. ## gcc-g++-gch (precompiled c++ headers) #( cd $PKG7 # mkdir -p usr/include/c++/$VERSION/$TARGET/bits # mv $PKG2/usr/include/c++/$VERSION/$TARGET/bits/stdc++.h.gch usr/include/c++/$VERSION/$TARGET/bits #) # Filter all .la files (thanks much to Mark Post for the sed script): ( cd $TMP for file in $( find . -type f -name "*.la" ) ; do sed -i 's%-L/gcc-[[:graph:]]* % %g' "$file" done ) # Start the fakeroot server: start_fakeroot # Delete old packages? if [ "${DELETEOLDPKGS}" = "Yes" ]; then rm -f $PKGSTORE/$PKGSERIES/gcc-*${VERSION}-* fi # Build packages: ( echo "Building gcc package" cd $PKG1 slackchown slack644docs makepkg -l y -c n $PKGSTORE/$PKGSERIES/gcc-$VERSION-$ARCH-$BUILD.tgz ) ( echo "Building g++ package" cd $PKG2 slackchown slack644docs makepkg -l y -c n $PKGSTORE/$PKGSERIES/gcc-g++-$VERSION-$ARCH-$BUILD.tgz ) ( cd $PKG3 slackchown slack644docs makepkg -l y -c n $PKGSTORE/$PKGSERIES/gcc-gfortran-$VERSION-$ARCH-$BUILD.tgz ) # Not for ARM: # ( cd $PKG4 # slackchown # slack644docs # makepkg -l y -c n $PKGSTORE/$PKGSERIES/gcc-gnat-$VERSION-$ARCH-$BUILD.tgz ) # ( cd $PKG5 # slackchown # slack644docs # makepkg -l y -c n $PKGSTORE/$PKGSERIES/gcc-java-$VERSION-$ARCH-$BUILD.tgz ) ( cd $PKG6 slackchown slack644docs makepkg -l y -c n $PKGSTORE/$PKGSERIES/gcc-objc-$VERSION-$ARCH-$BUILD.tgz ) #( cd $PKG7 # slackchown # slack644docs # makepkg -l y -c n $PKGSTORE/$PKGSERIES/gcc-g++-gch-$VERSION-$ARCH-$BUILD.tgz )