#!/bin/bash # libgccjit Slackware package build script # I have derived this script from the GCC build script written by volkerdi@slackware.com and # modified by others. For this reason I keep as-is below the copyright notice of the GCC build # script and the following notes - Didier Spaier # Copyright 2003, 2004 Slackware Linux, Inc., Concord, California, USA # Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2021 Patrick J. Volkerding, Sebeka, MN, 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 2011 by Eric Hameleers for OpenJDK. # Some notes, Fri May 16 12:31:32 PDT 2003: # # Why i486 and not i386? Because the shared C++ libraries in gcc-3.2.x will # require 486 opcodes even when a 386 target is used (so we already weren't # compatible with the i386 for Slackware 9.0, didn't notice, and nobody # complained :-). gcc-3.3 fixes this issue and allows you to build a 386 # compiler, but the fix is done in a way that produces binaries that are not # compatible with gcc-3.2.x compiled binaries. To retain compatibility with # Slackware 9.0, we'll have to use i486 (or better) as the compiler target # for gcc-3.3. # # It's time to say goodbye to i386 support in Slackware. I've surveyed 386 # usage online, and the most common thing I see people say when someone asks # about running Linux on a 386 is to "run Slackware", but then they also # usually go on to say "be sure to get an OLD version, like 4.0, before glibc, # because it'll be more efficient." Now, if that's the general advice, then # I see no reason to continue 386 support in the latest Slackware (and indeed # it's no longer easily possible). # Some more notes, Mon Aug 3 19:49:51 UTC 2015: # # Changing to -march=i586 for 32-bit x86 as several things (Mesa being one of # them) no longer work if constrained to -march=i486. We're not going to use # -march=i686 since the only additional opcode is CMOV, which is actually less # efficient on modern CPUs running in 32-bit mode than the alternate i586 # instructions. No need to throw i586 CPUs under the bus (yet). cd $(dirname $0) ; CWD=$(pwd) PKGNAM=libgccjit SRCNAM=gcc SRCVER=${VERSION:-$(echo $SRCNAM-*.tar.?z | rev | cut -f 3- -d . | cut -f 1 -d - | rev)} VERSION=$(echo $SRCVER | cut -f 1 -d _) BUILD=2slint # How many jobs to run in parallel: NUMJOBS=${NUMJOBS:-" -j$(expr $(nproc) + 1) "} # Automatically determine the architecture we're building on: if [ -z "$ARCH" ]; then case "$(uname -m)" in i?86) ARCH=i586 ;; arm*) readelf /usr/bin/file -A | egrep -q "Tag_CPU.*[4,5]" && ARCH=arm || ARCH=armv7hl ;; # Unless $ARCH is already set, use uname -m for all other archs: *) ARCH=$(uname -m) ;; esac export ARCH fi # If the variable PRINT_PACKAGE_NAME is set, then this script will report what # the name of the created package would be, and then exit. This information # could be useful to other scripts. if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then echo "$PKGNAM-$VERSION-$ARCH-$BUILD.txz" exit 0 fi if [ "$ARCH" = "i386" ]; then SLKCFLAGS="-O2 -march=i386 -mcpu=i686" LIBDIRSUFFIX="" LIB_ARCH=i386 elif [ "$ARCH" = "i486" ]; then SLKCFLAGS="-O2 -march=i486 -mtune=i686" LIBDIRSUFFIX="" LIB_ARCH=i386 elif [ "$ARCH" = "i586" ]; then SLKCFLAGS="-O2 -march=i586 -mtune=i686" LIBDIRSUFFIX="" LIB_ARCH=i386 elif [ "$ARCH" = "i686" ]; then SLKCFLAGS="-O2 -march=i686" LIBDIRSUFFIX="" LIB_ARCH=i386 elif [ "$ARCH" = "s390" ]; then SLKCFLAGS="-O2" LIBDIRSUFFIX="" LIB_ARCH=s390 elif [ "$ARCH" = "x86_64" ]; then SLKCFLAGS="-O2 -fPIC" LIBDIRSUFFIX="64" LIB_ARCH=amd64 elif [ "$ARCH" = "armv7hl" ]; then SLKCFLAGS="-O3 -march=armv7-a -mfpu=vfpv3-d16" LIBDIRSUFFIX="" LIB_ARCH=armv7hl else SLKCFLAGS="-O2" LIBDIRSUFFIX="" LIB_ARCH=$ARCH fi case "$ARCH" in arm*) TARGET=$ARCH-slackware-linux-gnueabi ;; *) TARGET=$ARCH-slackware-linux ;; esac # Temporary build location (this what I use for Slint, edit that as you see fit - Didier) : TMP=$CWD # Extract the source code: cd $TMP rm -rf gcc-$SRCVER tar xf $CWD/gcc-$SRCVER.tar.?z || exit 1 # This is the main DESTDIR target: PKG=$TMP/package-libgccjit # Clear the build locations: rm -rf $PKG mkdir $PKG cd gcc-$SRCVER || exit 1 # Smite the fixincludes: zcat $CWD/patches/gcc-no_fixincludes.diff.gz | patch -p1 --verbose --backup --suffix=.orig || exit 1 # Fix a gfortran bug: zcat $CWD/patches/gfortran.deferred-shape-vs-assumed-shape.patch.gz | patch -p0 --verbose --backup --suffix=.orig || exit 1 # Fix regressions in 10.3.0 (and presumably 11.1.0 since they still apply cleanly): zcat $CWD/patches/PR100102-2.a1b3484a8e6c53c8084723e3f1738d402374198e.patch.gz | patch -p1 --verbose --backup --suffix=.orig || exit 1 # Fix compiler error in gcc-go # https://github.com/golang/go/issues/47771 zcat $CWD/patches/7185690.diff.gz | patch -p1 --verbose --backup --suffix=.orig || exit 1 # Fix perms/owners: chown -R root:root . find . \ \( -perm 777 -o -perm 775 -o -perm 754 \) \ -exec chmod 755 {} \+ -o \ \( -perm 664 \) \ -exec chmod 644 {} \+ # Install slack-desc and docs: mkdir -p $PKG/install mkdir -p $PKG/usr/doc/$PKGNAM-$VERSION $PKG/install cp -a \ COPYING* gcc/ONEWS README INSTALL LAST_UPDATED \ $PKG/usr/doc/$PKGNAM-$VERSION cp $CWD/slack-desc $PKG/install/ mkdir gcc.build.lnx cd gcc.build.lnx # I think it's incorrect to include this option (as it'll end up set # to i586 on x86 platforms), and we want to tune the binary structure # for i686, as that's where almost all of the optimization speedups # are to be found. # Correct me if my take on this is wrong. # --with-cpu=$ARCH if [ "$ARCH" != "x86_64" ]; then GCC_ARCHOPTS="--with-arch=$ARCH" else GCC_ARCHOPTS="--disable-multilib" fi CFLAGS="$SLKCFLAGS" \ CXXFLAGS="$SLKCFLAGS" \ ../configure --prefix=/usr \ --libdir=/usr/lib$LIBDIRSUFFIX \ --mandir=/usr/man \ --infodir=/usr/info \ --enable-shared \ --enable-host-shared \ --enable-bootstrap \ --enable-languages=jit \ --enable-threads=posix \ --enable-checking=release \ --enable-objc-gc \ --with-system-zlib \ --enable-libstdcxx-dual-abi \ --with-default-libstdcxx-abi=new \ --disable-libstdcxx-pch \ --disable-libunwind-exceptions \ --enable-__cxa_atexit \ --disable-libssp \ --enable-gnu-unique-object \ --enable-plugin \ --enable-lto \ --disable-install-libiberty \ --disable-werror \ --with-gnu-ld \ --with-isl \ --verbose \ --with-arch-directory=$LIB_ARCH \ --disable-gtktest \ --enable-clocale=gnu \ $GCC_ARCHOPTS \ --target=${TARGET} \ --build=${TARGET} \ --host=${TARGET} || exit 1 make $NUMJOBS bootstrap || exit 1 make -C gcc DESTDIR="$PKG" jit.install-common jit.install-info find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \ | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true ( cd $PKG rm -rf usr/bin usrlib64/gcc usr/libexec usr/man usr/info/dir ( cd usr/info gzip -9 * ) makepkg -l y -c n $TMP/libgccjit-$VERSION-$ARCH-$BUILD.txz ) echo echo "Package $PKGNAM complete!" echo