Your Makefile
is wrong; should be (assuming a GNU make)
RM= rm -vf
CC= gcc
CFLAGS= -Wall -g
.PHONY: all clean
all: hello
hello: hello.o
hello.o: hello.c hello_api.h
clean:
$(RM) *.o *~
Last line, just after clean:
, starts with a tab character
See also this answer for more. Run make -p
to understand the implicit rules useful in the above case.
Read carefully the documentation on make variables. Those defined with =
are expanded lazily and textually (with the make variables further expanded in the substituted text). In other words, CC= $(CC) -g
gives an infinite loop. Because the first $(CC)
is replaced with $(CC) -g
which is rescanned and its $(CC)
is replaced with the same (getting $(CC) -g -g
) etc etc ad infinitum.
make
is mostly a string processing utility (with of course the dependency thing based upon file modification time). It does not really have some proper AST as internal representation of the commands to be run.