Skip to content

Instantly share code, notes, and snippets.

@benknoble
Created July 6, 2018 14:26
Show Gist options
  • Save benknoble/fea301daeb427ab65fb3c80bd5095f63 to your computer and use it in GitHub Desktop.
Save benknoble/fea301daeb427ab65fb3c80bd5095f63 to your computer and use it in GitHub Desktop.
Make dynamically generated targets (example/proof of concept)
all:
$(MAKE) $(shell ./targets.sh)
one:
@echo one
two:
@echo two
#! /usr/bin/env bash
targets() {
local targets=(
one
two
)
echo "${targets[@]}"
}
main() {
targets
}
main
@benknoble
Copy link
Author

Sample output:

$ make
make one two
make[1]: Entering directory '/home/knoble/tmp'
one
two
make[1]: Leaving directory '/home/knoble/tmp'

@benknoble
Copy link
Author

benknoble commented Jul 6, 2018

Recursive makes automatically inherit flags passed, so make -j will run everything in parallel.

If the targets were long running build processes, say,

one:
	@sleep 5
	@echo one

two:
	@sleep 5
	@echo two

Then make -j would only wait 5 seconds before outputting one and two (compared to 10 without -j, as each target is serially built).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment