Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AlainODea/6680233 to your computer and use it in GitHub Desktop.
Save AlainODea/6680233 to your computer and use it in GitHub Desktop.
Partial setup of GHC Cross-compiler for Ubuntu to Illumos
From 05960e888726b961ebe9c00c439f5158a46c0532 Mon Sep 17 00:00:00 2001
From: Muhaimin Ahsan <[email protected]>
Date: Thu, 26 Sep 2013 16:33:59 -0500
Subject: [PATCH] Include termios.h for solaris2 host. (Fixes #8366)
---
System/Console/Haskeline/Backend/Posix.hsc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/System/Console/Haskeline/Backend/Posix.hsc b/System/Console/Haskeline/Backend/Posix.hsc
index a028629..8ed9067 100644
--- a/System/Console/Haskeline/Backend/Posix.hsc
+++ b/System/Console/Haskeline/Backend/Posix.hsc
@@ -48,7 +48,7 @@ import GHC.IOBase(haFD,FD)
import GHC.Handle (withHandle_)
#endif
-#if defined(USE_TERMIOS_H) || defined(__ANDROID__)
+#if defined(USE_TERMIOS_H) || defined(__ANDROID__) || defined(solaris2_HOST_OS)
#include <termios.h>
#endif
#include <sys/ioctl.h>
--
1.8.4
#!/bin/bash
export TARGET=x86_64-sun-solaris2.11
export PREFIX=$HOME/Documents/gcc/cross/$TARGET
export PATH=$PATH:$PREFIX/bin
export GCC=$PREFIX/bin/$TARGET-gcc
export LD=$PREFIX/bin/$TARGET-ld
export NM=$PREFIX/bin/$TARGET-nm
export OBJDUMP=$PREFIX/bin/$TARGET-objdump
cabal install happy alex haddock
sudo apt-get update
sudo apt-get install --assume-yes ghc libncurses5-dev \
mesa-common-dev freeglut3-dev libedit-dev
git clone git://github.com/ghc/ghc
pushd ghc
patch -d libraries/haskeline/ -p1 < \
../ghc-patches/0001-Include-termios.h-for-solaris2-host.-Fixes-8366.patch
cp $SYSROOT/opt/local/include/gmp.h libraries/integer-gmp/gmp/
cp mk/build.mk{.sample,}
echo "Stage1Only = YES" >> mk/build.mk
./sync-all --no-dph get
perl boot
./configure \
--host=x86_64-unknown-linux-gnu \
--build=x86_64-unknown-linux-gnu \
--target=x86_64-sun-solaris2 \
--with-gcc=$GCC \
--with-ld=$LD \
--with-nm=$NM \
--with-objdump=$OBJDUMP
#make -j $(nproc)
make
scp inplace/lib/bin/mkGmpDerivedConstants root@ns2:.
ssh root@ns2 "./mkGmpDerivedConstants" > \
libraries/integer-gmp/mkGmpDerivedConstants/dist/GmpDerivedConstants.h
make
popd
@AlainODea
Copy link
Author

Still can't get this to build. I get the following error from make -d:

checking whether /home/alain_odea/Documents/gcc/cross/x86_64-sun-solaris2.11/bin/x86_64-sun-solaris2.11-gcc is gcc... yes
checking compiler /home/alain_odea/Documents/gcc/cross/x86_64-sun-solaris2.11/bin/x86_64-sun-solaris2.11-gcc -m32 -O2 -pedantic -fomit-frame-pointer ... no, program does not run
checking compiler /home/alain_odea/Documents/gcc/cross/x86_64-sun-solaris2.11/bin/x86_64-sun-solaris2.11-gcc -O2 -pedantic -fomit-frame-pointer ... no, program does not run
configure: error: could not find a working compiler, see config.log for details

It seems like the autoconf script expects my cross-compiler to emit binaries my host can run which is not possible since it's a compiler targeted at Illumos.

@AlainODea
Copy link
Author

Okay export CFLAGS=-m64 gets past the issue. I had to rerun ./configure ... and then make. I'm running into this error now:

Warning: 'data-dir: ..' is a relative path outside of the source tree. This
will not work when generating a tarball with 'sdist'.
Reaping winning child 0x0229c820 PID 12952 
Removing child 0x0229c820 PID 12952 from chain.
 Considering target file `ghc/stage1/package-data.mk'.
 File `ghc/stage1/package-data.mk' was considered already.
Re-executing[2]: make -r --no-print-directory -f ghc.mk phase=0 phase_0_builds
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu
Reading makefiles...
Reading makefile `ghc.mk'...
ghc.mk:100: *** Make has restarted itself 2 times; is there a makefile bug? See http://hackage.haskell.org/trac/ghc/wiki/Building/Troubleshooting#Makehasrestarteditself3timesisthereamakefilebug for details.  Stop.
Reaping losing child 0x025f4120 PID 12619 
make: *** [all] Error 2
Removing child 0x025f4120 PID 12619 from chain.

@AlainODea
Copy link
Author

Removing -j $(nproc) fixes the restarting make issue. Build will likely take at least the halflife of cesium now.

@AlainODea
Copy link
Author

Configure mk/build.mk before perl boot. Otherwise it will do a default build.

@AlainODea
Copy link
Author

Create ghc-patches directory beside cross_ghc.sh and put 0001-Include-termios.h-for-solaris2-host.-Fixes-8366.patch in there.

@AlainODea
Copy link
Author

@AlainODea
Copy link
Author

Got past the mkGmpDerivedConstants failure by ignoring it, shipping the Solaris binary to a SmartOS box, running that, and restarting make. This is getting more Rube-Goldberg with every revision. A cleaner fix would be a Makefile patch that integrates an instance of the target system into the build process.

@AlainODea
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment