Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile: ...is up to date

Tags:

c

makefile

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: make: `q_a' is up to date.

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 have not files with the same name in my folder and I can compile them when I write in terminal. Can you help? Thanks in advance!

like image 432
a_user Avatar asked Dec 26 '22 13:12

a_user


1 Answers

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.

like image 84
Andreas Grapentin Avatar answered Jan 02 '23 23:01

Andreas Grapentin