GHC compilation bug?

Some time ago I devised a little system to make compilation and testing of my Haskell programs a bit more comfortable. My project root looks as follows:

./bin/
./bin/myMain
./bin/test
./interfaces/
./obj/
./src/
./src/makefile
./src/MyLib.hs
./src/myMain.hs
./src/testSuite.hs

myMain is the main module, whose imports are like those:

import MyLib
-- irrelevant content follows

testSuite is similar:

import System.Exit
import Test.HUnit
import MyLib
-- irrelevant content follows

I compile those with two simple commands:

ghc  testSuite.hs -o ../bin/test -odir ../obj -hidir ../interfaces
ghc  myMain.hs -o ../bin/myMain -odir ../obj -hidir ../interfaces

Now, as I run the first, whole test suite compiles and executes perfectly fine, even if there are any object or intereface files present. However when I run the second to compile main executable, it compiles test binary again unless I run remove object and interface files.

The reason is, as far as I found, that main module produces Main.o and Main.hi , no matter what its name is. Therefore while compiling myMain, GHC sees those files present, so does not recompile main module. The strange part is this is not the case when I compile test suite - in such a case Main is recompiled even if there are objects and interfaces present.

$ ghc  testSuite.hs -o ../bin/test -odir ../obj -hidir ../interfaces
[1 of 2] Compiling MyLib       ( MyLib.hs, ../obj/MyLib.o )
[2 of 2] Compiling Main        ( testSuite.hs, ../obj/Main.o )
Linking ../bin/test ...

$ ghc  myMain.hs -o ../bin/myMain -odir ../obj -hidir ../interfaces
Linking ../bin/myMain ...

But when I run main compilation first:

$ ghc  myMain.hs -o ../bin/myMain -odir ../obj -hidir ../interfaces
[1 of 2] Compiling MyLib       ( MyLib.hs, ../obj/MyLib.o )
[2 of 2] Compiling Main        ( myMain.hs, ../obj/Main.o )
Linking ../bin/myMain ...

$ ghc  testSuite.hs -o ../bin/test -odir ../obj -hidir ../interfaces
[2 of 2] Compiling Main        ( testSuite.hs, ../obj/Main.o ) [Test.HUnit changed]
Linking ../bin/test ...

What's even stranger, the problem disappears when I put aside -odir and -hidir GHC parameters and compile everything in the same directory. Why?

[NOTE:]

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.6.3
链接地址: http://www.djcxy.com/p/7520.html

上一篇: GHC部分评估和单独编译

下一篇: GHC编译错误?