Makefile 8.97 KB
Newer Older
Tilman Steinweg's avatar
Tilman Steinweg committed
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
# this is <Makefile>
# ----------------------------------------------------------------------------
# 
# Copyright (c) 2011 by Thomas Forbriger (BFO Schiltach) 
# 
# create library for source wavelet correction filter determination (libstfinv)
#
# ----
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. 
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# ----
#
# See the README and the doxygen documentation for a list of libraries
# required in addition to libstfinv.
# 
# REVISIONS and CHANGES 
28
29
#    05/05/2011   V1.0   Thomas Forbriger (thof)
#    03/02/2014 thof:	 do not strip comments from header files
Tilman Steinweg's avatar
Tilman Steinweg committed
30
31
32
33
#
# ============================================================================
#

34
35
CONTRIBDIR=..
include $(CONTRIBDIR)/Makefile_var
Tilman Steinweg's avatar
Tilman Steinweg committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

.PHONY: all
all: install doxydoc

.PHONY: doc
doc: doxydoc

LIBRARIES=libstfinv.a

.PHONY: install
install: $(addprefix $(LOCLIBDIR)/,$(LIBRARIES))
$(LOCLIBDIR)/%: install-include %
	mkdir -pv $(LOCLIBDIR)
	/bin/mv -fv $(word 2,$^) $(LOCLIBDIR)

# ============================================================================
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
# select groups of files 
# they are used for editing and to create object file lists and dependencies

# whereever we find a README, we will use it
README=$(filter-out %.bak,$(shell find . -name README\*))
# the frame of doxygen documentation is palced in text files
DOXYTXT=$(shell find . -name doxygen\*.txt)
# C++ and C source code
SOURCEFILES=$(filter-out %usage.h, $(filter-out %usage.cc, \
		$(wildcard *.h *.cc *.c tests/*.cc tests/*.c tests/*.inp) \
	    $(wildcard test*/src/*.c) \
	    $(wildcard test*/src/*.h) \
	    $(wildcard test*/src/LEGAL*h)))
# LaTeX formatted documentation
DOCFILES=$(wildcard doc/*.tex doc/Makefile)
# end-user usage information
USAGEFILES=$(wildcard usage/*usage.txt)
# editional files to be edited
EDITFILES=Makefile $(README) \
	    $(DOXYTXT) $(DOCFILES) $(USAGEFILES) \
	    $(SOURCEFILES) \
	    $(wildcard *.cfg) \
	    $(wildcard test*/src/Makefile) \
	    COPYING
# ============================================================================
# check for settings expected in the environment
# ----------------------------------------------
Tilman Steinweg's avatar
Tilman Steinweg committed
79
80
81
82
83
84
85
86
#
CHECKVAR=$(if $($(1)),,$(error ERROR: missing variable $(1)))
CHECKVARS=$(foreach var,$(1),$(call CHECKVAR,$(var)))
#

$(call CHECKVARS,LOCINCLUDEDIR LOCLIBDIR LOCBINDIR)
$(call CHECKVARS,TF_BROWSER TF_WWWBASEDIR)

87
88
89
90
91
92
93
# ======================================================================
#
LIBHEADERS=$(filter-out none,$(wildcard *.h)) \
	     $(patsubst usage/%.txt,%.h,$(USAGEFILES))

LIBCCSRC=$(filter-out none,$(wildcard *.cc)) \
	   $(patsubst usage/%.txt,%.cc,$(USAGEFILES))
Tilman Steinweg's avatar
Tilman Steinweg committed
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

LIBCSRC=$(filter-out none,$(wildcard *.c))

