# Ultra-hack (or how to get GHC to play nicely^W with automake!) # # We use "ghc --make" to do the dependency tracking instead of automake having # to realise what the dependencies are. This is good, because "ghc --make" # will undoubtedly be a lot more reliable than any ultra-boogie scripts that we # could ever whip up. # # However, since "ghc --make" always wants to see the 'main' function in # whatever .hs file you give it, we need to pass it the "-no-hs-main" option to # stop it from trying to find 'main'. This prevents GHC from spitting out an # error and stopping the whole make process. # # Of course, in the event that GHC does actually find a 'main' function, it # then decides to merrily link all the imported modules together to produce an # executable, which is not what we want at all. (Especially since the '-o' # option tells GHC that we want an executable called "Foo.o", and it then tries # to write over the existing Foo.o object file which it just compiled. Arrgh.) # So, to stop that, we, uhm, tell GHC to use the 'true' command for the linker, # which doesn't do anything at all, besides return 0. # # I'm very proud of this hack :). AM_GHC_DEPEND_FLAGS = -no-hs-main --make -pgmltrue -odir . -hidir . DEFAULT_INCLUDES = -i$(srcdir) #HMAKE_INCLUDES = $(DEFAULT_INCLUDES) -P$(srcdir) AM_GHC_COMPILE_FLAGS = $(DEFS) $(GHC_PACKAGES) \ $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_GHCFLAGS) $(GHCFLAGS) # If the user has hmake, use that instead of ghc to compile stuff. It's far # less hacky than the evil --make -pgmltrue options above, and hmake is also # a bit smarter in compiling stuff. In particular, if you are importing an # already-compiled module which resides in a different directory, GHC will go # recompile the module again and put the compiled object in the current # directory. hmake will check the other directory and see that you've already # compiled that module. #if HMAKE #COMPILE = $(HMAKE) -ghc $(AM_GHC_COMPILE_FLAGS) #else COMPILE = $(GHC) $(AM_GHC_DEPEND_FLAGS) $(AM_GHC_COMPILE_FLAGS) #endif ## It seems that automake requires that you use "Suffix Rules", which are now ## deprecated by GNU make's Pattern Rules. See the make info manual for more ## details. (I suppose automake is also meant to work on systems without GNU ## make, though ...) hs.o: $(COMPILE) -o $@ $< # Use ghc as the linker LINK = $(GHC) $(GHC_PACKAGES) $(AM_LDFLAGS) $(GHCFLAGS) -o $@ # Clean out .hi files too CLEANFILES = *.hi # Tell automake that .hs files compile to .o files SUFFIXES = .hs