Skip to content

Instantly share code, notes, and snippets.

@tapih
Last active July 28, 2019 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tapih/e2fe4ba250023282c147a4710804c56d to your computer and use it in GitHub Desktop.
Save tapih/e2fe4ba250023282c147a4710804c56d to your computer and use it in GitHub Desktop.
example of GNU make builtin functions
YAML:=hoge.yaml
FILES:=$(YAML) fuga.tar.gz ./foo/bar.json
all: \
abspath \
addprefix \
addsuffix \
basename \
dir \
notdir \
realpath \
subst \
shell \
info \
warning \
if \
foreach
.PHONY: \
all \
abspath \
addprefix \
addsuffix \
basename \
dir \
notdir \
realpath \
subst \
shell \
info \
warning \
if \
foreach
abspath:
@echo $@
@echo $(abspath .)
@echo
addprefix:
@echo $@
@echo $(addprefix xxx,$(FILES))
@echo
addsuffix:
@echo $@
@echo $(addsuffix xxx,$(FILES))
@echo
basename:
@echo $@
@echo $(basename $(FILES))
@echo
dir:
@echo $@
@echo $(dir $(FILES))
@echo
notdir:
@echo $@
@echo $(notdir $(FILES))
@echo
realpath: $(YAML)
@echo $@
@echo $(realpath $(FILES))
@echo
subst:
@echo $@
@echo $(subst .json,.txt,$(FILES))
@echo
shell:
@echo $@
@echo $(shell ls)
@echo
info:
@echo $@
@echo $(info "this function is for print debug of Makefile")
@echo
warning:
@echo $@
@echo $(warning "warning")
@echo
foreach:
@echo $@
@echo $(foreach f,$(FILES),"$(f)\n")
@echo
if:
@echo $@
@echo $(if a,not empty,empty)
@echo $(if ,notempty,empty)
@echo
$(YAML):
touch $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment