Makefile.buildingblocks 11.4 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
# this is <Makefile.buildingblocks>
# ----------------------------------------------------------------------------
3
# $Id$
thomas.forbriger's avatar
thomas.forbriger committed
4
5
6
7
8
9
10
11
12
13
14
# 
# Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach) 
# 
# some building blocks for Makefiles
#
# The code in this file should be used by copy and paste operations to be
# added to individual Makefiles. Include operations are not appropriate, since
# this complicates reading dependencies across directories.
# 
# REVISIONS and CHANGES 
#    16/08/2010   V1.0   Thomas Forbriger
15
16
#    27/07/2011   V1.1   give precedence to $LOCINCLUDEDIR over 
#                        $SERVERINCLUDEDIR 
thomas.forbriger's avatar
thomas.forbriger committed
17
18
# 
# ============================================================================
19
20
21
22
23
24
25
 
PROGRAMS=fidase fidasex

.PHONY: all
all: install

.PHONY: install
26
27
install: $(addprefix $(LOCBINDIR)/,$(PROGRAMS))
$(LOCBINDIR)/%: %
28
29
	mkdir -pv $(dir $@)
	/bin/mv -fv $< $@
30

thomas.forbriger's avatar
thomas.forbriger committed
31
#
32
33
34
# This is the sequence of standard targets
# ----------------------------------------
# created by the template generator "new"
thomas.forbriger's avatar
thomas.forbriger committed
35
36
37
38
39
40
41
42
43
44
45
46

all:

flist: Makefile
	echo $^ | tr ' ' '\n' | sort > $@

.PHONY: edit
edit: flist; vim $<

.PHONY: clean
clean: ; 
	-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
47
	-/bin/rm -vf flist *.o *.d *.a $(PROGRAMS) *.xxx
thomas.forbriger's avatar
thomas.forbriger committed
48

thomas.forbriger's avatar
thomas.forbriger committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# ----------------------------------------------------------------------------
# advanced setup of flist

