I am new to make. I tried running sample make as shown below.
CC=gcc
CFLAGS=-I.
OBJ = hellofunc.o hellomake.o
SRC = hellofunc.c hellomake.c
DEPS := $(OBJ:.o=.d)
%.o: %.c
$(CC) -MT $@ -MMD -MP -MF $(patsubst %,%.d,$(basename $@)) -o $@ -c $(CFLAGS) $<
test:
@echo "inside test target"
hellomake: hellomake.o hellofunc.o
$(CC) -o $@ $^
include $(DEPS)
Output :
inside test target
As per make manual, it is saying that By default, make starts with the first target (not targets whose names start with ‘.’). So in this case first target is %.o: %c, right? Why it is not running that rule first? I don't have object files in my directory. make has to check for the absence of object files and try to build with C files using first rule, right?