49 lines
1.2 KiB
Makefile
49 lines
1.2 KiB
Makefile
.PHONY: all, clean
|
|
|
|
ifeq ($(origin IMAGE_DIR),undefined)
|
|
$(error $$IMAGE_DIR is not set)
|
|
endif
|
|
|
|
# Files for distribution
|
|
DIST_DIR ?= dist
|
|
# Temporary build artifacts
|
|
BUILD_DIR ?= build
|
|
|
|
images := $(shell find $(IMAGE_DIR) -iname '*.jpg')
|
|
image_names_cs := $(notdir $(images))
|
|
image_names := $(shell echo $(image_names_cs) | tr A-Z a-z)
|
|
dist_images := $(addprefix $(DIST_DIR)/,$(image_names))
|
|
|
|
extra_files := $(wildcard extra/*)
|
|
dist_extra_files := $(extra_files:%=dist/%)
|
|
|
|
define copy_image_rule =
|
|
$(DIST_DIR)/$(1): $(shell find $(IMAGE_DIR) -iname $(1))
|
|
@mkdir -p $(DIST_DIR)
|
|
cp --preserve $$< $$@
|
|
endef
|
|
|
|
build_metas := $(dist_images:$(DIST_DIR)/%.jpg=$(BUILD_DIR)/%.meta.json)
|
|
dist_html := $(dist_images:$(DIST_DIR)/%.jpg=$(DIST_DIR)/%.html)
|
|
|
|
### RULES ###
|
|
|
|
all: $(dist_html) $(dist_extra_files)
|
|
|
|
clean:
|
|
rm -rf $(DIST_DIR) $(BUILD_DIR)
|
|
|
|
$(foreach f,$(image_names),$(eval $(call copy_image_rule,$(f))))
|
|
|
|
$(BUILD_DIR)/%.meta.json: $(DIST_DIR)/%.jpg extract-metadata.py
|
|
@mkdir -p $(BUILD_DIR)
|
|
./extract-metadata.py --root $(DIST_DIR) $< > $@
|
|
|
|
$(DIST_DIR)/%.html: $(BUILD_DIR)/%.meta.json photo.hbs
|
|
@mkdir -p $(DIST_DIR)
|
|
handlebars-cli photo.hbs "$$(cat $<)" > $@
|
|
|
|
$(DIST_DIR)/extra/%: extra/%
|
|
@mkdir -p $(DIST_DIR)/extra
|
|
cp -r $< $@
|