Repository created.
[chemdb.git] / docs / Makefile
1 # Produce html, pdf, and dvi output from latex source
2 # W. Trevor King, 2008, version 0.2
3 # This file is in the public domain.
4 #
5 # exposed targets :
6 #  all          : generate each of the outputs (pdf, html, dvi) and call view
7 #  view         : call '$(PDF_VIEWER) main.pdf &' to see the pdf file
8 #  install      : call install_% for pdf, html, dvi, and dist
9 #  clean        : semi-clean and remove the $(GENERATED_FILES) as well
10 #  semi-clean   : remove all intermediate $(TEMP_FILES) used during generation
11 #
12 #  pdf          : generate the pdf file (Portable Document Format)
13 #  install_pdf  : install the dvi file (currently no action)
14 #  html         : generate html directory ready for posting
15 #  install_html : scp the html directory to $(INSTALL_HTML)
16 #  dvi          : generate main.dvi (DeVice Independent file)
17 #  install_dvi  : install the dvi file (currently no action)
18 #  dist         : gen. $(DOC_NAME)-$(VERSION).tar.gz containing $(DIST_FILES)
19 #  install_dist : install the dist file (currently no action)
20 #
21 #  images       : call for generation of all images in $(IMAGES)
22
23 DOC_NAME = chem_inventory
24 VERSION = 0.2
25
26 # I like to keep my images in seperate directories, where any processing
27 # they may need woln't clutter up the base directory with temp files.
28 # To control these, this Makefile calls the Makefiles in the IMAGE_DIRS,
29 # so make sure they exist, and have the following targets:
30 #  clean      : remove all generated files
31 #  semi-clean : remove all intermediate files
32 # for each image in IMAGE, you must have a rule that generates it,
33 # see 'image generation rules' below
34 IMAGES = mp/NFPA.1
35 IMAGE_DIRS = mp
36
37 # Non image source files
38 SOURCE_FILES = main.tex *.tex
39 # And anything else you'd like to distribute
40 OTHER_FILES = README Makefile
41
42 DIST_FILES = $(SOURCE_FILES) $(OTHER_FILES) $(IMAGE_DIRS)
43
44 # Select where to put things when you call the dist and install targets
45 DIST_DIR = $(DOC_NAME)-$(VERSION)
46 DIST_NAME = $(DOC_NAME)-$(VERSION).tar.gz
47 INSTALL_PDF = $(HOME)/rsrch/notes
48 INSTALL_DVI = 
49 INSTALL_HTML = einstein:./public_html/rsrch/papers/$(DOC_NAME)
50 # interpreted as latex by latex2html, so escape the '~' to '\~{}' 
51 TILDE = "%7E"
52 CSS_PATH = "/$(TILDE)wking/shared/style_l2h.css"
53
54 # Files removed on clean or semi-clean
55 TEMP_FILES = *[.]aux *[.]log *[.]out *[.]bak \
56         *.png *.eps
57 # Files removed only on clean
58 GENERATED_FILES = $(DIST_NAME) \
59         rm -f main.pdf main.dvi html *.pdf
60
61 PDF_VIEWER = xpdf # you can also try evince, acroread, 'xpdf -view H', etc. 
62
63 ## image generation rules, to handle the images in $(IMAGES)
64
65 mp/NFPA.1 : 
66         $(MAKE) -C mp images
67
68
69
70 ### The remaining rules shouldn't need to be changed
71
72 # pdf, dvi, and html depend on images
73 images : $(IMAGES)
74
75
76 ## Big targets
77 all : pdf html dvi view
78
79 view : pdf
80         $(PDF_VIEWER) main.pdf &
81
82 install : install_pdf install_html install_dvi install_dist
83
84 clean : semi-clean $(IMAGE_DIRS:%=%_clean)
85         rm -rf $(GENERATED_FILES)
86
87 semi-clean : $(IMAGE_DIRS:%=%_semi-clean)
88         rm -f $(TEMP_FILES)
89
90
91 ## Mid-level indirection targets
92
93 # indirection, so we can have short names like 'pdf'
94 # without rebuilding when it's not neccessary
95 pdf : main.pdf
96 dvi : main.dvi
97 dist : $(DIST_NAME)
98
99
100 ## Installation targets
101
102 install_pdf :
103 install_html : html clean_html_image_dirs
104         scp -r html $(INSTALL_HTML)
105 install_dvi :
106 install_dist :
107
108
109 ## The meat of the generation
110
111 # generate the pdf output directly with pdflatex
112 main.pdf : main.aux $(SOURCE_FILE) images
113         pdflatex main.tex
114
115 # generate html files, including the DIST_FILES in a subdir.
116 # latex2html requires main.aux to generate figure numbers
117 # main.pdf is for the '$(DOC_NAME).pdf' link in the footer
118 # (see ~/.latex2html-init) 
119 html : $(SOURCE_FILES) main.aux main.pdf
120         latex2html -split 1 -white -notransparent -html_version 3.2 \
121             -t $(DOC_NAME) -dir html -mkdir \
122             -noshort_extn -top_navigation -bottom_navigation \
123             -up_url '../' -up_title 'Papers' \
124             -show_section_numbers \
125             -style $(CSS_PATH) \
126             main.tex    # generate the html
127         if [ ! -d html/src ]; then  mkdir html/src ; fi # mk src if it doesn't exist yet
128         cp -r $(DIST_FILES) html/src/     # move the source files into html/src 
129         cp main.pdf html/$(DOC_NAME).pdf  # move the pdf in so we can link to it
130
131 # generate the .aux file which contains labels for referencing
132 # needed to correctly number references in the pdf and html output.
133 # (Clash between latex and pdflatex's .aux files? semi-clean fixes)
134 # -draftmode makes pdflatex ignore images and not make a pdf (faster)
135 main.aux : *.tex images
136         pdflatex -draftmode main.tex
137
138 # to stretch our .tex files a bit more, make a dvi as well :p
139 # run twice to straighten out and TOC or references issues
140 main.dvi : $(SOURCE_FILES) images
141         latex main.tex
142         latex main.tex
143
144 # generate a gzipped tar file containing the DIST_FILES
145 $(DIST_NAME) : $(DIST_FILES)
146         mkdir $(DIST_DIR)
147         cp $(DIST_FILES) $(DIST_DIR)
148         tar -chozf $(DIST_NAME) $(DIST_DIR)
149         rm -rf $(DIST_DIR)
150
151
152 ## IMAGE_DIR handling rules
153
154 # call clean for any image directory
155 %_clean : %
156         $(MAKE) -C $< clean
157
158 # call semi-clean for any image directory
159 %_semi-clean : %
160         $(MAKE) -C $< semi-clean
161
162 # clean and junk that was in the working image directories
163 clean_html_image_dirs : $(IMAGE_DIRS:%=%_html_dir_clean)
164
165 # call clean for any image directory in the html/src directory
166 %_html_dir_clean : %
167         $(MAKE) -C html/src/$< clean