EDITFILES=$(MAINSRC) Makefile README $(wildcard *.cfg contrib/*.h) COPYING
EDITALL=$(EDITFILES) $(LIBHEADERS) $(LIBSRC) $(TESTSRC) $(EDITFILES)
EDITFORMATHEADERS=$(filter $(patsubst %/,%.h,$(SUBDIRS)),$(LIBHEADERS))
EDITROOT=$(filter-out $(EDITFORMATHEADERS),$(wildcard *.cc *.h))
EDITFIRST=$(filter-out $(LIBHEADERS) $(LIBSRC) $(TESTSRC),$(EDITALL))
EDITSECOND=$(filter-out $(TESTSRC) $(EDITROOT) $(EDITFIRST),$(EDITALL))

flist: $(LIBHEADERS) $(LIBSRC) $(TESTSRC) $(EDITFILES) 
	echo $(filter $(EDITFIRST),$^) | tr ' ' '\n' | sort > $@
	echo "----" >> $@
	echo $(filter $(EDITROOT),$^) | tr ' ' '\n' | sort >> $@
	echo "----" >> $@
	echo $(sort $(filter $(EDITSECOND),$^)) | tr ' ' '\n' >> $@
	echo "----" >> $@
	echo $(filter-out $(EDITSECOND) $(EDITROOT) $(EDITFIRST),$^) \
	  | tr ' ' '\n' | sort >> $@
	echo "----" >> $@
	echo $(TF_EDIT) | tr ' ' '\n' | sort >> $@

thomas.forbriger's avatar
thomas.forbriger committed
71
# ============================================================================
72
73
# a variable definition to check variable settings
# ------------------------------------------------
thomas.forbriger's avatar
thomas.forbriger committed
74

75
76
77
78
79
80
81
82
83
84
85
86
87
# if you want to check whether variable TF_PUBLICATIONPATH is non-empty,
# insert line
#
## $(call CHECKVAR,TF_PUBLICATIONPATH)
#
# in your Makefile
#
# if you want to check whether variable AVAR, BVAR, and CVAR are non-empty,
# insert line
#
## $(call CHECKVARS,AVAR BVAR CVAR)
#
# in your Makefile
88
89
90
#
# check mandatory environment variable settings
# ---------------------------------------------
91
92
93

CHECKVAR=$(if $($(1)),,$(error ERROR: missing variable $(1)))
CHECKVARS=$(foreach var,$(1),$(call CHECKVAR,$(var)))
thomas.forbriger's avatar
thomas.forbriger committed
94

95
96
97
$(call CHECKVARS,LOCINCLUDEDIR LOCLIBDIR LOCBINDIR)
$(call CHECKVARS,TF_BROWSER TF_WWWBASEDIR)

98
99
100
101
102
103
#----------------------------------------------------------------------

FLAGS += $(MYFLAGS) -fPIC
FFLAGS += -ff2c -Wall -ffixed-line-length-0 -fno-backslash $(FLAGS)
CFLAGS += $(FLAGS)
CXXFLAGS+=-Wall $(FLAGS)
104
105
LDFLAGS=$(addprefix -L,$(LOCLIBDIR) $(subst :, ,$(SERVERLIBDIR)))
CPPFLAGS=$(addprefix -I,$(LOCINCLUDEDIR) $(subst :, ,$(SERVERINCLUDEDIR))) \
106
107
  $(FLAGS)

108
109
110
111
112
#======================================================================
# Fortran dependencies
# --------------------
%.d: %.f
	echo $<: $(shell cat $< | egrep '^ +include' | cut -f 2 -d \' | sort | uniq) > $@
113
include $(patsubst %.f,%.d,$(wildcard *.f))
114

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#======================================================================
# dependencies
# ------------
#
# The compiler is used to create dependency files, which are included below.

%.d: %.cc
	$(SHELL) -ec '$(CXX) -M $(CPPFLAGS) $< \
      | sed '\''s,\($(notdir $*)\)\.o[ :]*,$(dir $@)\1.o $@ : ,g'\'' \
        > $@; \
      [ -s $@ ] || rm -f $@'

%.d: %.c
	$(SHELL) -ec '$(CC) -M $(CPPFLAGS) $< \
      | sed '\''s,\($(notdir $*)\)\.o[ :]*,$(dir $@)\1.o $@ : ,g'\'' \
        > $@; \
      [ -s $@ ] || rm -f $@'

133
include $(patsubst %.cc,%.d,$(SRCFILES)) 
134

thomas.forbriger's avatar
thomas.forbriger committed
135
136
137
138
139
140
141
142
143
144
145
146
#======================================================================
# source code generators
# ----------------------

# description and online texts
# ----------------------------
%.cc %.h: %.txt
	echo "// DO NOT EDIT: this file is automatically derived from $<" \
	  > $(patsubst %.txt,%.h,$<)
	echo "extern char $(patsubst %.txt,%,$<)[];" >> $(patsubst %.txt,%.h,$<)
	echo "// DO NOT EDIT: this file is automatically derived from $<" \
	  > $(patsubst %.txt,%.cc,$<)
thomas.forbriger's avatar
thomas.forbriger committed
147
	echo "#include \"$(patsubst %.txt,%.h,$<)\"" >> $(patsubst %.txt,%.cc,$<)
thomas.forbriger's avatar
thomas.forbriger committed
148
149
150
151
152
153
154
	echo "char $(patsubst %.txt,%,$<)[]=" >> $(patsubst %.txt,%.cc,$<)
	echo "{" >> $(patsubst %.txt,%.cc,$<)
	cat $< | egrep -v '^#' | sed -e 's/"/\\"/g' \
	  | sed -e 's/$$/\\n"/' | sed -e 's/^/  "/'\
	  >> $(patsubst %.txt,%.cc,$<)
	echo "};" >> $(patsubst %.txt,%.cc,$<)

155
156
157
158
159
160
161
162
163
164
165
166
#======================================================================
# header files
# ------------
#
# Since we extensively document the class structures within the header files,
# these should be stripped for the production version (otherwise the compiler
# has to scan all comments on each compile). Stripping is done by the rule
# below and is controlled by the variables REMCMMNT and EMPTYPRINT (see
# above).

# comment stripping
# -----------------
167
168
EMPTYPRINT=0
$(call CHECKVARS,TF_REMCMMNT EMPTYPRINT)
169
170
171
172
173
174
175

# awk rule assumes that the first non-comment line starts with '#'
# and that the first (copyright) comment end with pattern "^ */"
%.h.strip: %.h
	awk 'BEGIN {hot=1;} /^ \*\// { if (hot) { hot=2; print; next;} }\
        /^#/ { hot=0; } \
        { if (hot==2) { print ""; } else if (hot) { print; } }' $< > $@
176
	$(TF_REMCMMNT) $< | awk 'BEGIN {hot=0;} \
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
        /^ *$$/ { if ((hot) && ($(EMPTYPRINT))) { print ""; } next; } \
        /^#/ { hot=1; } { if (hot) print; }' >> $@

#----------------------------------------------------------------------
.PRECIOUS: %.h.strip
      
$(call CHECKVAR,INCINSTALLPATH)
$(INCINSTALLPATH)/%.h: %.h.strip
	mkdir -vp $(dir $@)
	-rm -fv $@
	/bin/cp -vpd $< $@

# install header files
# INSTHEADER contains full qualified paths to library header files
# like /home/thof/include/aff/series.h
# usually then INCINSTALLPATH=/home/thof/include/aff
thomas.forbriger's avatar
thomas.forbriger committed
193
.PHONY: install-include
194
195
196
197
198
199
200
201
202
203
204
205
206
207
install-include: $(INSTHEADER)

#======================================================================
# create the binary library
# -------------------------
LIBOBS=$(ALLOBS) $(patsubst %.cc,%.o,$(SRC))
LIBOBS=$(patsubst %.cc,%.o,$(SRC))

# INSTHEADER contains full qualified paths to library header files
# like /home/thof/include/aff/series.h
libaff.a: $(INSTHEADER) $(LIBOBS)
	ar rcv $@ $(LIBOBS)
	ranlib $@

208
209
libdatrwxx.so: $(patsubst %.cc,%.o,$(LIBSRC))
	$(CXX) $(CXXFLAGS) -shared -o $@ $^
210
211

LIBRARIES=libaff.a libdatrwxx.so
212

213
.PHONY: install
214
215
install: $(addprefix $(LOCLIBDIR)/,$(LIBRARIES))
$(LOCLIBDIR)/%: install-include %
216
217
	mkdir -pv $(dir $@)
	/bin/mv -fv $(word 2,$^) $@
218
219
220
221

# install-include where no header files are to be installed
.PHONY: install-include
install-include:
222

223
224
225
226
227
228
229
230
231
232
233
234
235
#======================================================================
# reinstall target
# is necessary in case of header file problems (e.g. remcmmnt not installed)
.PHONY: clean-include
clean-include: 
	/bin/rm -fv $(INSTHEADER)

.PHONY: reinstall
reinstall:
	$(MAKE) clean
	$(MAKE) clean-include
	$(MAKE) install

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#======================================================================
# documentation part
# ------------------
#
# targets commonly used:
# ----------------------
#
# make doxyclean        removes all documentation
# make doxydoc          creates doxygen documentation in the DOXYWWWPATH
# make doxyview         creates doxygen documentation and launches netscape to
#                       browse in the documentation
# make doxyconf         edit the doxygen configuration file
#
# If you launch "make doxydoc" the documentation will be written to
# DOXYWWWPATH (see below). This is meant to export the documentation through
# your homepage. The doxyfull directory is just a symbolic link to this
# directory.
#

thomas.forbriger's avatar
thomas.forbriger committed
255
$(call CHECKVARS,TF_WWWBASEDIR TF_BROWSER)
256

thomas.forbriger's avatar
thomas.forbriger committed
257
DOXYWWWPATH=$(TF_WWWBASEDIR)/libaff
258
259
260

.PHONY: doxyclean doxyview doxydoc doxyconf

261
doxyclean: ;/bin/rm -rfv $(DOXYWWWPATH) doxydoc.xxx
262
263
264
265
266
267

DOXYSRC=$(README) $(HEADERS) $(SRC) \
  tests/f77procs.P tests/f77procs.f \
  tests/f77common.inc tests/f77common_com.P

# create doxygen intermediate configuration
268
PWD=$(shell env pwd)
269
270
271
doxydoc.xxx: doxydoc.cfg
	sed 's,<OUTPUTDIRECTORY>,$(DOXYWWWPATH),g;s,<STRIPFROMPATH>,$(PWD),g' \
	  $< > $@
272
273
274
# create commented version of doxygen configuration
doxycomm.xxx: doxydoc.cfg
	/bin/cp -vf $< $@; doxygen -u $@
275
276
277
278
279
280
281
282
283
284

$(DOXYWWWPATH)/html/index.html: doxydoc.xxx $(DOXYSRC)
	mkdir -vp $(DOXYWWWPATH)
	doxygen $<

doxydoc: $(DOXYWWWPATH)/html/index.html

doxyview: $(DOXYWWWPATH)/html/index.html
	$(TF_BROWSER) file:$< &

thomas.forbriger's avatar
thomas.forbriger committed
285
286
287
288
289
290
#======================================================================
# ASCII documentation (Fortran and C code)
# ----------------------------------------
%.doc:
	/usr/bin/awk 'BEGIN{ hot=0; } \
        /^cS/ { hot=1; \
291
          print "  c"; \
292
	    print FILENAME; \
293
          print "  c"; \
thomas.forbriger's avatar
thomas.forbriger committed
294
295
296
297
298
299
300
301
302
303
          next; } \
        /^cE/ { hot=0; } \
        { if (hot==1) { print "  " $$0; } }' $^ > $@

