Skip to content

Instantly share code, notes, and snippets.

@jacobly0
Last active March 25, 2017 02:01
Show Gist options
  • Select an option

  • Save jacobly0/a29bfad24108e335b3399f19ad17c714 to your computer and use it in GitHub Desktop.

Select an option

Save jacobly0/a29bfad24108e335b3399f19ad17c714 to your computer and use it in GitHub Desktop.
Dynamic makefile dependencies
all: create $(patsubst %.src,%.obj,$(wildcard *.src))
clean:
rm -f create *.src *.obj
%.obj: %.src
cp $< $@
create:
touch create {a,b,c}.src
test -e create # make sure it fails if the file wasn't created (to prevent infinite recursion)!
$(MAKE)
.PHONY: all clean
touch create {a,b,c}.src
make
make[1]: Entering directory '/home/jacob/Programming/makefile/dynamic-deps'
cp b.src b.obj
cp a.src a.obj
cp c.src c.obj
make[1]: Leaving directory '/home/jacob/Programming/makefile/dynamic-deps'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment