Makefile
- Introduction
Makefile is a way of automating software building procedure and other complex tasks with dependencies.
3. Syntax
The Two Flavors of Variables
The '?=' is the conditional variable assignment operator: it only has effect if the variable not yet defined
p ?= "INVOKE-WITH-p=WHATEVER"
Syntax of Conditionals
ifeq ('john', '${USER}')
u = "jdoe"
else
u = ${USER}
endif
Check if a command exists inside a target:
apply: ## Apply
ifeq (,$(shell command -v dot))
@echo "WARN 'graphviz' not found, can be installed w/ sudo apt install graphviz"
else
terraform graph | dot -Tsvg > graph-nogit.svg
endif
terraform apply
9. Examples
Full Makefile (example)
Sample invocation from command like:
make zip p=MYPROJ
Makefile
.PHONY: install run
# INI CONFIG
# ZIP naming YYYYMMDD_username_P_app.zip (eg: 20220811_myusername_MYPROJ_data-contacts-ws.zip)
# Sample command like invocation: make zip p=MYPROJ
ifeq ('myalias', '${USER}')
u = "myusername"
else
u = ${USER}
endif
p ?= "INVOKE-WITH-p=WHATEVER"
# END CONFIG
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
clean: ## Clean, updating child modules
./mvnw -N versions:update-child-modules \
&& ./mvnw clean \
&& rm -frd dist/
update-child-modules:
./mvnw -N versions:update-child-modules
install-notests:
./mvnw -DskipTests=true clean install
install: ## Update child modules, install (clean, no tests)
make update-child-modules
make install-notests
run: ## Run, only after install
echo http://localhost:8080/data-contacts-ws/DatasContactsService?wsdl && cd data-contacts-ws-core && ../mvnw jetty:run
sonar: ## Sonar
# [verified on 202w????, w/ x.x% coverage] https://sonarqube.cou.edu/sonar/dashboard?id=xxx%3Axxx_zzzz
./mvnw verify sonar:sonar
zip: ## make zip p=<PROJECT_CODE/JIRA> (only after package)
set -e ;\
rm -rf dist/ ;\
mkdir -p dist/bd/ ; \
mkdir -p dist/server/jboss72/ ; \
cp data-contacts-ws-core/target/data-contacts-ws.war dist/server/jboss72/ ;\
cd dist/ ;\
zip -r ../$(shell date +%Y%m%d)_${u}_${p}_data-contacts-ws.zip . ;\
cd .. ;\
all:
make install
make run