.SUFFIXES: SHELL = /bin/sh INSTALL = install M4 = m4 T = personal SUBDIRS = global $(T) M4FLAGS += $(patsubst %, -I%, $(SUBDIRS)) # these get automatically prefixed with the directory of the makefile that gets # included, super ugly but haha AUTOVARS = TARGETS RES M4_DEPS LIBEXEC define ASSIGN_TEMPLATE = $(1) := $(2) endef $(foreach var,$(AUTOVARS),$(eval $(call ASSIGN_TEMPLATE,ABS_$(var)))) define INCLUDE_TEMPLATE = $$(foreach var,$(AUTOVARS),$$(eval $$(call ASSIGN_TEMPLATE,$$(var)))) include $(1)/Makefile $$(foreach var,$(AUTOVARS),$$(eval $$(call ASSIGN_TEMPLATE,ABS_$$(var),$$$$(ABS_$$(var)) $$$$(patsubst %, $(1)/%, $$$$($$(var)))))) endef $(foreach subdir,$(SUBDIRS),$(eval $(call INCLUDE_TEMPLATE,$(subdir)))) TARGETS := $(ABS_TARGETS) RES := $(ABS_RES) $(foreach var,$(AUTOVARS),$(eval $(call ASSIGN_TEMPLATE,$(var),$$(ABS_$(var))))) INSTALL_TARGETS = $(TARGETS) $(RES) INSTALL_TARGETS_LIBEXEC = $(LIBEXEC) .PHONY: all all: $(TARGETS) .PHONY: clean clean: $(RM) $(TARGETS) .PHONY: install install: $(INSTALL) -d $(DESTDIR)/share/html/$(T) $(DESTDIR)/libexec/$(T) $(INSTALL) -m644 -t $(DESTDIR)/share/html/$(T) $(INSTALL_TARGETS) [[ "$(INSTALL_TARGETS_LIBEXEC)" != "" ]] && $(INSTALL) -m644 -t $(DESTDIR)/libexec/$(T) $(INSTALL_TARGETS_LIBEXEC) %.html: %.html.m4 $(M4_DEPS) $(M4) -DCURPAGE=$(notdir $*) $(M4FLAGS) $< > $@ sed -i '/^$$/d' $@