TESTHEADERS=$(wildcard tests/*.h)

TESTCCSRC=$(wildcard tests/*.cc)
TESTCSRC=$(wildcard tests/*.c)

TESTCCBIN=$(patsubst tests/%.cc,%,$(TESTCCSRC))
TESTCBIN=$(patsubst tests/%.c,%,$(TESTCSRC))

INCINSTALLPATH=$(LOCINCLUDEDIR)/stfinv
LIBINSTALLPATH=$(LOCLIBDIR)

# name of installed (exported) header files
INSTHEADER=$(addprefix $(INCINSTALLPATH)/,$(notdir $(LIBHEADERS)))


#
113
114
# compiler flags
# --------------
Tilman Steinweg's avatar
Tilman Steinweg committed
115
116
117
118
119
120

FLAGS=
FLAGS+=-fPIC $(MYFLAGS)
CXXFLAGS+=-Wall $(FLAGS)
LDFLAGS+=-L$(LOCLIBDIR)
CPPFLAGS+=-I$(LOCINCLUDEDIR) $(FLAGS)
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# 
# source code editing and directory clean-up
# ------------------------------------------

flist: $(EDITFILES) $(TF_EDIT)
	echo $(filter-out $(DOCFILES) $(SOURCEFILES) \
	  $(USAGEFILES),$(EDITFILES)) \
	  | tr ' ' '\n' | sort > $@
	echo '----' >> $@
	echo $(filter-out test%,$(SOURCEFILES)) | tr ' ' '\n' | sort >> $@
	echo '----' >> $@
	echo $(USAGEFILES) | tr ' ' '\n' | sort >> $@
	echo '----' >> $@
	echo $(filter test%,$(SOURCEFILES)) | tr ' ' '\n' | sort >> $@
	echo '----' >> $@
	echo $(DOCFILES) | tr ' ' '\n' | sort >> $@
	echo '----' >> $@
	echo $(TF_EDIT) | tr ' ' '\n' | sort >> $@
Tilman Steinweg's avatar
Tilman Steinweg committed
139
140
141
142
143
144
145
146
147
148
149

.PHONY: edit
edit: flist; vim $<

.PHONY: clean
clean: ; 
	-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
	-find . -name \*.o | xargs --no-run-if-empty /bin/rm -v
	-find . -name \*.d | xargs --no-run-if-empty /bin/rm -v
	-find . -name \*.hd | xargs --no-run-if-empty /bin/rm -v
	-/bin/rm -vf flist *.a *.so *.xxx $(TESTCBIN) $(TESTCCBIN)
150
151
	-/bin/rm -fv $(patsubst %.txt,%.h,$(USAGEFILES))
	-/bin/rm -fv $(patsubst %.txt,%.cc,$(USAGEFILES))
Tilman Steinweg's avatar
Tilman Steinweg committed
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

#======================================================================
# pattern rules
# -------------

%.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 $@'

#======================================================================
# library part
# ------------

include $(patsubst %.cc,%.d,$(LIBCCSRC) $(TESTCCSRC)) \
        $(patsubst %.c,%.d,$(LIBCSRC) $(TESTCSRC))

libstfinv.a: $(patsubst %.cc,%.o,$(LIBCCSRC)) \
             $(patsubst %.c,%.o,$(LIBCSRC))
	ar rcv $@ $^
	ranlib $@

#----------------------------------------------------------------------

183
$(INCINSTALLPATH)/%.h: %.h
Tilman Steinweg's avatar
Tilman Steinweg committed
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
	mkdir -p $(INCINSTALLPATH)
	-rm -fv $@
	/bin/cp -vpd $< $@

.PHONY: install-include
install-include: $(INSTHEADER)

#======================================================================
# 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

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

# ======================================================================
# source code generators
# ======================
#
# description and online texts
# ----------------------------
#  The following rules convert ordinary ASCII text files into C++ source code,
#  providing functions to output usage information (online help)
#
#  Such text files use names with the pattern *usage.txt
#  Automatically generated source code is excluded from editing and versioning
#
%usage.cc %usage.h: usage/%usage.txt
	echo "// DO NOT EDIT: this file is automatically derived from $<" \
	  > $(patsubst usage/%.txt,%.h,$<)
	echo "extern char $(patsubst usage/%.txt,%,$<)[];" \
	  >> $(patsubst usage/%.txt,%.h,$<)
	echo "// DO NOT EDIT: this file is automatically derived from $<" \
	  > $(patsubst usage/%.txt,%.cc,$<)
	echo "#include \"$(patsubst usage/%.txt,%.h,$<)\"" \
	  >> $(patsubst usage/%.txt,%.cc,$<)
	echo "char $(patsubst usage/%.txt,%,$<)[]=" \
	  >> $(patsubst usage/%.txt,%.cc,$<)
	echo "{" >> $(patsubst usage/%.txt,%.cc,$<)
	cat $< | egrep -v '^#' | sed -e 's/\\/\\\\/g' | sed -e 's/"/\\"/g' \
	  | sed -e 's/$$/\\n"/' | sed -e 's/^/  "/'\
	  >> $(patsubst usage/%.txt,%.cc,$<)
	echo "};" >> $(patsubst usage/%.txt,%.cc,$<)

Tilman Steinweg's avatar
Tilman Steinweg committed
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
#======================================================================
# 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.
#

$(call CHECKVARS,TF_WWWBASEDIR TF_BROWSER)

DOXYWWWPATH=$(TF_WWWBASEDIR)/libstfinv

.PHONY: doxyclean doxyview doxydoc doxyconf

doxyclean: ;/bin/rm -rfv $(DOXYWWWPATH) doxydoc.xxx

261
262
263
DOXYSRC=$(DOXYTXT) $(LIBCCSRC) $(LIBCSRC) $(LIBHEADERS)\
	  $(TESTCCSRC) $(TESTCSRC) \
        Makefile
Tilman Steinweg's avatar
Tilman Steinweg committed
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

PWD=$(shell env pwd)
# create doxygen intermediate configuration
doxydoc.xxx: doxydoc.cfg
	sed 's,<OUTPUTDIRECTORY>,$(DOXYWWWPATH),g;s,<STRIPFROMPATH>,$(PWD),g' \
	  $< > $@
# create commented version of doxygen configuration
doxycomm.xxx: doxydoc.cfg
	/bin/cp -vf $< $@; doxygen -u $@

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

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

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

#======================================================================
# test code
# ---------

$(TESTCCBIN): %: tests/%.o libstfinv.a
	$(CXX) $(FLAGS) -o $@ $^ -I$(LOCINCLUDEDIR) \
        -ltfxx -lfourierxx -lfftw3 -laff \
        -L$(LOCLIBDIR)

# ----- END OF Makefile -----