From: <cod...@go...> - 2009-08-11 18:58:32
|
Revision: 391 Author: jam...@us... Date: Tue Aug 11 11:50:17 2009 Log: (objc2 branch) pulled just-committed cabal build fix from trunk http://code.google.com/p/hoc/source/detail?r=391 Modified: / /branches/objc2/hoc /branches/objc2/hoc/HOC.cabal /branches/objc2/hoc/Setup.hs ======================================= --- /branches/objc2/hoc/HOC.cabal Tue Aug 11 11:50:04 2009 +++ /branches/objc2/hoc/HOC.cabal Tue Aug 11 11:50:17 2009 @@ -64,7 +64,16 @@ hs-source-dirs: HOC extra-libraries: objc, ffi + + -- This is a hack. + -- Setup.hs contains code to build HOC_cbits.o from the + -- objective-c sources, as well as a matching hack to prevent + -- Cabal from invoking "ghc -c" on this file. Cabal will then + -- include HOC_cbits.o on the linker command line, which is the + -- whole point of this exercise. c-sources: HOC_cbits.o + + if os(darwin) include-dirs: /usr/include/ffi frameworks: Foundation ======================================= --- /branches/objc2/hoc/Setup.hs Wed Dec 10 14:10:22 2008 +++ /branches/objc2/hoc/Setup.hs Tue Aug 11 11:50:17 2009 @@ -5,6 +5,7 @@ import Distribution.Simple.PreProcess import Distribution.Simple.Configure import Distribution.Simple.LocalBuildInfo +import Distribution.Simple.Program import System.Cmd( system ) import System.Exit( ExitCode(..) ) import System.Environment( getEnv ) @@ -99,6 +100,13 @@ extraFlags <- buildCBits (libBuildInfo libInfo) + -- add compiler flags required by C parts of HOC; + -- + -- HACK #1: + -- This passes the HOC_cbits.o object file on the + -- as a compiler flag so that template haskell can link + -- compile-time code. + let hooked_pd = pd { library = Just $ libInfo { libBuildInfo = addCompilerFlags extraFlags @@ -109,7 +117,42 @@ (executables pd) } - build hooked_pd lbi buildFlags knownSuffixHandlers + -- HACK #2: + -- HOC_cbits.o (built by buildCBits below) is specified in c-sources + -- for the library. Cabal reacts to this by invoking ghc -c HOC_cbits.o, + -- which ghc doesn't like. So, instead of calling ghc directly, we call + -- a short auto-generated shell script that does nothing in this case, + -- and calls the real ghc in all other cases. + -- After having "compiled" HOC_cbits.o in this way, Cabal will link + -- HOC_cbits.o as part of the library, which is what we want. + + let Just pr = lookupKnownProgram "ghc" (withPrograms lbi) + Just conf = lookupProgram pr (withPrograms lbi) + + ghcLocation = programLocation conf + + let fakeGHC = "./dist/build/fake-ghc.sh" + + writeFile fakeGHC $ unlines [ + "#!/bin/sh -e", + "case \"$*\" in", + " *HOC_cbits.o) true;;", + " *) \"" ++ locationPath ghcLocation ++ "\" \"$@\";;", + "esac" + ] + system $ "chmod +x " ++ fakeGHC + + let conf' = conf { programLocation = UserSpecified fakeGHC } + + progs' = updateProgram conf' (withPrograms lbi) + + let lbi' = lbi { + withPrograms = progs' + } + + -- call the default with our modified package description and + -- local build info + build hooked_pd lbi' buildFlags knownSuffixHandlers -- |Build HOC_cbits.o using the flags specified in the configuration -- stage, and return a list of flags to add to support usage of |