I actually want to automatically add .c and .o files whenever i create a new .c files.
Umm... there is a way, read on the wildcard function and stem substitution, as in
SOURCES := $(wildcard *.c)
OBJECTS := $(SOURCES: %.c=%.o)
calc: $(OBJECTS)
gcc -o calc $(OBJECTS)
%.o: %.c
gcc -c $< -o $@
In my opinion, wildcard is a misfeature (if you wish I may elaborate). In any case do not try to use it until you comfortably understand the basic make functionality.
Make's way of thinking is sort of convoluted. Take small steps to get used to it.can anybody explain what the variables $@ and $< mean.
$@ in a recipe means a target name. For example,
foo.o: foo.c
gcc -o foo.o foo.c
is the same as
foo.o: foo.c
gcc -o $@ foo.c
Similarly, $< means a prerequisite name:
foo.o: foo.c
gcc -o $@ $<
Not much of a value for the explicit rules, but very useful for the stem rules, such as
%.o: %.c
gcc -o $@ $<