Skip to content

Commit

Permalink
makefile support multicore compile
Browse files Browse the repository at this point in the history
  • Loading branch information
7sDream committed Feb 24, 2018
1 parent 5cbd027 commit 677e324
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/

## Core latex/pdflatex auxiliary files:
*.aux
*.lof
Expand All @@ -19,7 +21,6 @@
# these rules might exclude image files for figures etc.
# *.ps
# *.eps
scp*.pdf

## Generated if empty string is given at "Please type another file name for output:"
.pdf
Expand Down
49 changes: 25 additions & 24 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
SOURCE := scp.tex
VERSION := $(shell sed -n '/vhEntry/{n;p;}' changelog.tex | tail -n 1 | sed -nr 's/^\{([^}]+)\}.*/\1/p')
LATEXMKFLAG := -quiet -xelatex
OUTDIR := build
LATEXMKOUTDIR := -jobname=build
LATEXMKOUTDIR := -jobname=

$(info !!! Current version: ${VERSION})

scp.pdf:
$(info !!! Building test version: $@ ...)
scp.pdf: $(BUILDDIR)
$(info !!! Building test version: $ ...)
latexmk $(LATEXMKFLAG) ${SOURCE}

checkclean:
$(info !!! Checking if git repo is clean...)
@git diff --exit-code > /dev/null
@git diff --cached --exit-code > /dev/null

define build
$(info !!! Set target to $(1))
@sed -i -r -e 's/targetdevice\{(.*)\}/targetdevice{$(1)}/g' ${SOURCE}
$(info !!! Set font to $(2))
@sed -i -r -e 's/targetfonts\{(.*)\}/targetfonts{$(2)}/g' ${SOURCE}
$(info !!! Building $@ ...)
latexmk $(LATEXMKFLAG) $(LATEXMKOUTDIR)/$(3) ${SOURCE}
git checkout -- $(SOURCE)
mv $(OUTDIR)/$(3).pdf $(OUTDIR)/$(3)
find $(OUTDIR) -type f -not -name "*.pdf" -delete
$(info !!! Set font to $(2))
@sed -r -e 's/targetdevice\{(.*)\}/targetdevice{$(1)}/g' -e 's/targetfonts\{(.*)\}/targetfonts{$(2)}/g' ${SOURCE} > $(3).tex
$(info !!! Building $(3) ...)
@latexmk $(LATEXMKFLAG) $(LATEXMKOUTDIR)$(3) $(3).tex
@mv $(3).pdf $(3)
rm $(3).tex
endef

scp.pc.notofira.$(VERSION).pdf: checkclean
scp.pc.notofira.$(VERSION).pdf: $(BUILDDIR)
$(call build,pc,notofira,$@)

scp.pc.sarasa.$(VERSION).pdf: checkclean
scp.pc.sarasa.$(VERSION).pdf: $(BUILDDIR)
$(call build,pc,sarasa,$@)

scp.kindle.notofira.$(VERSION).pdf: checkclean
scp.kindle.notofira.$(VERSION).pdf: $(BUILDDIR)
$(call build,kindle,notofira,$@)

scp.kindle.sarasa.$(VERSION).pdf: checkclean
scp.kindle.sarasa.$(VERSION).pdf: $(BUILDDIR)
$(call build,kindle,sarasa,$@)

$(OUTDIR):
@mkdir -p $(OUTDIR)
$(BUILDDIR):
@mkdir -p $(BUILDDIR)

all: scp.pc.notofira.$(VERSION).pdf scp.pc.sarasa.$(VERSION).pdf scp.kindle.notofira.$(VERSION).pdf scp.kindle.sarasa.$(VERSION).pdf

clean:
git clean -dfX

cleanpdf:
-rm *.pdf

cleanall: clean cleanpdf

all: $(OUTDIR) scp.pc.notofira.$(VERSION).pdf scp.pc.sarasa.$(VERSION).pdf scp.kindle.notofira.$(VERSION).pdf scp.kindle.sarasa.$(VERSION).pdf
3 changes: 0 additions & 3 deletions preamble/page_format.tex
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
% ===== 页面整体格式控制 =====

% 工具包
\usepackage{etoolbox}

% 页面设置
\input{preamble/page_\targetdevice}

Expand Down
11 changes: 11 additions & 0 deletions scp.tex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
% So these two configures should be differ only in English monospaced characters
\def\targetfonts{notofira}

% make aux file different in different job
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@include}{\@input{#1.aux}}{\@input{#1-\jobname.aux}}{}{%
\errmessage{First patch of \noexpand\@include failed.}%
}
\patchcmd{\@include}{\@partaux #1.aux}{\@partaux#1-\jobname.aux}{}{%
\errmessage{Second patch of \noexpand\@include failed.}%
}
\makeatother

\include{preamble/index}

\include{editors}
Expand Down

0 comments on commit 677e324

Please sign in to comment.