# Mostly self contained setup to build a stage2 ghc for musl from debian:8.0 # Install stock bindist for cross compile env ghc 8.0.2 env arch x86_64 env llvm 3.7.1 env cabal 1.24.0.2 env destarch x86_64 env tardir /tmp/root env destdir /tmp/root/$destarch env triple ${arch}-pc-linux-musl env target ${arch}-pc-linux-musl env crosscc $triple-gcc # add cross toolchain to PATH env PATH /usr/$triple/bin:$PATH # all needed packages for compiling run apt-get clean && \ apt-get update && \ apt-get install -y \ binutils-gold \ musl-tools \ build-essential \ wget \ curl \ libncurses-dev \ autoconf \ elfutils \ libgmp-dev \ zlib1g-dev \ git \ libtool \ pkg-config \ libffi-dev \ cmake \ g++ \ python \ pixz \ openssl \ bison \ git \ flex add http://llvm.org/releases/$llvm/llvm-$llvm.src.tar.xz /tmp/ add http://llvm.org/releases/$llvm/polly-$llvm.src.tar.xz /tmp/ # Install a non ancient version of llvm on debian, I'm purposefully ignoring # debian repos in favor of compiling to not have to deal with # "what debian upstream has a current version of llvm" nonsense, takes more # time to do that than just build the right llvm from source. workdir /tmp copy llvm-$llvm.sh /tmp/llvm.sh run openssl sha1 llvm-$llvm.src.tar.xz | grep "SHA1(llvm-3.7.1.src.tar.xz)= 5dbdcafac105273dcbff94c68837a66c6dd78cef" && \ openssl sha1 polly-$llvm.src.tar.xz | grep "SHA1(polly-3.7.1.src.tar.xz)= 0e3a461907cde7505fbdb44bf61ff318aa9254f7" && \ tar xJpf /tmp/llvm-$llvm.src.tar.xz && \ tar xJpf /tmp/polly-$llvm.src.tar.xz && \ /tmp/llvm.sh && \ rm -fr /tmp/llvm-$llvm.src /tmp/build add https://downloads.haskell.org/~ghc/$ghc/ghc-$ghc-$arch-deb8-linux.tar.xz /tmp/ # Install debian ghc binary from upstream. workdir /tmp run openssl sha1 ghc-$ghc-$arch-deb8-linux.tar.xz | grep "SHA1(ghc-$ghc-x86_64-deb8-linux.tar.xz)= f298b7d0f37cc9ded7ac66b2662b0fa5ac6d0809" && \ tar xJpf /tmp/ghc-$ghc-$arch-deb8-linux.tar.xz workdir /tmp/ghc-$ghc run ./configure --prefix=/usr && \ make -j1 install && \ rm -fr /tmp/ghc-$ghc run curl -kL https://www.haskell.org/cabal/release/cabal-install-$cabal/cabal-install-$cabal.tar.gz -o /tmp/cabal-install-$cabal.tar.gz # Install cabal so we can install alex/happy to pull off of git # bootstrap cabal and install alex/happy the same way apks are built # only globally workdir /tmp run openssl sha1 cabal-install-$cabal.tar.gz | grep "SHA1(cabal-install-$cabal.tar.gz)= ca019360c45be32e224b6582ab46b420fb070417" && \ tar xzpf /tmp/cabal-install-$cabal.tar.gz workdir /tmp/cabal-install-$cabal run ./bootstrap.sh --global --no-doc && \ cabal update && \ cabal install --global alex happy && \ rm -fr /tmp/cabal-install-$cabal workdir /tmp run git clone --depth 1 https://github.com/GregorR/musl-cross.git musl-cross workdir /tmp/musl-cross run echo GCC_BUILTIN_PREREQS=yes >> config.sh && \ echo TRIPLE=${triple} >> config.sh && \ echo ARCH=${destarch} >> config.sh && \ echo GCC_STAGE1_NOOPT=1 >> config.sh && \ echo CC_BASE_PREFIX=/usr >> config.sh && \ echo MAKEFLAGS=-j$(grep -c processor /proc/cpuinfo) >> config.sh && \ echo "BINUTILS_CONFFLAGS='CXXFLAGS=-fpermissive --enable-gold --enable-plugins --disable-werror'" >> config.sh && \ echo "CFLAGS='-g -O3 -fno-pie -fno-pic'" >> config.sh copy gmpurl.patch gmpurl.patch run patch -p1 < gmpurl.patch && \ ./build.sh && \ rm -fr /tmp/musl-cross add http://downloads.haskell.org/~ghc/$ghc/ghc-$ghc-src.tar.xz /tmp/ workdir /tmp run openssl sha1 ghc-$ghc-src.tar.xz | grep "SHA1(ghc-$ghc-src.tar.xz)= 0e0ae6d5ba119c10f3c7b807d35166e7c06b9b35" && \ tar xJpf /tmp/ghc-$ghc-src.tar.xz workdir /tmp/ghc-$ghc copy bootstrap.patch bootstrap.patch copy rm-ghc-pwd.patch rm-ghc-pwd.patch copy build-unlit-twice.patch build-unlit-twice.patch copy build-hp2ps-twice.patch build-hp2ps-twice.patch run patch -p1 < bootstrap.patch && \ patch -p1 < rm-ghc-pwd.patch && \ patch -p1 < build-unlit-twice.patch && \ patch -p1 < build-hp2ps-twice.patch run cp mk/build.mk.sample mk/build.mk && \ ./boot && \ echo "BuildFlavour = perf-llvm" >> mk/build.mk && \ echo "BeConservative = YES" >> mk/build.mk && \ echo "INTEGER_LIBRARY = integer-simple" >> mk/build.mk && \ echo "HADDOCK_DOCS = NO" >> mk/build.mk && \ echo "BUILD_SPHINX_HTML = NO" >> mk/build.mk && \ echo "BUILD_SPHINX_PS = NO" >> mk/build.mk && \ echo "BUILD_SPHINX_PDF = NO" >> mk/build.mk && \ echo "SplitSections = YES" >> mk/build.mk && \ echo "V = 0" >> mk/build.mk && \ echo "SPLIT_CMD = :" >> mk/build.mk && \ ./configure \ --target=$triple \ --prefix=/usr run make -j$(grep -c processor /proc/cpuinfo) || make -j1 run make -j1 install DESTDIR=$destdir # remove target prefix from stage2 binaries workdir $destdir/usr/bin run (for i in $triple-* ; do ln -s $i ${i#$triple-} || /bin/true; done ) && \ rm -fr $destdir/usr/share/doc workdir $tardir # Compress to xz via pixz because xz is normally too # old for -TN multithreads run tar -I'pixz -9' -cf /tmp/ghc-$ghc-$destarch.tar.xz .