summaryrefslogtreecommitdiff
path: root/support/latexmake/makefile
blob: 66b9df37d67b94bbdb51f957e8bd934daaf2ed77 (plain)
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
################################################
# file: Makefile
# Makefile for latex
#
# @Author: SUN, Tong
# Copyright (c)2001, Tong SUN, all right reserved
# @Version: $Date: 2001/09/04 06:21:20 $ $Revision: 1.2.1.4 $
# @Home URL: http://xpt.sourceforge.net/
#
# CREDIT:
# Skeleton from: chris beggy chrisb@kippona.com
# Skeleton Id: skel-make-latex.el,v 1.3 2001/01/17 23:52:17 chrisb Exp 
#
# Readme begins:
# 
# This is a generic makefile to create output from a Latex file.
# 
# It will run the designated LaTeX FILE through TeX in turn until all
# cross-references are resolved, building all indices.  The directory
# containing each FILE is searched for included files.
# 
# It can also generate .html, .txt or .rtf files.
# 
# To get help, type 'make help'
# 
# Distribute freely, but please include the author's info & copyright,
# the file's version & url with the distribution.
# 
# Support free software movement! Please send you comments, suggestions, bug
# reports, patches to the author from the xpt project home URL. They are
# warmly welcome. Thank you for using the tools from the xpt project.
# 
# Readme ends.
#  cat Makefile | sed -n '/# [R]eadme /,/# [R]eadme / p' | cut -c3- > latexmake/README
# 
# {{{ Commentary:

#
#  To make the latex file latex_file.tex, issue:
#
#   make TEX_SOURCE_BASE=latex_file
#  or rather:
#   export TEX_SOURCE_BASE=latex_file
#   make
#  
# Basically you need to set the TEX_SOURCE_BASE variable before invoking make
# but using 'make check' can have 'make' makes suggestion for you: 
# If there is only one .tex file in current dirctory, make will suggest it.
# else suggest the directory name. For example, if the directory is named
# "thesis", make will assume that your will work on the file "thesis.tex".
# The benefit of setting this variable is that you can clean all the generated
# files easily using 'make clean'.

# If the TEX_DEST_DIR variable is set, all generated files (.ps, .pdf...) will
# end up in that particular directory. This is mandatory if you want to build
# an HTML (or .txt) version from the .tex file. The default is current dir.
#  
# It default makes only .dvi file, and no output unless errors occur
# You can also issue 'make view' to view the result right after the make
#
# To generate other formats, issue
#  
#   make ps
# and/or,
#   make pdf
#   make html
#   make txt
#   make rtf
#  
#  or simply:
#   make all rtf
#
# The general procedure would be
#   'make view' repeatly until you are fully satisfied
#   'make all', or 'make ps pdf html' for the final blast
#
#  Targets           Explanation
#  -------------------------------------------
#  dvi           dvi format
#  ps            postscript
#  pdf           pdf Adobe
#  html          for web browser
#  txt           normal plain text file
#  rtf           for M$ Word/WordPad
#
#  .tex          Latex source file 
#  .chk         check latex syntax with chktex
#
# The values of the BIBTEX, LATEX (or PDFLATEX), MAKEINDEX, MAKEINFO, TEX (or
# PDFTEX), and TEXINDEX environment variables are used to run those commands,
# if they are set.
#
# All tools used in this Makefile are well-known tools. They can all be easily
# located on the web using any search engines. Most of them may have already
# been included in your *nix distribution.
#

# }}} end commentary.
#
################################################

# {{{ Code:

# .............................................................. &ss ...
# here's the system dependent stuff
#

ifndef SYNTAXCHK
SYNTAXCHK = chktex
endif

ifndef LATEX
LATEX = texi2dvi -q
endif

ifndef DVIPS
DVIPS=dvips
endif

ifndef DVIVIEWER
DVIVIEWER=xdvi
endif

ifndef PDFLATEX
PDFLATEX = pdflatex
PDFLATEX = texi2pdf -q -p
PDFLATEX = ps2pdf
endif

ifndef LATEX2HTML
LATEX2HTML=latex2html -verbosity 0 -split 0 -nonavigation -dir ${TEX_DEST_DIR}
endif

ifndef HTML2TEXT
HTML2TEXT=w3m -dump -cols 78 
endif

ifndef LATEX2RTF
LATEX2RTF=`which ltx2rtf`
endif

ifndef MAKEFILE
MAKEFILE=Makefile
endif

# .............................................................. &ss ...
# here are the default rules
#


# Disable standard pattern rule:
%.dvi: %.tex

# Do not delete the following targets:
.PRECIOUS: %.chk %.aux %.bbl

%.chk: %.tex
#	$(SYNTAXCHK) -o $@ $< 
	latex $<
	@touch $@

# .dvi file is always generated to the current dir, 
# regardless of the ${TEX_DEST_DIR} setting
%.dvi: %.tex %.chk
	$(LATEX) $<

%.ps : %.dvi %.chk
	$(DVIPS) -o $@ $< 
	@[ $${TEX_DEST_DIR:+T} ] && mv $@ ${TEX_DEST_DIR} || true

