3 ms·
better still, IMO -- capitalize on those sweet, sweet implicit rules. CFLAGS=-Wall # define CFLAGS, CXXFLAGS, LDLIBS and LDFLAGS as necessary all: name_
by wyldfire 9y ago
better still, IMO -- capitalize on those sweet, sweet implicit rules.
CFLAGS=-Wall
# define CFLAGS, CXXFLAGS, LDLIBS and LDFLAGS as necessary
all: name_of_bin
name_of_bin: a.o b.o c.o
clean:
$(RM) -f *.o name_of_bin
.PHONY: clean all
- MereInterest 9y agoI don't really like those, because then it makes it harder to separate out the source and the build directory. VPATH is a partial solution, but I find it much easier to have a single explicit pattern rule, rather than using both implicit pattern rules and modification of those implicit pattern rules.
- syncsynchalt 9y agoThat's fair. In actual projects of more than a few source files I do copy/paste some boilerplate to give me a build dir, dependency files, and so on. I just thought this (actual real-world example that I use for smallish projects) would help someone.
- syncsynchalt 9y agoThanks... I suspected I was just redefining a built-in pattern rule, but I put it there anyway just so I can remember whether it's LDFLAGS (linker) vs LFLAGS (lexer). Plus I was thinking maybe less magic for someone trying to make sense of it. Is there no command needed for name_of_bin to be linked? Does it automatically figure it out based on *.o dependencies?
- spc476 9y agoYes it does. In fact, with GNU make, if you have a single file, hello.c, you can type "make hello" without a makefile and it will just work.
- jwilk 9y ago$(RM) is defined as "rm -f", so the extra -f is not needed. Personally, I would just write "rm -f" explicitly. I don't see any advantages of using $(RM).