Skip to content

C source files are not recompiled when headers change #4306

@amosr

Description

@amosr

For projects with C source files and headers, the check whether it needs to recompile is naive and only looks at whether the source file has changed.
So if you have two files foo.h and foo.c, touching foo.h should cause foo.c to be recompiled.

The same problem exists for .hsc files: #24 and #3087.

One idea for implementing this is to change the checkNeedsRecompilation function (https://github.com/haskell/cabal/blob/master/Cabal/Distribution/Simple/GHC.hs#L1327) to call out to gcc -M, which generates a makefile rule listing the dependencies for that particular file.
We'd need to call gcc -M with the C flags (the include dirs), parse the makefile rule, then go through all those files and see if any are newer than the object.
Does that sound too slow to do every time? Is there an easy way to cache this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions