#!/bin/bash ulimit -s unlimited # llvm.SlackBuild # Heavily based on the original Slackware build scripts, # Modified by Stuart Winter for Slackware ARM. # # Copyright 2008-2015 Heinz Wiesinger, Amsterdam, The Netherlands # Copyright 2012, 2013, 2014, 2015 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. # Record toolchain & other info for the build log: slackbuildinfo # Paths to skeleton port's source & real Slackware source tree: export CWD=$SLACKSOURCE/$PKGSERIES/$PKGNAM export PORTCWD=$PWD # Temporary build locations: export TMPBUILD=$TMP/build-$PKGNAM export PKG=$TMP/package-$PKGNAM mkpkgdirs # Delete & re-create temporary directories then cd into $TMPBUILD # Use gold linker: mkdir -vpm755 $TMPBUILD/gold ln -vfs /usr/bin/ld.gold $TMPBUILD/gold/ld export PATH=$TMPBUILD/gold:$PATH # Add ARM specific configuration parameters: case $ARCH in arm) export ARCHCFLAGS="-with-arch=armv5te --with-float=soft --with-optimize-option=' -g -O2 -marm' --with-cloog --with-isl -with-clang-default-openmp-runtime=libomp" esac # Extract source: tar xvvf $CWD/$PKGNAM-$VERSION.src.tar.xz || exit 1 cd $PKGNAM-${VERSION}/tools || cd $PKGNAM-${VERSION}.src/tools || exit 1 tar xvf $CWD/cfe-$VERSION.src.tar.xz || exit 1 mv cfe-${VERSION} clang 2>/dev/null || mv cfe-${VERSION}.src clang || exit 1 cd ../ slackhousekeeping cd tools/clang/tools || exit 1 tar xvf $CWD/clang-tools-extra-$VERSION.src.tar.xz || exit 1 mv clang-tools-extra-${VERSION} extra 2>/dev/null \ || mv clang-tools-extra-${VERSION}.src extra || exit 1 cd ../../../ cd projects || exit 1 tar xvf $CWD/compiler-rt-$VERSION.src.tar.xz || exit 1 mv compiler-rt-${VERSION} compiler-rt 2>/dev/null \ || mv compiler-rt-${VERSION}.src compiler-rt || exit 1 cd ../ pushd $TMPBUILD slackhousekeeping popd # Support GCC built for i586-slackware-linux: echo "Applying toolchain patch.." zcat $CWD/clang.toolchains.i586.triple.diff.gz | patch -p1 --verbose || exit 1 # Use i586 $ARCH on 32-bit x86: sed -r "/ifeq.*CompilerTargetArch/s#i386#i586#g" \ -i projects/compiler-rt/make/platform/clang_linux.mk # Allow an in-tree build. sed -i 's?if test ${srcdir} = "." ; then?if test ${srcdir} = "slkDUMMY" ; then?g' configure zcat $PORTCWD/sources/llvm.Makefile.config.in.diff.gz | patch -p1 --verbose || exit 1 # ARM patches: pushd tools tar xvvf $PORTCWD/sources/llvm-toolchain*z || exit 1 for pf in \ 26-set-correct-float-abi.diff \ atomic_library_1.diff \ atomic_library_2.diff \ removeduplicatedeclaration.diff \ ; do # auto_apply_patch debian/patches/$pf || echo "$pf FAILED" >> /tmp/FailEd auto_apply_patch debian/patches/$pf || exit 1 done popd # --mandir doesn't work currently # need to disable assertions to make llvm thread-safe # clang resource dir is a relative path based on the location of the clang binary # Configure: #COLLECT_GCC=gcc \ #COLLECT_LTO_WRAPPER=/usr/libexec/gcc/arm-slackware-linux-gnueabi/*/lto-wrapper \ #CFLAGS="$SLKCFLAGS" \ #CXXFLAGS="$SLKCFLAGS" \ ./configure \ $ARCHCONFARGS \ --prefix=/usr \ --libdir=/usr/lib$LIBDIRSUFFIX \ --sysconfdir=/etc \ --localstatedir=/var \ --mandir=/usr/man \ --enable-optimized \ --enable-shared \ --disable-assertions \ --enable-libffi \ --with-binutils-include=/usr/include \ --enable-pic \ --with-clang-resource-dir="../lib${LIBDIRSUFFIX}/clang/${VERSION}" \ --build=$ARCH-slackware-linux-gnueabi || failconfig # compiler-rt uses the clang binary we're about to build so # we need to be able to execute it from within the build tree. sed -i "s|\$(BuildMode)/lib|\$(BuildMode)/lib$LIBDIRSUFFIX|" \ Makefile.rules tools/clang/runtime/compiler-rt/Makefile \ tools/clang/lib/Headers/Makefile sed -i "s|\.\./lib|\.\./lib$LIBDIRSUFFIX|" \ Makefile.rules # Fix hardcoded libdir sed -i "s|\$(PROJ_prefix)/lib|\$(PROJ_prefix)/lib$LIBDIRSUFFIX|" \ Makefile.config tools/clang/lib/Headers/Makefile \ tools/clang/runtime/compiler-rt/Makefile sed -i "s|\"lib\"|\"lib${LIBDIRSUFFIX}\"|" \ tools/clang/lib/Frontend/CompilerInvocation.cpp sed -i "s|/lib/LLVMgold.so|/lib${LIBDIRSUFFIX}/LLVMgold.so|" \ tools/clang/lib/Driver/Tools.cpp sed -i "s|ActiveLibDir = ActivePrefix + \"/lib\"|ActiveLibDir = ActivePrefix + \"/lib${LIBDIRSUFFIX}\"|g" \ tools/llvm-config/llvm-config.cpp # Build: make $NUMJOBS VERBOSE=1 || make VERBOSE=1 || failmake # Install into package framework: make install DESTDIR=$PKG || failinstall # Fix strange permissions chmod 755 $PKG/usr/lib$LIBDIRSUFFIX/clang-analyzer/scan-build chmod 755 $PKG/usr/lib$LIBDIRSUFFIX/clang-analyzer/scan-view chmod 755 $PKG/usr/lib$LIBDIRSUFFIX/clang-analyzer/scan-view/Resources # Add symlinks for $ARCH-slackware-linux-{clang,clang++}: ( cd $PKG/usr/bin ln -vsf clang $ARCH-slackware-linux-clang ln -vsf clang++ $ARCH-slackware-linux-clang++ ) # Install clang-static-analyzer mkdir -p $PKG/usr/lib$LIBDIRSUFFIX/clang-analyzer cp -pr tools/clang/tools/scan-{build,view} \ $PKG/usr/lib$LIBDIRSUFFIX/clang-analyzer/ || exit 1 for i in scan-{build,view}; do ln -vfs /usr/lib$LIBDIRSUFFIX/clang-analyzer/$i/$i \ $PKG/usr/bin/$i || exit 1 done for i in ccc c++; do ln -vfs /usr/lib$LIBDIRSUFFIX/clang-analyzer/scan-build/$i-analyzer \ $PKG/usr/bin/$i-analyzer || exit 1 done # Fix paths in scan-build sed -i "s|\$RealBin/bin|/usr/bin|" \ $PKG/usr/lib$LIBDIRSUFFIX/clang-analyzer/scan-build/scan-build sed -i "s|\$RealBin/sorttable.js|/usr/lib${LIBDIRSUFFIX}/clang-analyzer/scan-build/sorttable.js|" \ $PKG/usr/lib$LIBDIRSUFFIX/clang-analyzer/scan-build/scan-build sed -i "s|\$RealBin/scanview.css|/usr/lib${LIBDIRSUFFIX}/clang-analyzer/scan-build/scanview.css|" \ $PKG/usr/lib$LIBDIRSUFFIX/clang-analyzer/scan-build/scan-build # Move man page directory: mv $PKG/usr/share/man $PKG/usr/ # Move scan-build man-page into place mkdir -p $PKG/usr/man/man1 mv -fv $PKG/usr/lib$LIBDIRSUFFIX/clang-analyzer/scan-build/scan-build.1 \ $PKG/usr/man/man1/ # Copy docs: mkdir -p $PKG/usr/doc/$PKGNAM-$VERSION/clang cp -a CREDITS* LICENSE* README* $PKG/usr/doc/$PKGNAM-$VERSION cp -a tools/clang/{INSTALL,LICENSE,NOTES,README}* \ $PKG/usr/doc/$PKGNAM-$VERSION/clang mv $PKG/usr/docs/llvm/* $PKG/usr/doc/$PKGNAM-$VERSION rm -rf $PKG/usr/docs # If necessary, start the fakeroot server so we can set file/dir ownerships: start_fakeroot # Apply generic Slackware packaging policies: cd $PKG slackstripall # strip all .a archives and all ELFs slackgzpages -i # compress man & info pages and delete usr/info/dir slackslack # chown -R root:root, chmod -R og-w, slackchown, slack644docs slackdesc # install slack-desc and doinst.sh slackmp # run makepkg -l y -c n # Perform any final checks on the package: cd $PKG slackhlinks # search for any hard links