Makefile

Теги: cicd  cli 

Формат

target [target ...]: [component ...]
Tab ↹[command 1]
	   .
	   .
	   .
Tab ↹[command n]

Допускаются макросы, переменные и использование суффиксов и префиксов и других конструкций. При отсутствии аргументов у команды make обращается к цели all или к первой встречной из ближайшего Makefile. Пример;

# target: all - Default target. Does nothing.
all:
	echo "Hello, this is make for my knowledgebase"
	echo "Try 'make help' and search available options"

# target: help - List of options
help:
	egrep "^# target:" [Mm]akefile

# terget: serve - build site for production
serve:
	JEKYLL_ENV=development bundle exec jekyll serve

# target: build - build site for deployment
build:
	JEKYLL_ENV=production bundle exec jekyll build

Пример из вики:

PACKAGE	 = package
VERSION	 = ` date "+%Y.%m%d%" `
RELEASE_DIR  = ..
RELEASE_FILE = $(PACKAGE)-$(VERSION)

# Notice that the variable LOGNAME comes from the environment in
# POSIX shells.
#
# target: all - Default target. Does nothing.
all:
	echo "Hello $(LOGNAME), nothing to do by default"
		# sometimes: echo "Hello ${LOGNAME}, nothing to do by default"
	echo "Try 'make help'"

# target: help - Display callable targets.
help:
	egrep "^# target:" [Mm]akefile

# target: list - List source files
list:
	# Won't work. Each command is in separate shell
	cd src
	ls

	# Correct, continuation of the same shell
	cd src; \
	ls

# target: dist - Make a release.
dist:
	tar -cf  $(RELEASE_DIR)/$(RELEASE_FILE) && \
	gzip -9  $(RELEASE_DIR)/$(RELEASE_FILE).tar

Смотир еще: