Created
September 6, 2015 17:37
-
-
Save piotrMocz/186682c16d09ed63b31a to your computer and use it in GitHub Desktop.
Install ghc on ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Disclaimer: work-in-progress-kind-of-thing, really more of a dockerfile-became-shellscript | |
# Installs emulated arm ghc on amd64 box | |
# It assumes you're running Ubuntu 14.04 (Trusty) | |
# Oh btw -- run with sudo | |
# from Alexey Raga's dockerfile (to stop apt from asking you for a "yes"): | |
export DEBIAN_FRONTEND=noninteractive | |
export OPTS_APT="-y --force-yes --no-install-recommends" | |
apt-get update | |
#apt-get install $OPTS_APT curl | |
#echo insecure >> ~/.curlrc | |
apt-get install $OPTS_APT wget | |
wget --no-check-certificate "sources.list" "https://gist.githubusercontent.com/piotrMocz/580649306537d58d78b2/raw/81cf358db18e50dc31824e54da5e92af48a3d18a/sources.list" | |
# enable qemu user emulation (in order to transparently run arm binaries): | |
apt-get install $OPTS_APT qemu binfmt-support qemu-user-static | |
# enable armhf | |
cp sources.list /etc/apt/sources.list | |
dpkg --add-architecture armhf | |
apt-get update | |
apt-get install $OPTS_APT gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf build-essential | |
# basic sets of libraries required by ghc (both amd64 and arm): | |
apt-get install $OPTS_APT zlib1g zlib1g-dev libncurses5 libncurses5-dev libgmp10 libgmp10-dev | |
apt-get install $OPTS_APT zlib1g:armhf zlib1g-dev:armhf libncurses5:armhf libncurses5-dev:armhf libgmp10:armhf libgmp10-dev:armhf | |
# install amd64 ghc (to compile arm ghc) | |
wget https://www.haskell.org/ghc/dist/7.8.4/ghc-7.8.4-x86_64-unknown-linux-deb7.tar.xz \ | |
&& tar xf ghc-7.8.4-x86_64-unknown-linux-deb7.tar.xz \ | |
&& rm ghc-7.8.4-x86_64-unknown-linux-deb7.tar.xz \ | |
&& mkdir /opt/ghc \ | |
&& cd ghc-7.8.4 && ./configure --prefix=/opt/ghc && make install \ | |
&& cd .. && rm -rf ghc-7.8.4 | |
export PATH=/opt/ghc/bin:$PATH | |
# install cabal | |
wget http://hackage.haskell.org/package/cabal-install-1.22.6.0/cabal-install-1.22.6.0.tar.gz \ | |
&& tar xf cabal-install-1.22.6.0.tar.gz \ | |
&& rm cabal-install-1.22.6.0.tar.gz \ | |
&& cd cabal-install-1.22.6.0 && ./bootstrap.sh | |
export PATH=$HOME/.cabal/bin:$PATH | |
cd .. \ | |
&& cabal update | |
&& cabal install alex happy | |
# upgrade dist so that LLVM has GLIBCXX version that it wants | |
apt-get install $OPTS_APT software-properties-common | |
add-apt-repository ppa:ubuntu-toolchain-r/test | |
apt-get update | |
apt-get $OPTS_APT upgrade | |
apt-get $OPTS_APT dist-upgrade | |
# install LLVM 3.5.1 (arm-ghc had some doubts about 3.5.0 that's available from ubuntu repos) | |
wget http://llvm.org/releases/3.5.1/clang+llvm-3.5.1-x86_64-linux-gnu.tar.xz \ | |
&& tar xf clang+llvm-3.5.1-x86_64-linux-gnu.tar.xz \ | |
&& rm clang+llvm-3.5.1-x86_64-linux-gnu.tar.xz \ | |
&& mv clang+llvm-3.5.1-x86_64-linux-gnu llvm \ | |
export PATH=$HOME/llvm:$PATH | |
# build a cross-compiler, which in turn will build arm ghc | |
wget https://www.haskell.org/ghc/dist/7.8.4/ghc-7.8.4-src.tar.bz2 \ | |
&& tar xf ghc-7.8.4-src.tar.bz2 \ | |
&& rm *.tar.bz2 \ | |
&& cd ghc-7.8.4 \ | |
&& mkdir /opt/ghc-cross-7.8.4 \ # again from Alexey: change build flavour to Quick Cross | |
&& sed -i 's/^PACKAGES_STAGE1 += terminfo$/\#\0/g' ghc.mk \ | |
&& sed -i 's/^PACKAGES_STAGE1 += haskeline$/\#\0/g' ghc.mk \ | |
&& cp mk/build.mk.sample mk/build.mk \ | |
&& sed -i 's/^#\(BuildFlavour *= *quick-cross\)$/\1/g' mk/build.mk \ | |
&& ./configure --target=arm-linux-gnueabihf --with-gcc=arm-linux-gnueabihf-gcc --prefix=/opt/ghc-cross-7.8.4 --enable-unregisterised \ | |
&& make && make install | |
# in case it doesn't work with your llvm add under the seds above ;) | |
# && sed -i 's/^SRC_HC_OPTS *= .*$/SRC_HC_OPTS = -O -H64m/g' mk/build.mk \ | |
# && sed -i 's/^GhcStage1HcOpts *= .*$/GhcStage1HcOpts = -O -fasm/g' mk/build.mk \ | |
# && sed -i 's/^GhcStage2HcOpts *= .*$/GhcStage2HcOpts = -O2 -fasm/g' mk/build.mk \ | |
# && sed -i 's/^GhcLibHcOpts *= .*$/GhcLibHcOpts = -O2/g' mk/build.mk \ | |
# install arm ghc: | |
wget https://www.haskell.org/ghc/dist/7.8.4/ghc-7.8.4-src.tar.xz \ | |
&& tar xf ghc-7.8.4-src.tar.xz \ | |
&& rm *.tar.xz \ | |
&& mkdir /opt/armghc \ | |
&& ./configure \ | |
&& mv /usr/bin/strip /usr/bin/amd64-strip \ # saddly we have to symlink to an arm strip because ghc's configure doesn't have the "with-strip" option | |
&& ln -s /usr/bin/arm-linux-gnueabihf-strip /usr/bin/strip \ | |
&& cd ghc-7.8.4 \ | |
&& ./configure --target=arm-linux-gnueabihf --prefix=/opt/armghc \ | |
--with-ghc=/opt/ghc-cross-7.8.4/bin/arm-unknown-linux-gnueabihf-ghc \ | |
--with-ghc-pkg=/opt/ghc-cross-7.8.4/bin/arm-unknown-linux-gnueabihf-ghc-pkg \ | |
--with-gcc=arm-linux-gnueabihf-gcc --with-ld=arm-linux-gnueabihf-ld.gold \ | |
&& make && make install \ | |
&& cd .. && rm -rf ghc-7.8.4 | |
cd $HOME | |
echo "alias armcabal_install=\"cabal install --with-ghc=arm-unknown-linux-gnueabihf-ghc --with-ld=arm-linux-gnueabihf-ld --with-ghc-pkg=arm-unknown-linux-gnueabihf-ghc-pkg --hsc2hs-option=-x\"" >> .bashrc | |
echo "export PATH=$HOME/llvm/bin:/opt/ghc:$HOME/.cabal/bin:$PATH" >> .bashrc | |
# yay, we're done! | |
echo "Finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment