m8pple/arch2-2016-cw

Change in private header does not cause makefile to recompile

RaviWoods opened this issue · 3 comments

If one of the private header files change, but the C/C++ file that depends on it doesn't change, the makefile assumes there has been no change and so doesn't recompile the C/C++

A solution would probably involve makefile dependencies, but I'm not well versed enough to work it out.

You can add clean:
$(RM) $(USER_CPU_OBJECTS)
at the end of the makefile and run make clean and then make. Not the best solution but it will get your code recompiled.

Cool, much easier! Will leave this issue open for now in case a better solution is found.

This is a general issue with makefiles, and one of the arguments for full-blown
build systems in IDEs like eclipse and DevStudio, or language specific systems
like CMake.

The problem is that make has absolutely no clue what it is you are doing, it
only knows about inputs, outputs, and the commands that turn inputs into
outputs. So unless you tell it, it doesn't understand that the c files are including
those header files.

There are a few solutions:

1 - Use a build system or IDE that does understand how you are building things.

2 - Do make clean first (as suggested by @nikonikolov). You can make this easier
by having the single command line make clean; make.

3 - Force build, using the -B argument to make. So make -B will tell it to ignore
the timestamps, and just build everything.

4 - Manually indicate that the objects depend on the header files within the makefile.

5 - Include another build step that extracts dependencies, e.g.: http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/

For now, I would recommend options 1, 2, or 3. Option 4 can be enacted by creating
a list of headers and adding it to the build step, but I don't want to encourage
too much complexity. Option 5 you might find interesting to read about, but I
would not recommend doing it.