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)))
WORKING_DIR := $(patsubst %/,%,$(dir $(mkfile_path)))
BOOKNAME=kommersbuch
SRC_DIR=src
BUILD_DIR=build
TMP_DIR=tmp
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
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
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}))
BOOK_TYPES=folio quarto sexto octavo
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)))
.PHONY: book songs midi opus clean 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:
mkdir -p $*
${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
$(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
${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 $< $@
${TMP_MIDI_DIR}/%-1.midi: ${SONG_DIR}/%.ly | ${TMP_MIDI_DIR}.dir
lilypond --output=${TMP_MIDI_DIR} ${WORKING_DIR}/$<
$(TMP_MIDI_DIR)/%-1.midi: $(SONG_DIR)/%.ly | $(TMP_MIDI_DIR).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 - $@
${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
$(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
${TMP_BOOK_DIR}/%-folio.pdf: ${TMP_BOOK_DIR}/%.pdf
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
$(BUILD_DIR)/%.pdf: $(TMP_DIR)/%.pdf | $(BUILD_BOOK_DIR).dir $(BUILD_SONG_DIR).dir
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}
songs: ${LY_PDFS}
midi: ${LY_MIDIS}
opus: ${LY_OPUS}
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)
all: book songs midi opus
clean:
rm -rf ${BUILD_DIR}
rm -rf ${TMP_DIR}
rm -r ${SRC_DIR}/tmp-ly
rm -rf $(BUILD_DIR)
rm -rf $(TMP_DIR)
rm -rf $(SRC_DIR)/tmp-ly