Hey all,
I just pushed a new branch called 'groups' which can help writing
Tupfiles where commands should run in stages. For example, you may
want to build all auto-generated header files before compiling
anything, but it could be cumbersome/slow to declare the headers as
inputs to each compilation command. Instead of writing a Tupfile like
this:
: |> generate header... |> foo.h
: |> generate header... |> bar.h
... lots more headers generated
: foreach *.c | foo.h bar.h ... |> gcc -c ... |>
You can now do something like this:
: |> generate header... |> foo.h <myheaders>
: |> generate header... |> bar.h <myheaders>
...
: foreach *.c | <myheaders> |> gcc -c ... |>
Anything that lists <myheaders> as an output becomes fair game for use
by those commands that list <myheaders> as an input. The group is
actually inserted as a node in the graph in whatever directory you
specify, so <myheaders> in a/Tupfile is different from <myheaders> in
b/Tupfile. You could use ../b/<myheaders> to refer to a group in
another directory. It may be easiest to put any groups in the
top-level of your project using a Tuprules.tup file:
myproject/Tuprules.tup:
MYPROJECT_ROOT = $(TUP_CWD)
!generate_header = |> python blah... |> %B.h $(MYPROJECT_ROOT)/<autoheaders>
!cc = | $(MYPROJECT_ROOT)/<autoheaders> |> gcc -c %f -o %o |> %B.o
Then in any sub Tupfile you can do:
: foreach *.
h.in |> !generate_header |>
: foreach *.c |> !cc |>
And the cc commands can use the generated headers without tup complaining.
Note that it is trivial to add circular dependencies by using groups,
so don't do that. You could also invert commands in a Tupfile by using
a group, but that is not the recommended use case.
Another example where it might help is with vala/vapi files (Simon or
Tal or other vala users, can you try it out and see if it helps?) -
myproject/Tuprules.tup:
MYPROJ_ROOT = $(TUP_CWD)
!fast-vapi = |> valac-0.16 --fast-vapi=%B.vapi %f |> %B.vapi
$(MYPROJ_ROOT)/<vapi>
!valac = | $(MYPROJ_ROOT)/<vapi> |> valac-0.16 $(VAPISPARAMS)
$(VALAPKGS) %f -C |> %B.c
This way you don't have to list *.vapi as inputs to the valac command.
However, you still need some way to construct the correct
--use-fast-vapi arguments to pass to valac, and the grouping feature
doesn't help with that.
Any feedback would be appreciated!
Thanks,
-Mike