Originally Posted by
cisokay
So if prog.o is older than prog.c then it will compile the source with this makefile, else it will skip it ?
Code:
#Makefile
#############
default: clean compile
compile: prog.cpp
g++ -o prog prog.cpp
clean:
rm -f *.o prog a.out core*
A simple make statement is like this:
Code:
target: dependancies
command
if any of the dependancies is newer than target, command is run. Note that the command must have a tab char before.
Your make will always compile prog. You're stating that compile depends on prog.cpp. When that command is run no file named compile exists, so the command is always run, whenever make is run.
Also you're not stating that prog depends on prog.cpp. re-read my previous post.
and finally since I seriously doubt that there'll ever be any file called compile declare compile like this
.PHONY compile
In other words, compile will always be a word passed through the command line like clean
To sum up we have
Code:
prog: prog.cpp
g++ prog.cpp -o prog
.PHONY clean compile
compile: prog
clean:
rm -f *.o prog a.out core*