ASCII-Pony/Makefile

103 lines
2.9 KiB
Makefile
Raw Normal View History

2014-12-21 19:07:25 +01:00
PREFIX?=/usr/local
DATAROOT=$(PREFIX)/share
DATADIR=$(DATAROOT)/ascii-pony
BINDIR=$(PREFIX)/bin
2013-11-09 08:58:29 +01:00
2013-11-12 16:02:03 +01:00
MAKEFILE=$(lastword $(MAKEFILE_LIST))
MAKEFILE_DIR=$(dir $(MAKEFILE))
2013-11-09 08:58:29 +01:00
PONY_DIR=$(MAKEFILE_DIR)Ponies
2016-05-24 13:52:14 +02:00
SCRIPT_INTERPRETER=$(MAKEFILE_DIR)patsi/.env/bin/python
SCRIPT=$(MAKEFILE_DIR)patsi/patsi-render.py
2013-11-09 08:58:29 +01:00
OUT_DIR=$(MAKEFILE_DIR)rendered
2014-04-21 19:01:11 +02:00
PONIES=$(notdir $(shell find $(PONY_DIR) -maxdepth 1 -mindepth 1 -type d ))
2016-05-24 13:52:14 +02:00
OUT_ALL=$(foreach pony,$(PONIES),$(foreach format,$(FORMATS),$(OUT_DIR)/$(format)/$(pony).$(format)))
2013-11-08 22:28:04 +01:00
OUT_DIRS=$(sort $(dir $(OUT_ALL)))
2014-04-21 19:22:10 +02:00
find_deps=$(subst ;,\\\;,$(wildcard $(PONY_DIR)/$(1)/*))
2016-05-24 13:52:14 +02:00
FORMATS=txt ansi svg sh irc png
2013-11-08 17:36:09 +01:00
2014-12-21 19:07:25 +01:00
INSTALL_DIR=cp -rf
INSTALL_FILE=cp -f
UNINSTALL_DIR=rm -rf
2015-08-16 21:44:05 +02:00
REMOVE_FILE=rm -f
UNINSTALL_FILE=$(UNINSTALL_FILE)
2014-12-21 19:07:25 +01:00
REMOVE_DIR=$(foreach d, $(1), [ -d $(d) ] && rmdir $(d) || true;)
MAKE_DIR=mkdir -p
2014-12-09 22:02:35 +01:00
# NOTE: not .PONY :-P
2014-12-21 19:17:07 +01:00
.PHONY: all show show_deps clean list random install uninstall touchput
2013-11-09 10:23:42 +01:00
2013-11-08 19:48:53 +01:00
all: $(OUT_ALL)
2013-11-08 17:07:35 +01:00
2016-05-24 13:52:14 +02:00
define rule_single_output
$(OUT_DIR)/$(2)/$(1).$(2): | $(dir $(OUT_DIR)/$(2)/$(1))
$(OUT_DIR)/$(2)/$(1).$(2): $(call find_deps, $(1))
$(OUT_DIR)/$(2)/$(1).$(2): $(PONY_DIR)/$(1)
$(OUT_DIR)/$(2)/$(1).$(2): $(SCRIPT_INTERPRETER)
$(SCRIPT_INTERPRETER) $(SCRIPT) -i $(PONY_DIR)/$(1) -o $(OUT_DIR)/$(2)/$(1).$(2)
endef
2013-11-08 18:42:21 +01:00
define rule_template
2014-04-21 19:22:10 +02:00
2016-05-24 13:52:14 +02:00
$(foreach format,$(FORMATS),$(eval $(call rule_single_output,$(1),$(format))))
2014-04-21 19:01:11 +02:00
.PHONY: $(1)
2016-05-24 13:52:14 +02:00
$(1) : $(foreach format,$(FORMATS),$(OUT_DIR)/$(format)/$(1).$(format))
@cat $(OUT_DIR)/ansi/$(1).ansi
2014-04-21 19:01:11 +02:00
2015-08-16 21:44:05 +02:00
.PHONY: clean_$(1)
clean_$(1):
2016-05-24 13:52:14 +02:00
$(REMOVE_FILE) $(foreach format,$(FORMATS),$(OUT_DIR)/$(format)/$(1).$(format))
2015-08-16 21:44:05 +02:00
2013-11-08 22:28:04 +01:00
endef
define dir_rule_template
$(1) :
2014-12-21 19:07:25 +01:00
$(MAKE_DIR) $(1)
2013-11-08 18:42:21 +01:00
endef
2013-11-08 17:07:35 +01:00
2013-11-08 18:42:21 +01:00
$(foreach pony,$(PONIES),$(eval $(call rule_template,$(pony))))
2013-11-08 22:28:04 +01:00
$(foreach directory,$(OUT_DIRS),$(eval $(call dir_rule_template,$(directory))))
2013-11-08 17:36:09 +01:00
2016-05-24 13:52:14 +02:00
show: $(OUT_DIR)/ansi/$(PONY).ansi
@cat $(OUT_DIR)/ansi/$(PONY).ansi
2013-11-08 18:42:21 +01:00
show_deps:
2013-11-08 22:28:04 +01:00
@$(foreach d,$(call find_deps,$(PONY)), echo $(d);)
clean:
2014-12-21 19:07:25 +01:00
$(REMOVE_FILE) $(OUT_ALL)
$(call REMOVE_DIR, $(OUT_DIRS) $(OUT_DIR))
2013-11-12 16:02:03 +01:00
list:
@$(foreach pony,$(PONIES), echo $(pony);)
random: PONY=$(shell make -f $(MAKEFILE) list | shuf | head -n 1)
random:
2014-04-21 19:01:11 +02:00
@make --no-print-directory -f $(MAKEFILE) show PONY=$(PONY)
2014-12-21 19:07:25 +01:00
$(DATADIR):
$(MAKE_DIR) $(DATADIR)
$(BINDIR):
$(MAKE_DIR) $(BINDIR)
install: $(OUT_ALL)
install: $(DATADIR)
install: $(BINDIR)
2014-12-21 19:31:10 +01:00
$(INSTALL_DIR) $(OUT_DIR) $(DATADIR)
2014-12-21 19:07:25 +01:00
$(INSTALL_FILE) $(MAKEFILE_DIR)systempony $(BINDIR)
uninstall:
$(UNINSTALL_DIR) $(DATADIR)
$(UNINSTALL_FILE) $(BINDIR)/systempony
$(call REMOVE_DIR, $(DATADIR) $(DATAROOT) $(BINDIR))
2014-12-21 19:17:07 +01:00
#touch output files to avoid re-generations (eg: after cloning)
touchput:
2014-12-21 19:31:10 +01:00
find $(PONY_DIR) -name '*.txt' -exec touch {} \;
find $(OUT_DIR) -exec touch {} \;
find $(OUT_DIR) -name '*.png' -exec touch {} \;
2016-05-24 13:52:14 +02:00
$(SCRIPT_INTERPRETER): $(MAKEFILE_DIR)patsi/setup-env.sh
$(SCRIPT_INTERPRETER): $(MAKEFILE_DIR)patsi/requirements.pip
$(MAKEFILE_DIR)patsi/setup-env.sh