Skip to content
Snippets Groups Projects
vars 4.52 KiB
Newer Older
  • Learn to ignore specific revisions
  • VERSION != git tag | tail -1
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    QR_TARGET != grep mailto: README.md | cut -d: -f2,3 | tail -c+2
    QR_CODE=\qrcode[height=.2\textwidth]{$(QR_TARGET)}
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    COMPRESS = gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dNOPAUSE -dQUIET -dBATCH -dPrinted=false -sOutputFile=$@ $<
    
    CP := ln -f
    
    BOOK != basename "$(shell pwd)"
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    TITLE != head -1 README.md | tail -c+3 | tr ' ' '_'
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    DROSS = rubbish
    
    DBOOK ?= $(DROSS)/$(BOOK).pdf
    COMPILER = latexmk -e '$$max_repeat=6' -file-line-error -output-directory=$(DROSS) -pdflua -interaction=nonstopmode -halt-on-error -shell-escape -r config/.latexmkrc
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    RELEASE = $(TITLE).pdf
    GLOS := makeglossaries -d $(DROSS)
    RUN := lualatex -output-directory $(DROSS) -shell-escape
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    # 'EXTERNAL_REFERENTS' will usually include 'core', and 'judgement',
    # so these lines will include '../aux/core.aux' and copy it to
    # 'rubbish/core.aux'.
    AUX_DIR = ../aux_share
    AUX_EXTERNAL = $(foreach referent, $(EXTERNAL_REFERENTS), \
    			$(wildcard $(AUX_DIR)/$(referent).aux) \
    	)
    
    AUX_REFERENCES = $(patsubst $(AUX_DIR)/%.aux, $(DROSS)/%.aux, $(AUX_EXTERNAL))
    
    
    DEPS += $(wildcard config/*.sty)
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    DEPS += $(AUX_REFERENCES)
    
    DEPS += $(wildcard *.tex)
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    .PHONY: book
    book: $(RELEASE) ## Compile the pdf
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    $(RELEASE): $(DBOOK)
    	@$(CP) $< $@
    
    
    $(DBOOK): main.tex $(DEPS)
    
    	$(COMPILER) -jobname=$(BOOK) $<
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    
    
    pdfs += $(RELEASE)
    
    %/:
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    	mkdir $@
    
    	echo '*' > $@.gitignore
    
    $(DROSS)/%.pdf: %.tex $(wildcard config/*.sty) | $(DROSS)/
    	$(COMPILER) -jobname=$(basename $(@F)) $<
    %.pdf: $(DROSS)/%.pdf
    	$(CP) $(DROSS)/$@ $@
    
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    $(DROSS)/%.pdf: %/main.tex $(wildcard config/*sty) | $(DROSS)/
    
    	$(COMPILER) -jobname=$(<D) $<
    
    $(AUX_REFERENCES): $(DROSS)/%.aux: $(AUX_DIR)/%.aux | $(DROSS)/
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    	cp $< $@
    
    .PHONY: refs
    refs: $(AUX_DIR)/$(BOOK).aux
    
    $(AUX_DIR)/$(BOOK).aux: $(DROSS)/$(BOOK).aux | $(AUX_DIR)/
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    	cp $< $@
    $(DROSS)/$(BOOK).aux: $(DBOOK)
    
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    qr.tex: README.md config/vars
    
    	printf '%s' '\qrcode[height=.2\textwidth]{$(QR_TARGET)}' > qr.tex
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    .switch-gls:
    
    	touch .switch-gls
    
    output += qr.tex .switch-gls svg-inkscape
    
    
    images/extracted/inclusion.tex: images/extracted/
    
    	printf '%s\n' '\externaldocument{$(BOOK)}' > $@
    
    	printf '%s\n' '\newcommand\bookTitle{$(TITLE)}' | tr '_' ' ' >> $@
    
    output += images/extracted/
    
    
    output += $(DROSS)/
    
    dependencies += git git-lfs lualatex latexmk inkscape
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    .PHONY: check
    check: ## Check you have the project dependencies
    
    	@$(foreach program, $(dependencies), \
    	command -v $(program) >/dev/null || { echo install $(program) && exit 1 ;} ;)
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    help: ## Print the help message
    	@awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z._-]+:.*?## / {printf "\033[36m%s\033[0m : %s\n", $$1, $$2}' $(MAKEFILE_LIST) | \
    		sort | \
    		column -s ':' -t
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    
    
    .PHONY: graph
    
    Malin Freeborn's avatar
    Malin Freeborn committed
    graph: ## Show a dependency graph (needs graph-easy and make2graph)
    
    	make -Bind $(TARG) | make2graph | graph-easy --boxart
    
    ######## Automated Materials Check ########
    
    text_shadows = $(patsubst $(DROSS)/%.pdf, $(DROSS)/%.txt, $(wildcard $(DROSS)/*.pdf))
    
    $(text_shadows): $(DROSS)/%.txt: $(DROSS)/%.pdf
    	pdftotext $< $@
    
    .PHONY: report
    report: $(text_shadows) ## Check for missing references and repetition in all pdfs.
    	@command -v pdftotext >/dev/null || { echo install pdftotext ; exit 1 ;}
    	@test -f '$<' || exit 1
    	@! grep -F '??' $^
    	@grep --color=always -nE '(\b\S+\b)\s+\b\1\b' $^ || echo "No problems found."
    
    
    ######## A3 12 signature pdfs ########
    A3_12_signature_%.pdf: %.pdf
    
    	pdfjam --landscape --paper a3paper --nup 1x1 --signature 12 $< -o $@
    
    A3_pdfs = $(patsubst %.pdf, A3_12_signature_%.pdf, $(pdfs))
    
    .PHONY: printables
    printables: $(A3_pdfs)
    
    
    ######## A7 pdf booklets ########
    
    # The A7 booklet has 16 pages to the signature
    layout = 16:
    
    # The layout lists page indexes, so '0' means 'page 1', and '0L' means 'page 1
    # but turn 90 degrees to the left'
    layout += 4L(1w,0h)+12L(1w,0.25h)+15L(1w,0.5h)+0L(1w,0.75h)+3R(0w,0.25h)+11R(0w,0.5h)+8R(0w,0.75h)+7R(0w,1h),
    
    # The first block ends with a comma, which indicates that we are working on the
    # back-page.
    layout += 5L(1w,0h)+10L(1w,0.25h)+9L(1w,0.5h)+6L(1w,0.75h)+2R(0w,0.25h)+13R(0w,0.5h)+14R(0w,0.75h)+1R(0w,1h)
    
    # 'make' adds spaces between variables, but `pstops` will not be happy with those spaces.
    a7_layout != printf '%s' '$(layout)' | tr -d ' '
    
    $(DROSS)/a7_%.ps: $(DROSS)/a7_%.pdf
    	pdftops $< $@
    
    $(DROSS)/onepage_%.ps: $(DROSS)/a7_%.ps
    	pstops -pa4 '$(a7_layout)' $< $@
    
    $(DROSS)/onepage_%.pdf: $(DROSS)/onepage_%.ps
    	ps2pdf $< $@
    
    %.pdf: $(DROSS)/onepage_%.pdf
    	$(CP) $< $@
    
    #################################
    
    targets += $(pdfs)
    output += $(targets)
    
    all: $(targets) ## All standard targets
    
    
    .PHONY: clean
    clean: ## Clean repo, including cross-reference files
    
    	$(RM) -r $(output) $(wildcard *.pdf)