Where do we put the all in a Makefiles?
I had a similar question found earlier, but I needed a little bit more details. I also looked at the GNU make manual, but got lost in the mountain of documentation. I tried the googles, but didn’t find a good example. So, I did what was my last resort and tried to figure it out by hacking at a Makefile myself. I have:
CC=gcc
CFLAGS=-Wall -g
clean:
rm -f all: ex1
This didn’t compile my ex1 in C. Also, if I wanted to add more to this make file. Like ex1, ex2, to exercise whatever. Would I just put the all at the top and repeat the
rm - f whatever
line below clean?
Appreciate your help and assistance. Patience appreciated too.
allis actually nothing special, just a target name commonly used. To make it work best, it should be the first target in the file. This makes it the default target, andgmakeworks the same asgmake all.Normally, the
alltarget has dependencies, which are the things which need to be built. E.g.rmis related to thecleantarget (which is also nothing special, just a name commonly used). You define it this way:This makes it delete
myexewhengmake cleanis run. If you makefile builds other files, they should also be listed there.There’s a lot more to know about makefiles. Normally you would use variables and template rules, which help you avoid repeating yourself. But this is far more than a simple answer can describe.