%.pdf : %.ps %.tex %.chk
	$(PDFLATEX) $<
	@[ $${TEX_DEST_DIR:+T} ] && mv $@ ${TEX_DEST_DIR} || true

${TEX_DEST_DIR}/%.html : %.tex %.chk
	$(LATEX2HTML) $<
	rm -f ${TEX_DEST_DIR}/index.html ${TEX_DEST_DIR}/labels.pl ${TEX_DEST_DIR}/WARNINGS
	@printf "\n\n"

${TEX_DEST_DIR}/%.txt : ${TEX_DEST_DIR}/%.html
	@echo $(HTML2TEXT) $<
	@cd ${TEX_DEST_DIR}; \
	$(HTML2TEXT) $< | perl \
	-pn000e 's{\n\s*\n\s*\n-}{\n-}g; s/\n/\r\n/g; s/\xa0//g; exit if /^About this document \./' > $@
#	sed "s/$$/`printf '\r'`/" > $@

%.rtf : %.tex %.chk
	$(LATEX2RTF) $<
	@[ $${TEX_DEST_DIR:+T} ] && mv $@ ${TEX_DEST_DIR} || true

# .............................................................. &ss ...
# here are the targets
#

# default is to build dvi
# it will be recreated if any .tex in current dir changed

dvi : $(TEX_SOURCE_BASE).chk $(TEX_SOURCE_BASE).dvi

$(TEX_SOURCE_BASE).dvi: $(wildcard *.tex)

view: $(TEX_SOURCE_BASE).dvi
	$(DVIVIEWER) ${TEX_SOURCE_BASE}.dvi &

# You can change the 'meaning' of 'all' the way you want
# by adding or deleting targets
all :  dvi ps pdf txt 		# txt implies html

ps : $(TEX_SOURCE_BASE).ps
	@printf " == The $@ version of the target generated\n\n\n"

pdf : $(TEX_SOURCE_BASE).pdf
	@printf " == The $@ version of the target generated\n\n\n"

html : ${TEX_DEST_DIR}/$(TEX_SOURCE_BASE).html 
	@printf " == The $@ version of the target generated\n\n\n"

${TEX_DEST_DIR}/$(TEX_SOURCE_BASE).html: $(TEX_SOURCE_BASE).tex

txt : ${TEX_DEST_DIR}/$(TEX_SOURCE_BASE).txt
	@printf " == The $@ version of the target generated\n\n\n"

rtf : $(TEX_SOURCE_BASE).rtf
	@printf " == The $@ version of the target generated\n\n\n"

# .............................................................. &ss ...
# here is the source
#
#TEX_SOURCE_BASE is get from environment or command line

check:
# Make sure the TEX_SOURCE_BASE is set and help set it if not.
	@if [ $${TEX_SOURCE_BASE:+T} ]; then \
	  printf "TEX_SOURCE_BASE=${TEX_SOURCE_BASE}\nTEX_DEST_DIR=${TEX_DEST_DIR}\n"; \
	else  { \
		if [ `ls *.tex | wc -l` = "1" ]; then \
			TEX_SOURCE_BASE=`basename \`ls *.tex\` .tex`; \
			true; \
		else \
			TEX_SOURCE_BASE=`echo $$PWD|tr '/' '\n'|tail -1`; \
			true; \
		fi; \
	printf "\nPlease set\n\n export TEX_SOURCE_BASE=$$TEX_SOURCE_BASE\nor,\n setenv TEX_SOURCE_BASE $$TEX_SOURCE_BASE\n"; \
	}; fi

# .............................................................. &ss ...
.PHONY : help usage check clean cleangen clean-bak clean-th

help:
	@echo "To see the usage of this make file, type 'make usage'"
	@echo " (need to set the environment var MAKEFILE if you "
	@echo "  have change the default name/location of this Makefile"
	@echo "  which requires the -f parameter for the make)"

usage:
	@cat ${MAKEFILE} | sed -n '/ [Cc]ommentary/,/ [Cc]ommentary/ p' | cut -c3-
	@echo 
	@echo To get the help from the tools used:
	@echo type \'texi2pdf --help\'
#	texi2pdf --help

clean: 
	rm -f ${TEX_SOURCE_BASE}.chk ${TEX_SOURCE_BASE}.dvi ${TEX_SOURCE_BASE}.log ${TEX_SOURCE_BASE}.aux ${TEX_SOURCE_BASE}.bbl ${TEX_SOURCE_BASE}.blg ${TEX_SOURCE_BASE}.ilg ${TEX_SOURCE_BASE}.toc ${TEX_SOURCE_BASE}.lof ${TEX_SOURCE_BASE}.lot ${TEX_SOURCE_BASE}.idx ${TEX_SOURCE_BASE}.ind ${TEX_SOURCE_BASE}.out

cleangen :
	rm -f *.chk *.dvi *.log *.aux *.bbl *.blg *.ilg *.toc *.lof *.lot *.idx *.ind *.out *.ps *.pdf  

clean-bak : clean
	rm -f *~

clean-th : clean
	rm -f *.txt *.html *.css

# .............................................................. &ss ...

# }}}

## end of Makefile