andandandand
andandandand

Reputation: 22270

Understanding Make's implicit rules

If I erase the gcc lines from this file shouldn't it take compilation as the implicit rule? Why isn't it allowing me to run the program ./calc with that makefile configuration?

Makefile:

all: calc 

clean:  
    rm -rf calc arit.o calc.o

calc:   calc.o arit.o
    #gcc -o calc calc.o arit.o

calc.o: calc.c arit.h
    #gcc -c calc.c 

arit.o: arit.c arit.h
    #gcc -c arit.c

Upvotes: 2

Views: 1117

Answers (2)

Jack Kelly
Jack Kelly

Reputation: 18667

Further to Jonathan Leffler's answer, the following minimal GNUMakefile should do all compilation and linking through implicit rules only:

calc: calc.o arit.o
arit.o: arit.c arit.h
calc.o: calc.c arit.h
clean:
    rm -rf calc arit.o calc.o

Upvotes: 2

Jonathan Leffler
Jonathan Leffler

Reputation: 753725

Because the comment is indented by a tab stop, it is treated as a command (and executed by the shell, which treats it as a comment).

If the '#' symbols were in column 1, then they would be pure (make) comments.

Upvotes: 6

Related Questions