clean up makefile

This commit is contained in:
Sebastian Hugentobler 2022-04-18 15:46:53 +02:00
parent 391ea7059a
commit e59d496f0f
Signed by: shu
GPG Key ID: BB32CF3CA052C2F0

View File

@ -1,75 +1,70 @@
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
WORKING_DIR := $(patsubst %/,%,$(dir $(mkfile_path))) WORKING_DIR := $(patsubst %/,%,$(dir $(mkfile_path)))
BOOKNAME=kommersbuch BOOKNAME=kommersbuch
SRC_DIR=src SRC_DIR=src
BUILD_DIR=build BUILD_DIR=build
TMP_DIR=tmp TMP_DIR=tmp
SONG_DIR=${SRC_DIR}/songs SONG_DIR=$(SRC_DIR)/songs
BUILD_BOOK_DIR=${BUILD_DIR}/books BUILD_BOOK_DIR=$(BUILD_DIR)/books
TMP_BOOK_DIR=${TMP_DIR}/books TMP_BOOK_DIR=$(TMP_DIR)/books
BUILD_SONG_DIR=${BUILD_DIR}/songs BUILD_SONG_DIR=$(BUILD_DIR)/songs
TMP_SONG_DIR=${TMP_DIR}/songs TMP_SONG_DIR=$(TMP_DIR)/songs
BUILD_MIDI_DIR=${BUILD_DIR}/midi BUILD_MIDI_DIR=$(BUILD_DIR)/midi
TMP_MIDI_DIR=${TMP_DIR}/midi TMP_MIDI_DIR=$(TMP_DIR)/midi
BUILD_OPUS_DIR=${BUILD_DIR}/opus BUILD_OPUS_DIR=$(BUILD_DIR)/opus
LY_FILES=$(wildcard ${SONG_DIR}/*.ly) BOOK_TYPES=folio quarto sexto octavo
LY_PDFS=$(patsubst %.ly,${BUILD_SONG_DIR}/%.pdf,$(notdir ${LY_FILES}))
LY_TMP_PDFS=$(patsubst %.ly,${TMP_SONG_DIR}/%.pdf,$(notdir ${LY_FILES})) LY_FILES=$(wildcard $(SONG_DIR)/*.ly)
LY_MIDIS=$(patsubst %.ly,${BUILD_MIDI_DIR}/%.midi,$(notdir ${LY_FILES})) LY_PDFS=$(patsubst %.ly,$(BUILD_SONG_DIR)/%.pdf,$(notdir $(LY_FILES)))
LY_TMP_MIDIS=$(patsubst %.ly,${TMP_MIDI_DIR}/%.midi,$(notdir ${LY_FILES})) LY_TMP_PDFS=$(patsubst %.ly,$(TMP_SONG_DIR)/%.pdf,$(notdir $(LY_FILES)))
LY_OPUS=$(patsubst %.ly,${BUILD_OPUS_DIR}/%.opus,$(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)))
.PHONY: book songs midi opus clean all .PHONY: book songs midi opus clean all
.DEFAULT_GOAL := all .DEFAULT_GOAL := all
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: %.dir:
mkdir -p $* mkdir -p $*
${TMP_SONG_DIR}/%.pdf: ${SONG_DIR}/%.ly ${SONG_DIR}/%.tex | ${TMP_SONG_DIR}.dir $(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 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
${BUILD_MIDI_DIR}/%.midi: ${TMP_MIDI_DIR}/%-1.midi | ${BUILD_MIDI_DIR}.dir $(BUILD_MIDI_DIR)/%.midi: $(TMP_MIDI_DIR)/%-1.midi | $(BUILD_MIDI_DIR).dir
cp $< $@ cp $< $@
${TMP_MIDI_DIR}/%-1.midi: ${SONG_DIR}/%.ly | ${TMP_MIDI_DIR}.dir $(TMP_MIDI_DIR)/%-1.midi: $(SONG_DIR)/%.ly | $(TMP_MIDI_DIR).dir
lilypond --output=${TMP_MIDI_DIR} ${WORKING_DIR}/$< lilypond --output=$(TMP_MIDI_DIR) $(WORKING_DIR)/$<
${BUILD_OPUS_DIR}/%.opus: ${BUILD_MIDI_DIR}/%.midi | ${BUILD_OPUS_DIR}.dir $(BUILD_OPUS_DIR)/%.opus: $(BUILD_MIDI_DIR)/%.midi | $(BUILD_OPUS_DIR).dir
timidity $< -Ow -o - | opusenc - $@ timidity $< -Ow -o - | opusenc - $@
${TMP_BOOK_DIR}/%.pdf: ${SRC_DIR}/%.tex ${SRC_DIR}/images/title.png | ${TMP_BOOK_DIR}.dir $(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} $< latexmk -cd -lualatex -e '$$lualatex=q/lualatex %O -shell-escape %S/' -output-directory=$(WORKING_DIR)/$(TMP_BOOK_DIR) $<
rm -r ${SRC_DIR}/tmp-ly rm -r $(SRC_DIR)/tmp-ly
${TMP_BOOK_DIR}/%-folio.pdf: ${TMP_BOOK_DIR}/%.pdf $(BUILD_DIR)/%.pdf: $(TMP_DIR)/%.pdf | $(BUILD_BOOK_DIR).dir $(BUILD_SONG_DIR).dir
cd ${TMP_BOOK_DIR} && \
../../bin/makebook -v -t folio -i $(notdir $<) -o $(notdir $@)
#long edge binding
${TMP_BOOK_DIR}/%-quarto.pdf: ${TMP_BOOK_DIR}/%.pdf
cd ${TMP_BOOK_DIR} && \
../../bin/makebook -v -t quarto -i $(notdir $<) -o $(notdir $@)
${TMP_BOOK_DIR}/%-sexto.pdf: ${TMP_BOOK_DIR}/%.pdf
cd ${TMP_BOOK_DIR} && \
../../bin/makebook -v -t sexto -i $(notdir $<) -o $(notdir $@)
#short edge binding
${TMP_BOOK_DIR}/%-octavo.pdf: ${TMP_BOOK_DIR}/%.pdf
cd ${TMP_BOOK_DIR} && \
../../bin/makebook -v -t octavo -i $(notdir $<) -o $(notdir $@)
${BUILD_DIR}/%.pdf: ${TMP_DIR}/%.pdf | ${BUILD_BOOK_DIR}.dir ${BUILD_SONG_DIR}.dir
cp $< $@ cp $< $@
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} 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} songs: $(LY_PDFS)
midi: ${LY_MIDIS} midi: $(LY_MIDIS)
opus: ${LY_OPUS} opus: $(LY_OPUS)
all: book songs midi opus all: book songs midi opus
clean: clean:
rm -rf ${BUILD_DIR} rm -rf $(BUILD_DIR)
rm -rf ${TMP_DIR} rm -rf $(TMP_DIR)
rm -r ${SRC_DIR}/tmp-ly rm -rf $(SRC_DIR)/tmp-ly