define usage
Demonstrate how to serialize specific targets while building everything
else in parallel using file locking. Note that the numbered targets
are built in the same second whereas the letters are one second apart
due to the serialized "sleep 1".

The Makefile is used as the lockfile simply because it's a file known
to exist.

EXAMPLE: make clean && make -j24
endef

MKFILE := $(lastword $(MAKEFILE_LIST))
SAFE_TARGETS := 0 1 2 3 4 5 6 7 8 9
LOCK_TARGETS := A B C D E F G H I J
TARGETS := $(SAFE_TARGETS) $(LOCK_TARGETS)

.PHONY: all
all: $(TARGETS)

$(SAFE_TARGETS):
	@touch $@
	@echo Made $@ at $$(date)

$(LOCK_TARGETS):
	@flock $(MKFILE) sleep 1
	@touch $@
	@echo Made $@ at $$(date)

.PHONY: help
help:; @:$(info $(usage))

.PHONY: clean
clean:
	$(RM) $(SAFE_TARGETS) $(LOCK_TARGETS)

# vim: filetype=make shiftwidth=2 tw=80
