check makefile is OK
cat -e -t -v makefile_name
vars
Integrate with Bash
special variables
run bash script
temp var
run in one shell solution
out.tar:
set -e ;\
TMP=$$(mktemp -d) ;\
echo hi $$TMP/hi.txt ;\
tar -C $$TMP cf $@ . ;\
rm -rf $$TMP ;\
use separate lines
get-backup-dir: TEMP = $(shell find "$(BACKUP_DIR)" -maxdepth 1 -type d -printf '%p\n' | sort -r | head -n1)
get-backup-dir: ## print that last backup dir
@echo "The relative path is:\n $(TEMP)"
using eavl
out.tar :
$(eval TMP := $(shell mktemp -d))
@echo hi $(TMP)/hi.txt
tar -C $(TMP) cf $@ .
rm -rf $(TMP)
call another target with arg
.PHONY: callee
callee:
@echo $(XYZ)
.PHONY: caller
caller: XYZ = 2
caller: a
caller:
@echo 'test'
if empty
ifeq ($(a),)
b=2
else
b=$(a)
endif
multiprocess jobs
You can also use MAKEFLAGS += 2
in the Makefile to be able to have two parallel processes
To use all of cpus:
NPROCS = $(shell grep -c 'processor' /proc/cpuinfo)
MAKEFLAGS += -j$(NPROCS)