%.doc: 
	/usr/bin/awk 'BEGIN{ hot=0; } \
        /^\/\*S\*\// { hot=1; next; } \
        /^\/\*E\*\// { hot=0; } \
        { if (hot==1) { print "  " $$0; } }' $^ > $@

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
#======================================================================
# comments
# --------
#
# Installation instructions
# -------------------------
# The command
#   make all
# will compile and install the binary executables as well as the doxygen
# documentation.
#
# Environment variables control where the results are stored and where
# libraries and library header files are expected:
#   LOCLIBDIR		defines location of binary libraries
#   LOCINCLUDEDIR 	defines location of C/C++ header files (prototypes)
#   LOCBINDIR		defines location of binary executables
#   TF_WWWBASEDIR 	defines location of doxygen output
#
# Dependencies:
#   Compilers required to build the programs:
#     C++ compiler
#     C/C++ preprocessor
#     doxygen (required to process source code documentation)
#
#   TFSoftware libraries required to compile the code:
#     libgsexx
#     libaff
#     libtime
#     libsffxx
#     libdatrwxx
#     libtfxx
#
#   Further non-standard libraries required to compile the code:
#     libboost_regex
#   
339
340
341
# Tests and examples are provided in subdirectory tests
#  
# Source code documentation is available in the output files of doxygen
342
 
