问题
I am searching a make like build tool that supports (besides usual make features):
- Automatic deletion of temporary created files (like in GNU make for example)
- Regular expressions in rule patterns (like e.g. in Cook
About 1: By default GNU make deletes temporary files. For example have these rules:
%.c: %.y
some-comand
%.o: %.c
some-comand
If you have a file foo.y and call make foo.o then make derives that is has to create first foo.c and then foo.o. After it is ready it delete the temporary file foo.c.
Cook does not support this.
About 2: Make just support suffix pattern style rules. For example like this (equivalent notations):
%.o: %.c
some-comand
.c.o: some-comand
Allowing regular expressions in rules of patterns is of course more powerful. Pseudo-code examples:
foo.+bar.o: foo.+bar.c
some-comand
foo\1bar.o: foo(.+)bar.c
some-comand
The first rule matches (and its command is executed) if for example fooXXXbar.o is needed and fooYYYbar.c exists (or make knows how to create it. The second rule matches, if for example fooXXXbar.o is needed and fooXXXbar.c exists.
Do you know a build that supports these features?
回答1:
I'm not really familiar with any build tool but GNUMake; it doesn't handle regexes, but it can handle these cases. The second rule is easy:
foo%bar.o: foo%bar.c
@echo trying to make $@, found $^
The first one requires some kludgery:
PPP = $(firstword $(filter-out foobar.c, $(wildcard foo*bar.c)))
ifneq ($(PPP),)
foo%bar.o: $(PPP)
@echo found $^
else
WAR = $(warning no match to the regex)
foo%bar.o:
$(WAR)
endif
回答2:
GNU Make obviously has 1, and needs 2 (its maintainers seem to agree), but there isn't a full design for it, let alone a patch.
You can emulate this functionality in GNU make by using functions such as $(call), $(eval) or even $(shell), and/or generating auxiliary Makefiles and including them, but the results are quite hard to read.
回答3:
.SECONDEXPANSION
expansion can help quite a lot. For example:
.SECONDEXPANSION:
1.o another.o dir/3rd.o: $$(call munge,$$@)
gcc blah blah -o $@
∶
Basically, $munge
should return the source given the target. You can define your function to do practically anything, even calling perl via $(shell...)
(though $shell
hurts performance somewhat). A simple one might be:
munge = $(patsubst %.o,%.cpp,$(notdir $1))
来源:https://stackoverflow.com/questions/3545700/make-like-tool-that-supports-automatic-deletion-of-temp-files-and-regular-expres