I have been struggling a bit to get make to compile only the files that have been edited. However I didn't have much success and all the files get recompiled. Can someone explain me why?
My files are:
main.c
a_functions.c
where main.c includes main.h and a_functions.c includes a.h
Here is my makefile:
CC=gcc
CFLAGS=-Wall -I. -c
EXEC_FILE=program1
all: program
a_functions.o: a_functions.c
a_functions.c: a.h
main.o: main.c
main.c: main.h
objects: a_functions.c main.c
$(CC) a_functions.c main.c $(CFLAGS)
program: a_functions.o main.o
$(CC) a_functions.o main.o -o $(EXEC_FILE)
Changing the makefile as per suggestions seems to have the same problem::
all: program
a_functions.o: a_functions.c a.h
gcc a_functions.c -c
main.o: main.c main.h
gcc main.c -c
program: a_functions.o main.o
gcc a_functions.o main.o -o program1
-I.
strikes me as strange. What's up with that? – Barbaresea.h
in the current directory. The default may well have (eg)/usr/include
for the system headers but not.
for local stuff. I'm pretty certain every gcc I've ever used also looked in the current directory by default (the actual behaviour is implementation-defined) but it may be a weird variant here. – Polyethylene#include "a.h"
to include the file rather than#include <a.h>
? – Barbarese