views:

71

answers:

3

I am searching a make like build tool that supports (besides usual make features):

  1. Automatic deletion of temporary created files (like in GNU make for example)
  2. 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  A: 

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
Beta
yeah, the first snippet works in that case (e.g. wanting .* instead of .+ would need some workaround then -> adding another foobar.o: foobar.c). The second snippet only works, if some foo.+bar.c is already created as file in the filesystem. It does not consider other rules that know how to create the needed foo.+bar.c (e.g. if there is a fooxbar.y file).
maxschlepzig
+1  A: 

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.

reinierpost
A: 

.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))
bobbogo