kommersbuch/Makefile

71 lines
2.5 KiB
Makefile
Raw Normal View History

mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
WORKING_DIR := $(patsubst %/,%,$(dir $(mkfile_path)))
2022-04-18 13:46:53 +00:00
2017-11-08 10:07:22 +00:00
BOOKNAME=kommersbuch
SRC_DIR=src
BUILD_DIR=build
TMP_DIR=tmp
2022-04-18 13:46:53 +00:00
SONG_DIR=$(SRC_DIR)/songs
BUILD_BOOK_DIR=$(BUILD_DIR)/books
TMP_BOOK_DIR=$(TMP_DIR)/books
BUILD_SONG_DIR=$(BUILD_DIR)/songs
TMP_SONG_DIR=$(TMP_DIR)/songs
BUILD_MIDI_DIR=$(BUILD_DIR)/midi
TMP_MIDI_DIR=$(TMP_DIR)/midi
BUILD_OPUS_DIR=$(BUILD_DIR)/opus
BOOK_TYPES=folio quarto sexto octavo
2017-11-08 10:07:22 +00:00
2022-04-18 13:46:53 +00:00
LY_FILES=$(wildcard $(SONG_DIR)/*.ly)
LY_PDFS=$(patsubst %.ly,$(BUILD_SONG_DIR)/%.pdf,$(notdir $(LY_FILES)))
LY_TMP_PDFS=$(patsubst %.ly,$(TMP_SONG_DIR)/%.pdf,$(notdir $(LY_FILES)))
LY_MIDIS=$(patsubst %.ly,$(BUILD_MIDI_DIR)/%.midi,$(notdir $(LY_FILES)))
LY_TMP_MIDIS=$(patsubst %.ly,$(TMP_MIDI_DIR)/%.midi,$(notdir $(LY_FILES)))
LY_OPUS=$(patsubst %.ly,$(BUILD_OPUS_DIR)/%.opus,$(notdir $(LY_FILES)))
2017-11-08 10:07:22 +00:00
.PHONY: book songs midi opus clean all
2017-11-08 10:07:22 +00:00
.DEFAULT_GOAL := all
2022-04-18 13:46:53 +00:00
define BUILDER
$(TMP_BOOK_DIR)/%-$(TYPE).pdf: $(TMP_BOOK_DIR)/%.pdf
cd $(TMP_BOOK_DIR) && \
../../bin/makebook -v -t $(TYPE) -i $$(notdir $$<) -o $$(notdir $$@)
endef
$(foreach TYPE,$(BOOK_TYPES),$(eval $(BUILDER)))
%.dir:
mkdir -p $*
2017-11-08 10:07:22 +00:00
2022-04-18 13:46:53 +00:00
$(TMP_SONG_DIR)/%.pdf: $(SONG_DIR)/%.ly $(SONG_DIR)/%.tex | $(TMP_SONG_DIR).dir
cd $(SRC_DIR) && lualatex --jobname='$(notdir $(basename $@))' \
--output-directory=$(WORKING_DIR)/$(TMP_SONG_DIR) \
--shell-escape $(WORKING_DIR)/$(SRC_DIR)/song.tex \
$(WORKING_DIR)/$(SONG_DIR)/$(notdir $(basename $@)).ly $(WORKING_DIR)/$(SONG_DIR)/$(notdir $(basename $@)).tex
2017-11-08 10:07:22 +00:00
2022-04-18 13:46:53 +00:00
$(BUILD_MIDI_DIR)/%.midi: $(TMP_MIDI_DIR)/%-1.midi | $(BUILD_MIDI_DIR).dir
2017-11-08 10:07:22 +00:00
cp $< $@
2022-04-18 13:46:53 +00:00
$(TMP_MIDI_DIR)/%-1.midi: $(SONG_DIR)/%.ly | $(TMP_MIDI_DIR).dir
lilypond --output=$(TMP_MIDI_DIR) $(WORKING_DIR)/$<
2017-11-08 10:07:22 +00:00
2022-04-18 13:46:53 +00:00
$(BUILD_OPUS_DIR)/%.opus: $(BUILD_MIDI_DIR)/%.midi | $(BUILD_OPUS_DIR).dir
2017-11-08 10:07:22 +00:00
timidity $< -Ow -o - | opusenc - $@
2022-04-18 13:46:53 +00:00
$(TMP_BOOK_DIR)/%.pdf: $(SRC_DIR)/%.tex $(SRC_DIR)/images/title.png | $(TMP_BOOK_DIR).dir
latexmk -cd -lualatex -e '$$lualatex=q/lualatex %O -shell-escape %S/' -output-directory=$(WORKING_DIR)/$(TMP_BOOK_DIR) $<
rm -r $(SRC_DIR)/tmp-ly
2017-11-08 10:07:22 +00:00
2022-04-18 13:46:53 +00:00
$(BUILD_DIR)/%.pdf: $(TMP_DIR)/%.pdf | $(BUILD_BOOK_DIR).dir $(BUILD_SONG_DIR).dir
2017-11-08 10:07:22 +00:00
cp $< $@
2022-04-18 13:46:53 +00:00
book: $(BUILD_BOOK_DIR)/$(BOOKNAME).pdf $(BUILD_BOOK_DIR)/$(BOOKNAME)-folio.pdf $(BUILD_BOOK_DIR)/$(BOOKNAME)-quarto.pdf $(BUILD_BOOK_DIR)/$(BOOKNAME)-sexto.pdf $(BUILD_BOOK_DIR)/$(BOOKNAME)-octavo.pdf $(LY_FILES)
songs: $(LY_PDFS)
midi: $(LY_MIDIS)
opus: $(LY_OPUS)
2017-11-08 10:07:22 +00:00
all: book songs midi opus
clean:
2022-04-18 13:46:53 +00:00
rm -rf $(BUILD_DIR)
rm -rf $(TMP_DIR)
rm -rf $(SRC_DIR)/tmp-ly