Skip to content

Instantly share code, notes, and snippets.

@algas
Last active August 13, 2023 08:13
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save algas/377ca9d3f11916af39951ccd599a3b88 to your computer and use it in GitHub Desktop.
Save algas/377ca9d3f11916af39951ccd599a3b88 to your computer and use it in GitHub Desktop.
makefile subcommand example

Usage

hello command with an argument

$ make hello-foo
hello foo

hello command without arguments

$ make hello
hello foo
hello bar
hello baz

hello command parallel

$ make --jobs 2 hello
hello bar
hello foo
hello baz

hello command with arguments

$ make hello NAMES=hoge fuga
hello hoge
hello fuga

world command with an argument

$ make world-123
123 world

world command without arguments

$ make world
foo world
bar world
baz world
NAMES = foo bar baz
hello: $(addprefix hello-, $(NAMES))
hello-%:
@echo "hello ${@:hello-%=%}"
world: $(addprefix world-, $(NAMES))
world-%:
@echo "${@:hello-%=%} world"
.PHONY: hello hello-% world world-%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment