public
Created

This wrapper script *should* enable GHC 7.* to work on systems with Xcode 5. To use it, drop this script somewhere, make it executable, and run.... Then follow the instructions it prints out. What it will do is, instruction you to put a copy in /usr/bin, then re-run it sudo. It will then find all your GHC 7 settings files, and patch them to make this wrapper the C compiler. The wrapper notices if your system has clang installed as gcc (which is what Xcode 5 does), and if so, adjusts the command line arguments to make GHC work with it. Let me know how it goes!

  • Download Gist
ghc-clang-wrapper
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
#!/bin/sh
 
inPreprocessorMode () {
hasE=0
hasU=0
hasT=0
for arg in "$@"
do
if [ 'x-E' = "x$arg" ]; then hasE=1; fi
if [ 'x-undef' = "x$arg" ]; then hasU=1; fi
if [ 'x-traditional' = "x$arg" ]; then hasT=1; fi
done
[ "$hasE$hasU$hasT" = '111' ]
}
 
gccIsClang () {
gcc --version 2>/dev/null | grep -q clang
}
 
extraClangArgs="-Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs"
 
adjustPreprocessorLanguage () {
newArgs=''
while [ $# -gt 0 ]
do
newArgs="$newArgs $1"
if [ "$1" = '-x' ]
then
shift
if [ $# -gt 0 ]
then
if [ "$1" = 'c' ]
then
newArgs="$newArgs assembler-with-cpp"
else
newArgs="$newArgs $1"
fi
fi
fi
shift
done
echo $newArgs
}
 
installThisScript () {
if [ \! -x /usr/bin/ghc-clang-wrapper ]
then
echo "Copy this execute script to /usr/bin/ghc-clang-wrapper, then re-run it."
echo "You can copy it with these commands:"
echo
echo sudo cp $0 /usr/bin/ghc-clang-wrapper
echo sudo chmod 755 /usr/bin/ghc-clang-wrapper
echo sudo ghc-clang-wrapper
exit 1
fi
 
settings=`ls -1 /Library/Frameworks/GHC.framework/Versions/7*/usr/lib/ghc-7*/settings 2>/dev/null`
 
if [ "$settings" = '' ]
then
echo "You don't seem to have Haskell Platform installed."
echo "Visit http://www.haskell.org/platform/ to get and install it."
echo "Then run this script again."
echo
echo "If you have GHC installed in a non-standard place, find the file"
echo "named 'settings', that is alongside the compiler, and edit the"
echo "c compiler line to read:"
echo ' ("C compiler command", "/usr/bin/ghc-clang-wrapper"),'
exit 1
fi
 
anyNeedPatching=0
for sfile in $settings
do
if grep -q ghc-clang-wrapper $sfile
then
echo ALREADY PATCHED: $sfile
else
if [ `id -u` -eq 0 ]
then
sed -e '/C compiler command/s:"[^ ]*gcc":"/usr/bin/ghc-clang-wrapper":' -i '.bak' $sfile
echo PATCHED: $sfile
else
echo WOULD PATCH: $sfile
anyNeedPatching=1
fi
fi
done
 
if [ $anyNeedPatching -eq 1 ]
then
echo "Please run this script sudo to actually patch GHC:"
echo sudo $0
fi
}
 
if [ $# -eq 0 ]
then
installThisScript
else
if gccIsClang
then
if inPreprocessorMode "$@"
then
exec gcc $extraClangArgs `adjustPreprocessorLanguage "$@"`
else
exec gcc $extraClangArgs "$@"
fi
else
exec gcc "$@"
fi
fi

Used the wrapper and tried cleaning things up a little (deleted .cabal, .ghc, cabal update). I'm still getting code loading errors - does that seem related?

/Users/schell/Library/Haskell/ghc-7.6.3/lib/bindings-GLFW-3.0.3.1/lib/HSbindings-GLFW-3.0.3.1.o: unknown symbol `__objc_empty_vtable'

WHY IS THERE A SUDO.

and this seems to not work if the user used a bin-dist ghc install.

  1. There is a sudo because the settings file is owned by root.
  2. It doesn't work from a bin-dist as we don't know where the user ended up putting ghc. The script discovers this and gives instructions. If they used GHC Mac installer, it will work, as it is in the same place.

schell: You shouldn't have had to delete .cabal & .ghc -- those aren't affected by the Xcode changes.

The build error you are seeing is a problem with bindings-GLFW - which references the Objective-C run-time symbol __objc_empty_vtable. That symbol changed significantly in 10.9, which causes the error. They seem to know about this issue in the bindings-GLFW repo, and have a fix in head.

it works great, thanks!

mzero: Got it, thanks. I read that ghc 7.7+ (HEAD) will build and link bindings-GLFW fine, so in my quest to build GLFW-b I'm trying to build ghc HEAD. I'm naively using your wrapper to configure the build but am getting a nasty error, I think it might be related to any of the 3(?) issue that are keeping the new haskell platform from releasing. Here's the build output: http://lpaste.net/95206

I installed the wrapper. I have deleted my .cabal and .ghc directories. I first ran cabal update, then cabal install cabal-install. This worked but I don't seem to be able to install other packages:

$ cabal install hashtables
Resolving dependencies...
Configuring hashtables-1.1.2.1...
Failed to install hashtables-1.1.2.1
Last 10 lines of the build log ( /Users/james/.cabal/logs/hashtables-1.1.2.1.log ):
cabal: Error: some packages failed to install:
hashtables-1.1.2.1 failed during the configure step. The exception was:
ExitFailure 10

The log file is empty.

A bit later, having not changed anything I can think of, running 'cabal install hashtables' yields 'Bus error: 10'.

In case feedback is still useful, this script doesn't notice ghc that is installed via stow. (It did patch my existing binary HP one with ghc 7.4.1 though)

I guess I should note that when I upgraded to Mavericks, ghc still seemed to work anyway, but I'm not really following the issue closely enough to know if something broke.

On my system, the builtin echo on line 42 eats up the leading -E. Replacing with /bin/echo fixes that. Yay shell!

Also, clang complains incessantly about the -nodefaultlibs flag, I stripped that out with "${@/-nodefaultlibs/}".

Hi,

I think currently the script does not escape spaces properly. I've stumbled upon this problem when I was trying to build darcs with this wrapper: http://bugs.darcs.net/issue2355?

The -DPACKAGE_VERSION_STATE="+1 patch" parameter for GHC behaves weirdly and results in build failure as shown in the log: http://pastebin.com/zVK2GkRz

@elaforge Could you post a gist with your fix for -nodefaultlibs?

I've fixed the -nodefaultlibs warning in https://gist.github.com/tibbe/8448715.

Works beautifully, thank you!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.