Skip to content

Instantly share code, notes, and snippets.

@algas
Last active July 14, 2026 01:14
Show Gist options
  • Select an option

  • Save algas/377ca9d3f11916af39951ccd599a3b88 to your computer and use it in GitHub Desktop.

Select an option

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-%
@ec22s

ec22s commented Jul 14, 2026

Copy link
Copy Markdown
10  world-%:
11  -	@echo "${@:hello-%=%} world"
11  +	@echo "${@:world-%=%} world"

FYI:

$ make hello NAMES=hoge fuga
hello hoge
make: *** No rule to make target `fuga'.  Stop.

$ make hello NAMES="hoge fuga"
hello hoge
hello fuga

$ make --version
GNU Make 3.81

$ $SHELL --version
GNU bash, version 5.3.15(1)-release (x86_64-apple-darwin23.6.0)

^_^)

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