-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
265 lines (223 loc) · 8.82 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# To make the document with the default settings:
# > make
#
# To make with a specific format:
# > make <format>
#
# To tar up a flat version of a specific format:
# > make <format> tar
#
# Alex Drlica-Wagner: https://github.com/LSSTDESC/start_paper/issues/new?body=@kadrlica
# Primary file names - avoid cookiecutter variables, to enable `make
# upgrade` to cleanly over-write this Makefile...
main ?= example
#default=$(shell cat .metadata.json | grep 'default_format' | cut -d'"' -f4)
outname ?= $(notdir $(shell pwd))
#ifeq ($(default), {{ cookiecutter.default_format }})
style ?= lsstdescnote
#else
# style=${default}
#endif
# 'note' shall be an alias for 'lsstdescnote'
ifeq ($(style),note)
style = lsstdescnote
endif
# mkauthlist doesn't recognize lsstdescnote as a style, so tell it to do something generic
ifeq ($(style),lsstdescnote)
mastyle = tex
else
mastyle = $(style)
endif
DESCTEX := desc-tex
DESCTEXORIGIN := git@github.com:LSSTDESC/desc-tex.git
localpip ?= F
PIPOPTS = --upgrade-strategy only-if-needed
ifeq ($(localpip),T)
MKAUTHBIN := bin/mkauthlist
MKAUTH := PYTHONPATH=$$(ls -d lib/python*/site-packages 2>/dev/null | head -n1):$$PYTHONPATH $(MKAUTHBIN)
PIPOPTS += --install-option="--prefix=$(PWD)"
GETMKAUTH := [ -e $(MKAUTHBIN) ] || pip install $(PIPOPTS) mkauthlist
else
MKAUTHBIN :=
MKAUTH := mkauthlist
GETMKAUTH := pip list 2>/dev/null | grep -q mkauthlist || pip install $(PIPOPTS) mkauthlist
endif
# LATEX environment variables
export TEXINPUTS:=./$(DESCTEX)/styles/:./tables/:
export BSTINPUTS:=./$(DESCTEX)/bst/:
export BIBINPUTS:=./$(DESCTEX)/bib/:
# LaTeX journal class switcher flags
# apj=\def\flag{apj}
# apjl=\def
# mnras=\def\flag{mnras}
# Submission flags (these need some thought)
# arxiv=\def\flag{emulateapj}
# submit=${aastex}
# draft=\def\linenums{\linenumbers}
# Files to copy when making tarball
tardir := tmp
figdir ?= ./figures
figures ?= $(figdir)/*.{png,jpg,pdf}
tabdir ?= ./tables
tables ?= $(tabdir)/*.tex
styles ?= ./$(DESCTEX)/styles/*.{sty,cls}
bibs ?= ./$(DESCTEX)/bib/*.bst
source = $(main).{tex,bbl,bib} $(DESCTEX)/bib/lsstdesc.bib $(DESCTEX)/ack/*.tex authors.tex contributions.tex
tarfiles = $(figures) $(tables) $(styles) $(bibs) $(source)
# prefix for difference files
DIFPRE ?= diff_
# git repo branch to compare changes against
BASEBRANCH ?= master
# git repo branch we are compiling
THISBRANCH := $(shell git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/' | tr -d ' ')
# temp file for the version to compare against
DRAFT = $(main).$(BASEBRANCH)
# base for difference files to generate
DIFF = $(DIFPRE)$(THISBRANCH)--$(BASEBRANCH)
maketargets := all authlist clean copy diff help $(main) update tar templates tidy touch
.PHONY: $(maketargets)
styleopts := aastex61 apj apjl emulateapj lsstdescnote mnras note prd prl tex
help:
@echo "Usage: make [style=lsstdescnote] [localpip=F] <target(s)>\n Possible targets: $(maketargets) <style> $(DESCTEX)\n all: equivalent to 'make $(main) copy'\n authlist: use mkauthlist to generate latex author/affiliation listing\n clean: remove latex temporary files AND compiled outputs\n copy: copy $(main).pdf to $(outname).pdf\n diff: if we're in a git repo, use latexdiff to compare the current $(main).tex vs the $(BASEBRANCH) branch, and attempt to compile to $(DIFF).pdf\n help: what you're looking at\n $(main): compile $(main).tex\n update: update desc-tex, mkauthlist, and templates repo\n tar: tar up latex source files to $(outname).tar.gz\n templates: download latest templates to templates/\n tidy: delete latex temporary files\n touch: touch $(main).tex to force a recompile\n <style>: equivalent to 'make style=<style> $(main) copy tar' (see style option)\n $(DESCTEX): download $(DESCTEX), which provides the DESC header logo and latex helper files\n Options for style: $(styleopts) (Anything else results in generic latex)\n Options for localpip: T or F. Set to T to install mkauthlist in this directory rather than systemwide"
# Interpret `make` with no target as `make tex` (a latex Note).
# At present, if the default_format is anything other than
# [apj|apjl|mnras|prd|prl|emulateapj], a latex Note is made.
# In future, we could think of using `make` to eg run the ipynb
# notebook and make PDF from the output, but this has not been
# implemented yet.
$(main): export flag = \def\flag{${style}}
envflag = \\def\\flag{${style}}
all: $(main) copy
copy:
cp ${main}.pdf ${outname}.pdf
touch:
touch ${main}.tex
# if we are in a git repo, add as a submodule; otherwise clone
$(DESCTEX):
if [ -d .git ]; then git submodule add $(DESCTEXORIGIN); else git clone $(DESCTEXORIGIN); fi
#http://journals.aas.org/authors/aastex/linux.html
#change the compiler call to allow a "." file
# {% raw %}
$(main) : $(DESCTEX) authlist
STYLEFLAG=$(envflag) latexmk $(main)
# latexmk -g -pdf \
-pdflatex='openout_any=a pdflatex %O -interaction=nonstopmode "${flag}\input{%S}"' \
${main}
# {% endraw %}
diff: $(DIFF).pdf
$(DIFF).pdf: $(DIFF).tex
STYLEFLAG=$(envflag) latexmk $<
$(DIFF).tex: $(DRAFT).tex $(main).tex
latexdiff --exclude-textcmd="multicolumn" $^ > $@
# this ensures that the version to latexdiff against is always updated
.PHONY: $(DRAFT).tex
$(DRAFT).tex:
if git show $(BASEBRANCH):$(main).tex > $@; then true; else echo "\n\n'make diff' is intended to be used inside a git repository\n"; false; fi
tar : $(main)
mkdir -p ${tardir}
cp ${tarfiles} ${tardir} | true
cp ${outname}.pdf ${tardir}/${outname}.pdf
cd ${tardir} && tar -czf ../${outname}.tar.gz . && cd ..
rm -rf ${tardir}
authlist: authors.tex
authors.tex : authors.csv
$(GETMKAUTH)
$(MKAUTH) -j ${mastyle} -f -c "LSST Dark Energy Science Collaboration" \
--cntrb contributions.tex authors.csv authors.tex
# pip install --upgrade mkauthlist
# http://stackoverflow.com/q/8028314/
.PHONY: $(styleopts)
$(styleopts): export style = $(@)
$(styleopts): export flag = \def\flag{$(@)}
$(styleopts):
$(MAKE) -e $(main)
$(MAKE) -e copy
$(MAKE) -e tar
# NB. the 'tex' target doesn't actually do anything in docswitch - make
# with no target compiles PDF out of main.tex using lsstdescnote.cls
# (which is to say, by default we assume you are writing an LSST
# DESC Note in latex format).
tidy:
rm -f *.log *.aux *.out *.dvi *.synctex.gz *.fdb_latexmk *.fls
rm -f *.bbl *.blg *Notes.bib ${main}.pdf
clean: tidy
rm -f ${outname}.pdf ${outname}.tar.gz
# Update the tex styles etc:
baseurl=https://raw.githubusercontent.com/LSSTDESC/start_paper/deploy
# UPDATES=\
# texmf/bib/apj.bst \
# texmf/bib/mnras.bst \
# texmf/styles/aas_macros.sty \
# texmf/styles/aastex.cls \
# texmf/styles/aastex61.cls \
# texmf/styles/aps_macros.sty \
# texmf/styles/docswitch.sty \
# texmf/styles/emulateapj.cls \
# texmf/styles/mnras.cls \
# texmf/styles/lsstdescnote.cls \
# texmf/styles/lsstdesc_macros.sty \
# texmf/logos/desc-logo-small.png \
# texmf/logos/desc-logo.png \
# texmf/logos/header.png \
# lsstdesc.bib \
# .travis.yml \
# figures/example.png
# .PHONY: $(UPDATES)
# $(UPDATES):
# curl -s -S -o $(@) ${baseurl}/$(@)
# @echo " "
update: templates
@echo Updating desc-tex
cd $(DESCTEX) && git pull
@echo
@echo Updating mkauthlist
pip install --upgrade $(PIPOPTS) mkauthlist
#@echo "\nOver-writing LaTeX style files with the latest versions: \n"
#@mkdir -p .logos figures texmf/styles texmf/bib
#$(MAKE) $(UPDATES)
# Get fresh copies of the templates etc, for reference:
# It is a bad idea to make these phony targets
TEMPLATES:=\
authors.csv \
main.ipynb \
main.md \
main.rst \
main.tex \
main.bib \
Makefile
#.metadata.json \
#.travis.yml
#figures/example.png
# #acknowledgments.tex \
ALLTEMPLATES := $(TEMPLATES) header.png
# .PHONY: $(TEMPLATES)
# $(TEMPLATES):
# curl -s -S -o templates/$(@) ${baseurl}/$(@)
# @echo " "
gettemplates := $(foreach t,$(TEMPLATES),curl -s -S -o templates/$(t) ${baseurl}/$(t); )
# NB: fetching header.png will fail as long as desc-tex is private
templates:
@echo "\nDownloading the latest versions of the template files, for reference: \n"
@mkdir -p templates
$(gettemplates)
curl -f -s -S -o templates/header.png https://raw.githubusercontent.com/LSSTDESC/desc-tex/master/logos/header.png || true
@echo
@echo templates/ listing:
@ls -a templates/*
@for f in $(ALLTEMPLATES); do diff -q $$f templates/$$f; true; done
#$(MAKE) $(TEMPLATES)
# $(MAKE) new
# Get a template copy of the latest Makefile, for reference:
# new:
# @echo "\nDownloading the latest version of the Makefile, for reference: \n"
# @mkdir -p templates
# curl -s -S -o templates/Makefile ${baseurl}/Makefile
# @echo " "
# Over-write this Makefile with the latest version:
# Why would we include this when a safe option already exists?
# upgrade:
# @echo "\nDownloading the latest version of the Makefile: \n"
# curl -s -S -o Makefile ${baseurl}/Makefile
# @echo "\nUpgrading version of mkauthlist: \n"
# pip install mkauthlist --upgrade --no-deps
# @echo "\nNow get the latest styles and templates with\n\n make update\n make templates\n"