makefilebuild-dependenciesbuild-target

Makefile: Getting "`target' is up to date"


I have made a makefile for some c files. I have seen too many ways on the internet but i had always the same problem: Running make, I am told:

make: `q_a' is up to date.

My Makefile contains:

q_a: 
gcc -o q_a quick_sort_i.c

q_g: 
gcc -o q_g quick_sort_g.c

s_a: 
gcc -o s_a shell_sort_i.c

s_g: 
gcc -o s_g shell_sort_g.c

fork: 
gcc -o fork fork.c

I don't have files with the same name as the target in my folder, and I can perform the compilation commands successfully them when I enter them manually in a terminal.


Solution

  • You have not specified dependencies for your targets.

    What make does, is first checking if your target (q_a) exists as a file, and if it does, if its dependencies are newer (as in, have more recent modification time) as your target. Only if it needs to be updated (it does not exist or dependencies are newer) the rule is executed.

    That means, if you need q_a to be recompiled every time quick_sort_i.c is changed, you need to add it as a dependency to q_a, like this:

    q_a: quick_sort_i.c
        gcc -o q_a quick_sort_i.c
    

    With that, make will recompile q_a if necessary.