How can I setup a Makefile so it only compiles the source files that actually includes the .h file that changed instead of compiling every file?
lets say I have following variables for my source files and include files:
SRC := SRC/*.c
OBJ := $(SRC:.c=.o)
INC := INC/*.h
TARGET := programm
Now I have following rules to create the TARGET:
$(TARGET) : $(OBJ) $(INC)
$(CC) $(CFLAGS) $(OBJ) -o $@
#CC is the compiler and CFLAGS the flags to compile e.g. gcc -Wall -Werror
Bu if I change something in of the INC files it will recompile all object files. Is there a way to have the makefile just compile the files that actually are effected by the change in the .h file?