343
344
345
346
347
348
349
350
351
352
353
354
355
#======================================================================
# reports
# -------

.PHONY: list-programs
list-programs:
	echo $(PROGRAMS) | tr ' ' '\n' | sort

.PHONY: list-libraries
list-libraries:
	grep ' -l' Makefile | tr ' ' '\n' | egrep '^-l' | sort | uniq
	
#
thomas.forbriger's avatar
thomas.forbriger committed
356
357
358
359
360
#======================================================================
# create package
# --------------
# is delegated to Makefile.packages
ifdef TF_MAKEPKG
thomas.forbriger's avatar
thomas.forbriger committed
361
362
363
364
365
366
367
368
369
370
371
372
373
374
.PHONY: package
package: $(TF_MAKEPKG)
	$(MAKE) -f $< \
	  PACKAGE=convsff \
	  PACKAGEEXPORT="trunk/src/conv/sff:src" \
	  PACKAGETARGETS="src:all" \
	  PACKAGELIBS="-"
.PHONY: fullpackage
fullpackage: $(TF_MAKEPKG)
	$(MAKE) -f $< \
	  PACKAGE=convsffwithlibs \
	  PACKAGEEXPORT="trunk/src/conv/sff:src" \
	  PACKAGETARGETS="src:all" \
	  PACKAGELIBS="libsff libtf libsffu libts libaff libtime libgsexx libsffxx libdatrwxx libtfxx libtsxx"
thomas.forbriger's avatar
thomas.forbriger committed
375
376
endif

thomas.forbriger's avatar
thomas.forbriger committed
377
# ----- END OF Makefile.buildingblocks -----