-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
419 lines (390 loc) · 18.2 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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
####################################################################################
# Makefile (configuration file for GNU make - see http://www.gnu.org/software/make/)
#
# --------------------------------------------------------------------------------
# This is a generic makefile in the sense that it doesn't require to be
# modified when adding/removing new source files.
# --------------------------------------------------------------------------------
#
# Author: Sebastien Varrette <Sebastien.Varrette@uni.lu>
# Web page : http://www-id.imag.fr/~svarrett/
# Version : 1.2
# Creation date : 2012-07-24
#
# Compilation of files written in LaTeX
#
# This makefile search for LaTeX sources from the current directory, identifies
# the main files (i.e the one containing the sequence '\begin{document}') and
# launch the compilation for the generation of PDFs and optionnaly compressed
# Postscript files.
# Two compilation modes can be configured using the USE_PDFLATEX variable:
# 1/ Rely on pdflatex to generate directly a pdfs from the LaTeX sources.
# The compilation follow then the scheme:
#
# main.tex --[pdflatex/bibtex]--> main.pdf + main.[aux|log etc.]
#
# Note that in that case, your figures should be in pdf format instead of eps.
# To use this mode, just set the USE_PDFLATEX variable to 'yes'
#
# 2/ Respect the classical scheme: +-[dvips]-> main.ps
# | |
# | +-[gzip]
# main.tex -[latex/bibtex]-> main.dvi + main.[aux|log etc.]-+ |
# | +-> main.ps.gz
# +-[dvipdf]-> main.pdf
# To use this mode, just set the USE_PDFLATEX variable to 'no'
# In all cases:
# - all the intermediate files (main.aux, main.log etc.) will be moved
# to $(TRASH_DIR)/ (if it exists).
# - the dvi file (generated if pdflatex is not used) will stay in the current directory.
# - other target files (pdfs + compressed Postscript files if pdflatex is not used)
# are moved to the $(OUTPUT_DIR) directory.
# Note that this directory is automatically created if $(OUTPUT_DIR) differs from '.'
#
# Available Commands
# ------------------
# make : Compile LaTeX files, generated files (pdf etc.) are placed in $(OUTPUT_DIR)/
# make force : Force re-compilation, even if not needed
# make clean : Remove all generated files
# make rtf : Generate an RTF file using latex2rtf (useful for further
# copy/paste in a Word document)
# make html : generate HTML files from tex in $(HTML_DIR)/ (using latex2html)
# The directory is created on the first invocation
# make help : Print help message
# make setup : Initiate git-flow configuration for your local copy of the repository
# make start_bump_{major,minor,patch}: start a new version release with git-flow at a given
# level (major, minor or patch bump)
# make release: Finalize the release using git-flow
#
############################## Variables Declarations ##############################
SHELL = /bin/bash
# set to 'yes' to use pdflatex for the direct generation of pdf from LaTeX sources
# set to 'no' to use the classical scheme tex -> dvi -> [ps|pdf] by dvips
USE_PDFLATEX = yes
# Directory where PDF, Postcript files and other generated files will be placed
# /!\ Please ensure there is no trailing space after the values
OUTPUT_DIR = .
TRASH_DIR = .Trash
HTML_DIR = $(OUTPUT_DIR)/HTML
# Check avalibility of source files
TEX_SRC = $(wildcard *.tex)
ifeq ($(TEX_SRC),)
all:
@echo "No source files available - I can't handle the compilation"
@echo "Please check the presence of source files (with .tex extension)"
else
# Main tex file and figures it may depend on
MAIN_TEX = Tutorial_Latex.tex
FIGURES = $(shell find . -name "*.eps" -o -name "*.fig" | xargs echo)
ifeq ($(MAIN_TEX),)
all:
@echo "I can't find any .tex file with a '\begin{document}' directive "\
"among $(TEX_SRC). Please define a main tex file!"
else
# Commands used during compilation
LATEX = $(shell which latex)
PDFLATEX = $(shell which pdflatex)
LATEX2HTML = $(shell which latex2html)
BIBTEX = $(shell which bibtex)
DVIPS = $(shell which dvips)
DVIPDF = $(shell which dvipdf)
GZIP = $(shell which gzip)
LATEX2RTF = $(shell which latex2rtf)
GRB = $(shell which grb)
GITFLOW = $(shell which git-flow)
# Generated files
DVI = $(MAIN_TEX:%.tex=%.dvi)
PS = $(MAIN_TEX:%.tex=%.ps)
PS_GZ = $(MAIN_TEX:%.tex=%.ps.gz)
PDF = $(MAIN_TEX:%.tex=%.pdf)
RTF = $(MAIN_TEX:%.tex=%.rtf)
TARGET_PDF = $(PDF)
TARGET_PS_GZ = $(PS_GZ)
ifneq ($(OUTPUT_DIR),.)
TARGET_PDF = $(PDF:%=$(OUTPUT_DIR)/%)
TARGET_PS_GZ = $(PS_GZ:%=$(OUTPUT_DIR)/%)
endif
TARGETS = $(DVI) $(TARGET_PDF) $(TARGET_PS_GZ)
BACKUP_FILES = $(shell find . -name "*~")
# Files to move to $(TRASH_DIR) after compilation
# Never add *.tex (or any reference to source files) for this variable.
TO_MOVE = *.aux *.log *.toc *.lof *.lot *.bbl *.blg *.out
# Git stuff management
LAST_TAG_COMMIT = $(shell git rev-list --tags --max-count=1)
LAST_TAG = $(shell git describe --tags $(LAST_TAG_COMMIT) )
TAG_PREFIX = "latex-tutorial-v"
VERSION = $(shell head VERSION)
# OR try to guess directly from the last git tag
#VERSION = $(shell git describe --tags $(LAST_TAG_COMMIT) | sed "s/^$(TAG_PREFIX)//")
MAJOR = $(shell echo $(VERSION) | sed "s/^\([0-9]*\).*/\1/")
MINOR = $(shell echo $(VERSION) | sed "s/[0-9]*\.\([0-9]*\).*/\1/")
PATCH = $(shell echo $(VERSION) | sed "s/[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/")
# total number of commits
BUILD = $(shell git log --oneline | wc -l | sed -e "s/[ \t]*//g")
#REVISION = $(shell git rev-list $(LAST_TAG).. --count)
#ROOTDIR = $(shell git rev-parse --show-toplevel)
NEXT_MAJOR_VERSION = $(shell expr $(MAJOR) + 1).0.0-b$(BUILD)
NEXT_MINOR_VERSION = $(MAJOR).$(shell expr $(MINOR) + 1).0-b$(BUILD)
NEXT_PATCH_VERSION = $(MAJOR).$(MINOR).$(shell expr $(PATCH) + 1)-b$(BUILD)
.PHONY: all clean create_output_dir dvi force help html move_to_trash pdflatex ps release rtf setup start_bump_major start_bump_minor start_bump_patch test versioninfo
############################### Now starting rules ################################
# Required rule : what's to be done each time
all: $(TARGET_PDF)
ifeq ($(GRB),)
setup:
@echo "Unable to find the 'grb' binary. Install it to setup your git repository."
@echo "See https://github.com/webmat/git_remote_branch/ for more details"
else
setup:
grb grab production
git config gitflow.branch.master production
git config gitflow.branch.develop master
git config gitflow.prefix.feature feature/
git config gitflow.prefix.release release/
git config gitflow.prefix.hotfix hotfix/
git config gitflow.prefix.support support/
git config gitflow.prefix.versiontag $(TAG_PREFIX)
endif
versioninfo:
@echo "Current version: $(VERSION)"
@echo "Last tag: $(LAST_TAG)"
@echo "$(shell git rev-list $(LAST_TAG).. --count) commit(s) since last tag"
@echo "Build: $(BUILD) (total number of commits)"
@echo "next major version: $(NEXT_MAJOR_VERSION)"
@echo "next minor version: $(NEXT_MINOR_VERSION)"
@echo "next patch version: $(NEXT_PATCH_VERSION)"
# Git flow management - this should be factorized
ifeq ($(GITFLOW),)
start_bump_patch start_bump_minor start_bump_major release:
@echo "Unable to find git-flow on your system. "
@echo "See https://github.com/nvie/gitflow for installation details"
else
start_bump_patch:
@echo "Start the patch release of the repository from $(VERSION) to $(NEXT_PATCH_VERSION)"
git pull origin
git flow release start $(NEXT_PATCH_VERSION)
@echo $(NEXT_PATCH_VERSION) > VERSION
git commit -s -m "Patch bump to version $(NEXT_PATCH_VERSION)" VERSION
@echo "=> remember to update the version number in $(MAIN_TEX)"
@echo "=> run 'make release' once you finished the bump"
start_bump_minor:
@echo "Start the minor release of the repository from $(VERSION) to $(NEXT_MINOR_VERSION)"
git pull origin
git flow release start $(NEXT_MINOR_VERSION)
@echo $(NEXT_MINOR_VERSION) > VERSION
git commit -s -m "Minor bump to version $(NEXT_MINOR_VERSION)" VERSION
@echo "=> remember to update the version number in $(MAIN_TEX)"
@echo "=> run 'make release' once you finished the bump"
start_bump_major:
@echo "Start the major release of the repository from $(VERSION) to $(NEXT_MAJOR_VERSION)"
git pull origin
git flow release start $(NEXT_MAJOR_VERSION)
@echo $(NEXT_MAJOR_VERSION) > VERSION
git commit -s -m "Major bump to version $(NEXT_MAJOR_VERSION)" VERSION
@echo "=> remember to update the version number in $(MAIN_TEX)"
@echo "=> run 'make release' once you finished the bump"
release: $(TARGET_PDF)
@cp $(TARGET_PDF) $(TARGET_PDF:%.pdf=%-v$(VERSION).pdf)
git flow release finish -s $(VERSION)
git push origin
git push origin --tags
endif
# Dvi files generation
dvi $(DVI) : $(TEX_SRC) $(FIGURES)
@echo "==> Now generating $(DVI)"
@for f in $(MAIN_TEX); do \
$(LATEX) $$f; \
bib=`grep "^[\]bibliography{" $$f|sed -e "s/^[\]bibliography{\(.*\)}/\1/"|tr "," " "`;\
if [ ! -z "$$bib" ]; then \
echo "==> Now running BibTeX ($$bib used in $$f)"; \
$(BIBTEX) `basename $$f .tex`; \
$(LATEX) $$f; \
fi; \
$(LATEX) $$f; \
$(MAKE) move_to_trash; \
done
@echo "==> $(DVI) generated"
# Compressed Postscript generation
ps $(PS) $(TARGET_PS_GZ) : $(DVI)
@for dvi in $(DVI); do \
ps=`basename $$dvi .dvi`.ps; \
echo "==> Now generating $$ps.gz from $$dvi"; \
$(DVIPS) -q -o $$ps $$dvi; \
$(GZIP) -f $$ps; \
done
@if [ "$(OUTPUT_DIR)" != "." ]; then \
$(MAKE) create_output_dir; \
for ps in $(PS); do \
echo "==> Now moving $$ps.gz to $(OUTPUT_DIR)/"; \
mv $$ps.gz $(OUTPUT_DIR); \
done; \
fi
###################### The following part is specific for the case where pdflatex is used ######################
ifeq ("$(USE_PDFLATEX)", "yes")
pdflatex $(TARGET_PDF): $(TEX_SRC) $(FIGURES)
@echo "==> Now generating $(PDF)"
@for f in $(MAIN_TEX); do \
$(PDFLATEX) $$f; \
bib=`grep "^[\]bibliography{" $$f|sed -e "s/^[\]bibliography{\(.*\)}/\1/"|tr "," " "`;\
if [ ! -z "$$bib" ]; then \
echo "==> Now running BibTeX ($$bib used in $$f)"; \
$(BIBTEX) `basename $$f .tex`; \
$(PDFLATEX) $$f; \
fi; \
$(PDFLATEX) $$f; \
$(MAKE) move_to_trash; \
done
@if [ "$(OUTPUT_DIR)" != "." ]; then \
$(MAKE) create_output_dir; \
for pdf in $(PDF); do \
echo "==> Now moving $$pdf to $(OUTPUT_DIR)/"; \
mv $$pdf $(OUTPUT_DIR); \
done; \
fi
@$(MAKE) help
###################### End of specific case where pdflatex is used ######################
else
pdf $(TARGET_PDF): $(DVI)
@for dvi in $(DVI); do \
ps=`basename $$dvi .dvi`.pdf; \
echo "==> Now generating $$pdf from $$dvi"; \
$(DVIPDF) $$dvi; \
done
$(MAKE) create_output_dir
@if [ "$(OUTPUT_DIR)" != "." ]; then \
for pdf in $(PDF); do \
echo "==> Now moving $$pdf to $(OUTPUT_DIR)/"; \
mv $$pdf $(OUTPUT_DIR); \
done; \
fi
@$(MAKE) help
endif
###################### End of specific case where pdflatex is NOT used ######################
TO_TRASH=$(shell ls $(TO_MOVE) 2>/dev/null | xargs echo)
move_to_trash:
@if [ ! -z "${TO_TRASH}" -a -d $(TRASH_DIR) -a "$(TRASH_DIR)" != "." ]; then \
echo "==> Now moving ${TO_TRASH} to $(TRASH_DIR)/"; \
mv -f ${TO_TRASH} $(TRASH_DIR)/; \
elif [ ! -d $(TRASH_DIR) ]; then \
echo "*** /!\ The trah directory $(TRASH_DIR)/ does not exist!!!"; \
echo "*** May be you should create it to hide the files ${TO_TRASH}";\
fi;
create_output_dir:
@if [ ! -d $(OUTPUT_DIR) ]; then \
echo " /!\ $(OUTPUT_DIR)/ does not exist ==> Now creating ./$(OUTPUT_DIR)/"; \
mkdir -p ./$(OUTPUT_DIR); \
fi;
# Clean option
clean:
rm -f *.dvi $(RTF) $(TO_MOVE) $(BACKUP_FILES)
@if [ ! -z "$(OUTPUT_DIR)" -a -d $(OUTPUT_DIR) -a "$(OUTPUT_DIR)" != "." ]; then \
for f in $(MAIN_TEX); do \
base=`basename $$f .tex`; \
echo "==> Now cleaning $(OUTPUT_DIR)/$$base*"; \
rm -rf $(OUTPUT_DIR)/$$base*; \
done \
fi
@if [ "$(OUTPUT_DIR)" == "." ]; then \
for f in $(MAIN_TEX); do \
base=`basename $$f .tex`; \
echo "==> Now cleaning $$base.ps.gz and $$base.pdf"; \
rm -rf $$base.ps.gz $$base.pdf; \
done \
fi
@if [ ! -z "$(TRASH_DIR)" -a -d $(TRASH_DIR) -a "$(TRASH_DIR)" != "." ]; then \
for f in $(MAIN_TEX); do \
base=`basename $$f .tex`; \
echo "==> Now cleaning $(TRASH_DIR)/$$base*"; \
rm -rf $(TRASH_DIR)/$$base*; \
done \
fi
@if [ ! -z "$(HTML_DIR)" -a -d $(HTML_DIR) -a "$(HTML_DIR)" != "." ]; then \
echo "==> Now removing $(HTML_DIR)"; \
rm -rf $(HTML_DIR); \
fi
# force recompilation
force :
@touch $(MAIN_TEX)
@$(MAKE)
# Test values of variables - for debug purpose
test:
@echo "USE_PDFLATEX: $(USE_PDFLATEX)"
@echo "--- Directories --- "
@echo "OUTPUT_DIR -> $(OUTPUT_DIR)"
@echo "TRASH_DIR -> $(TRASH_DIR)"
@echo "HTML_DIR -> $(HTML_DIR)"
@echo "--- Compilation commands --- "
@echo "PDFLATEX -> $(PDFLATEX)"
@echo "LATEX -> $(LATEX)"
@echo "LATEX2HTML -> $(LATEX2HTML)"
@echo "LATEX2RTF -> $(LATEX2RTF)"
@echo "BIBTEX -> $(BIBTEX)"
@echo "DVIPS -> $(DVIPS)"
@echo "DVIPDF -> $(DVIPDF)"
@echo "GZIP -> $(GZIP)"
@echo "--- Files --- "
@echo "TEX_SRC -> $(TEX_SRC)"
@echo "MAIN_TEX -> $(MAIN_TEX)"
@echo "FIGURES -> $(FIGURES)"
@echo "BIB_FILES -> $(BIB_FILES)"
@echo "DVI -> $(DVI)"
@echo "PS -> $(PS)"
@echo "PS_GZ -> $(PS_GZ)"
@echo "PDF -> $(PDF)"
@echo "TO_MOVE -> $(TO_MOVE)"
@echo "TARGET_PS_GZ -> $(TARGET_PS_GZ)"
@echo "TARGET_PDF -> $(TARGET_PDF)"
@echo "TARGETS -> $(TARGETS)"
@echo "BACKUP_FILES -> $(BACKUP_FILES)"
# print help message
help :
@echo '+----------------------------------------------------------------------+'
@echo '| Available Commands |'
@echo '+----------------------------------------------------------------------+'
@echo '| make: Compile LaTeX files. |'
@echo '| Generated files (pdf etc.) are placed in $(OUTPUT_DIR)/ '
@echo '| make force: Force re-compilation, even if not needed |'
@echo '| make clean: Remove all generated files |'
@echo '| make html: Generate HTML files from TeX in $(HTML_DIR)/ '
@echo '| make help: Print help message |'
@echo '| make setup: Initiate git-flow for your local copy of the repository|'
@echo '| make start_bump_{major,minor,patch}: start a new version release with|'
@echo '| git-flow at a given level (major, minor or patch bump) |'
@echo '| make release: Finalize the release using git-flow |'
@echo '| make rtf: Generate an RTF file from LaTeX sources (useful for |'
@echo '| further copy/paste in a Word document) |'
@echo '+----------------------------------------------------------------------+'
# RTF generation using latex2rtf
rtf $(RTF): $(TARGET_PDF)
ifeq ($(LATEX2RTF),)
@echo "Please install latex2rtf to use this option!"
else
@echo "==> Now generating $(RTF)"
-cp $(TRASH_DIR)/*.aux $(TRASH_DIR)/*.bbl .
@for f in $(MAIN_TEX); do \
$(LATEX2RTF) -i english $$f; \
done
@$(MAKE) move_to_trash
@echo "==> $(RTF) is now generated"
@$(MAKE) help
endif
# HTML pages generation using latex2html
# First check that $(LATEX2HTML) and $(HTML_DIR)/ exist
html :
ifeq ($(LATEX2HTML),)
@echo "Please install latex2html to use this option!"
@echo "('apt-get install latex2html' under Debian)"
else
@if [ ! -d ./$(HTML_DIR) ]; then \
echo "$(HTML_DIR)/ does not exist => Now creating $(HTML_DIR)/"; \
mkdir -p ./$(HTML_DIR); \
fi
-cp $(TRASH_DIR)/*.aux $(TRASH_DIR)/*.bbl .
$(LATEX2HTML) -show_section_numbers -local_icons -split +1 \
-dir $(HTML_DIR) $(MAIN_TEX)
@rm -f *.aux *.bbl $(HTML_DIR)/*.tex $(HTML_DIR)/*.aux $(HTML_DIR)/*.bbl
@echo "==> HTML files generated in $(HTML_DIR)/"
@echo "May be you can try to execute 'mozilla ./$(HTML_DIR)/index.html'"
endif
endif
endif