Makefile
Makefile
adventures
.PHONY
target
By default, Makefile targets are "file targets" - they are used to build files from other files. Make assumes its target is a file. These special targets are called phony and you can explicitly tell Make they're not associated with files. We don't need to use .PHONY
as long as you don't have a file with the same name as the task. The task will always be executed anyway, and the Makefile will be more readable.
echo "echo \"This is clean file\"" > clean echo "echo \"This is clean_runfile file\"" > clean_runfile cat > Makefile <<EOF .PHONY: clean clean: cat ./clean clean_runfile: cat ./clean_runfile EOF
Running the example:
make clean # executes the commands explicitly as it has .PHONY target cat ./clean echo "This is clean file" make clean_runfile make: 'clean_runfile' is up to date. piotr@Sylwia-zonka:~/src/myprojects/Makfile_adventures$
Help section
define FLUXCHART_MAKE_HELP Targets: generate Generate a new chart files from flux version specified at start of Makefile. helmdocs Update README.md files in chart directories. unittests Run helm unittest against the charts. update.appversion Update version strings in testfiles and Chart.yaml. update.chartversion Bump Semver chart version. reviewable Run to see if everything fits. endef export FLUXCHART_MAKE_HELP .PHONY: help help: @echo "$$FLUXCHART_MAKE_HELP"
Color and logging format
# ==================================================================================== # Colors BLUE := $(shell printf "\033[34m") YELLOW := $(shell printf "\033[33m") RED := $(shell printf "\033[31m") GREEN := $(shell printf "\033[32m") CNone := $(shell printf "\033[0m") # ==================================================================================== # Logger TIME_LONG = `date +%Y-%m-%d' '%H:%M:%S` TIME_SHORT = `date +%H:%M:%S` TIME = $(TIME_SHORT) INFO = echo ${TIME} ${BLUE}[ .. ]${CNone} WARN = echo ${TIME} ${YELLOW}[WARN]${CNone} ERR = echo ${TIME} ${RED}[FAIL]${CNone} OK = echo ${TIME} ${GREEN}[ OK ]${CNone} FAIL = (echo ${TIME} ${RED}[FAIL]${CNone} && false)
References
- fluxcd helm chart Makefile
- Multiline bash in Makefile