I have an external tool that fetches some sources (Rebar). I want to fill in a variable according to the contents of a directory after Rebar runs.
EFLAGS += -I$(PWD)/include
EFLAGS += -pa $(PWD)/ebin
## $(PWD)/deps/* will only have contents after Rebar runs
EFLAGS += $(patsubst %,-pa %,$(wildcard $(PWD)/deps/*/ebin))
build-deps:
./rebar get-deps
./rebar compile
build-main: build-deps
erlc $(EFLAGS) $(INFILE)
The above will work as intended if I run it as two separate invocations:
make build-deps
make build-main
However, if I just make build-main
, then EFLAGS
gets set while the deps/
directory is empty, then the directory is populated, and then I use EFLAGS
.
Is there a good way for me to only set EFLAGS
after I've run some rules?
EDIT: Here's a Makefile that may demonstrate the problem more easily:
A=$(wildcard test*)
foo:
touch test1
bar: foo
@echo $A
clean:
-rm test*
Here, the "foo" target is standing in for my call to rebar
, so just imagine that you don't know which files I'm going to pass to touch
. If you try
make clean
make bar
make bar
you will find that the two invocations of make bar
produce different results, because in the second one test1
exists before make
begins. I'm looking for a way to get the output of the second make bar
invocation immediately after running make clean
.