Makefile 10.6 KB
Newer Older
thomas.forbriger's avatar
new  
thomas.forbriger committed
1
2
# this is <Makefile>
# ----------------------------------------------------------------------------
thomas.forbriger's avatar
thomas.forbriger committed
3
# $Id$
thomas.forbriger's avatar
new  
thomas.forbriger committed
4
5
6
7
8
9
# 
# Copyright (c) 2002 by Thomas Forbriger (IMG Frankfurt) 
# 
# Fourier coefficients library
#
# provide Fourier coefficients of filter responses etc.
10
#
11
# this library makes use of libtfxx
12
# libtfxx must be installed first
thomas.forbriger's avatar
new  
thomas.forbriger committed
13
14
15
# 
# REVISIONS and CHANGES 
#    07/11/2002   V1.0   Thomas Forbriger
thomas.forbriger's avatar
thomas.forbriger committed
16
17
18
19
#    05/01/2003   V1.1   uuuhhhhhh
#                        had to resolve a specific problem: my library
#                        procuded object files for Fortran code with the same
#                        name of the object files of C++ code
thomas.forbriger's avatar
thomas.forbriger committed
20
#    17/12/2007   V1.2   move to gfortran and 64bit compilation
21
22
23
24
25
26
27
#    18/09/2010   V1.3   start migration to SVN scheme
#                        - discard f2c (fallback) solution
#                        - check variables
#                        - copy headers (no symbolic links)
#                        - new doxygen definitions
#                        - package creation not yet implemented
#                        - set TF_REMCMMNT to cat if not defined
thomas.forbriger's avatar
thomas.forbriger committed
28
#    07/10/2010   V1.4   - migrate to FFTW3
thomas.forbriger's avatar
thomas.forbriger committed
29
#    15/11/2010   V1.5   - avoid makefdoc.pl
30
#    18.12.2010   V1.6   - shared library does not work satisfactory
31
32
33
#    11.01.2011   V1.7   - renamed Fortran source code such that
#                          Fotran object files to not conflict with
#                          C++ object files
34
#    17/01/2011   V1.8   distinguish library creation and installation
thomas.forbriger's avatar
new  
thomas.forbriger committed
35
36
37
38
# 
# ============================================================================
#

39
40
41
42
43
44
45
.PHONY: all
all: install doc

.PHONY: doc
doc: doxydoc libfourier.doc

LIBRARIES=libfourier.a libfourierxx.a
46
#shared: libfourierxx.so
thomas.forbriger's avatar
new  
thomas.forbriger committed
47

48
.PHONY: install
49
50
51
install: 
	$(MAKE) install-include 
	$(MAKE) $(LIBRARIES)
52
53
54
55
	/bin/mv -fv $(LIBRARIES) $(LOCLIBDIR)

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

56
flist: Makefile $(wildcard *.f *.inc *.h *.cc *.c README *.cfg)
thomas.forbriger's avatar
new  
thomas.forbriger committed
57
58
59
60
61
62
	echo $^ | tr ' ' '\n' | sort > $@

.PHONY: edit
edit: flist; vim $<

.PHONY: clean
63
64
65
66
67
68
clean:
	-/bin/rm -fv *.o *.bak *.doc *.o77 flist *.of2c
	-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 \*.h.strip | xargs --no-run-if-empty /bin/rm -v
69
	-/bin/rm -vf flist *.o install-include *.xxx junk* *.a *.so
70
71
72
73
74
75
76
77
78

# ============================================================================
#
CHECKVAR=$(if $($(1)),,$(error ERROR: missing variable $(1)))
CHECKVARS=$(foreach var,$(1),$(call CHECKVAR,$(var)))
#

$(call CHECKVARS,LOCINCLUDEDIR LOCLIBDIR)
$(call CHECKVARS,TF_BROWSER TF_WWWBASEDIR)
thomas.forbriger's avatar
new  
thomas.forbriger committed
79

thomas.forbriger's avatar
thomas.forbriger committed
80
81
82
AR=ar
AS=as
RANLIB=ranlib
thomas.forbriger's avatar
new  
thomas.forbriger committed
83

thomas.forbriger's avatar
thomas.forbriger committed
84
85
86
87
88
#----------------------------------------------------------------------
# uncomment this to activate the FFTW fallback solution
# i.e. to use FFTW instead of FFTW3
# this option will disappear in the near future! Better not use it...
#FFTWFALLBACK=-DFFTWFALLBACK
89
90
#FFTWLIB=-ldrfftw -ldfftw
FFTWLIB=-lfftw3
thomas.forbriger's avatar
thomas.forbriger committed
91
92
#----------------------------------------------------------------------

93
94
95
96
97
FLAGS+=-fPIC
FFLAGS+=-ff2c -Wall -ffixed-line-length-0 -fno-backslash $(FLAGS)
CFLAGS+=$(FLAGS)
CXXFLAGS+=-Wall -fPIC $(FLAGS) 
LDFLAGS+=-L$(LOCLIBDIR) -fPIC
98
CPPFLAGS+=-I$(LOCINCLUDEDIR) $(FLAGS)
thomas.forbriger's avatar
new  
thomas.forbriger committed
99

thomas.forbriger's avatar
thomas.forbriger committed
100
LIBSRC=$(wildcard *.f)
thomas.forbriger's avatar
new  
thomas.forbriger committed
101
LIBOBS=$(patsubst %.f,%.o,$(LIBSRC))
thomas.forbriger's avatar
thomas.forbriger committed
102
DOCS=libfourier.doc
thomas.forbriger's avatar
new  
thomas.forbriger committed
103
104
105

docs: $(DOCS)

thomas.forbriger's avatar
thomas.forbriger committed
106
107
%.o: %.f
	$(FC) $(FFLAGS) -c -o $@ $<
thomas.forbriger's avatar
new  
thomas.forbriger committed
108

thomas.forbriger's avatar
thomas.forbriger committed
109
libfourier.doc: $(LIBSRC) $(wildcard *.inc)
thomas.forbriger's avatar
thomas.forbriger committed
110
111
112
113
114
115
116
	/usr/bin/awk 'BEGIN{ hot=0; } \
        /^cS/ { hot=1; \
	    print FILENAME; \
          print "  c\n  c"; \
          next; } \
        /^cE/ { hot=0; } \
        { if (hot==1) { print "  " $$0; } }' $^ > $@
thomas.forbriger's avatar
new  
thomas.forbriger committed
117

thomas.forbriger's avatar
thomas.forbriger committed
118
libfourier.a: $(LIBOBS)
thomas.forbriger's avatar
new  
thomas.forbriger committed
119
120
121
122
123

%.a: 
	$(AR) rcv $@ $^
	$(RANLIB) $@

thomas.forbriger's avatar
thomas.forbriger committed
124
125
126
127
128
129
130
131
132
133
134
135
136
# ============================================================================
#     
# A note on header files:
# We extensively comment class declarations within the header files. The
# reduce compilation time when using the library code, comments will be
# stripped from the header files that are exportet. These stripped versions
# are placed in the source code path with name *.h.strip and will be linked to
# INCINSTALLPATH with name *.h.
#
# Although comment stripping could be done by perl with an elaborate regular
# expression, we prefer the remcmmnt command by Jari Laaksonen. You can find
# the code at 
#   http://www.eti.pg.gda.pl/KATEDRY/kecs/lab-cpp/snippets/
137
# If it is not available to you, you should set TF_REMCMMNT=cat (see below)
thomas.forbriger's avatar
thomas.forbriger committed
138
139
140
141
142
143
144
145
146
147
148
149
150
# 
# ============================================================================
#
# environment variables
# ---------------------
#
# You will like to set the following environment variables:
#
# LOCINCLUDEDIR         Defines the path where header files will be copied for
#                       usage in your own projects. You will pass this path to
#                       the precompiler with the -I option.
# LOCLIBDIR             Defines the path where the binary library will be
#                       placed.
151
# TF_WWWBASEDIR         Defines the path to your personal homepage. That's the
thomas.forbriger's avatar
thomas.forbriger committed
152
153
154
155
156
157
158
159
160
161
162
163
#                       place where doxygen output will be written too (see
#                       below).

# files
# -----

# all header files used within this project
HEADERS=$(shell find . -name \*.h)
# all source code to be compiled to object files and to be included
# in the binary version of the library
# (see below for the configuration of a preinstantiated version of template
# code)
164
SRC=fcommand.cc filters.cc polesnzeroes.cc fftwaff.cc error.cc fftwaffar.cc
thomas.forbriger's avatar
thomas.forbriger committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# test programs are placed in a subdirectory
TESTS=$(wildcard tests/*.cc)
# whereever we find a README, we will use it
README=$(shell find . -name README) 

# place where we will copy header files
INCINSTALLPATH=$(LOCINCLUDEDIR)/fourier
# place where we will copy the binary library
LIBINSTALLPATH=$(LOCLIBDIR)

# name of headers with comments stripped off (these are linked to your include
# directory)
STRIPHEADER=$(addsuffix .strip,$(notdir $(HEADERS)))
# name of installed (exported) header files (these are the names in your
# include directory)
INSTHEADER=$(addprefix $(INCINSTALLPATH)/,$(filter-out ./tests/%,$(HEADERS)))

# if defined, empty lines are kept in comment-stripped headers
# to synchronize line numbers (necessary during library debugging)
EMPTYPRINT=1
#EMPTYPRINT=0

# define this to be cat in case you do not have remcmmnt available
188
189
190
ifndef TF_REMCMMNT
TF_REMCMMNT=cat
endif
thomas.forbriger's avatar
thomas.forbriger committed
191
192
193

# compiler and preprocessor flags
FLAGS=
thomas.forbriger's avatar
thomas.forbriger committed
194
195
196
197
#CXXFLAGS += -Wall -pedantic $(FLAGS) -O3
CXXFLAGS += -Wall $(FLAGS) -O3
LDFLAGS += -L$(LOCLIBDIR)
CPPFLAGS += -I$(LOCINCLUDEDIR) $(FLAGS)
thomas.forbriger's avatar
thomas.forbriger committed
198
199
200
201

LIBOBSXX=$(patsubst %.cc,%.o,$(SRC))

libfourierxx.a: install-include $(LIBOBSXX)
thomas.forbriger's avatar
thomas.forbriger committed
202
	ar rcv $@ $(LIBOBSXX)
thomas.forbriger's avatar
thomas.forbriger committed
203
204
	ranlib $@

205
206
207
libfourierxx.so: install-include libfourier.a $(LIBOBSXX) 
	$(CXX) $(CXXFLAGS) -shared -o $@ $(LIBOBSXX) -lfourier \
        -L$(LOCLIBDIR)
208

thomas.forbriger's avatar
thomas.forbriger committed
209
210
211
212
213
214
215
216
217
218
219
220
#======================================================================
# dependencies
# ------------
#
# The compiler is used to create dependency files, which are included below.

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

221
include $(patsubst %.cc,%.d,$(SRC)) 
thomas.forbriger's avatar
thomas.forbriger committed
222
223
224
225
226
227
228
229

#======================================================================
# 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
230
# below and is controlled by the variables TF_REMCMMNT and EMPTYPRINT (see
thomas.forbriger's avatar
thomas.forbriger committed
231
232
233
234
235
236
237
238
239
240
241
# above).

# comment stripping
# -----------------

# 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; } }' $< > $@
242
	$(TF_REMCMMNT) $< | awk 'BEGIN {hot=0;} \
thomas.forbriger's avatar
thomas.forbriger committed
243
244
245
246
247
248
249
250
251
        /^ *$$/ { if ((hot) && ($(EMPTYPRINT))) { print ""; } next; } \
        /^#/ { hot=1; } { if (hot) print; }' >> $@

#----------------------------------------------------------------------
.PRECIOUS: %.h.strip
      
$(INCINSTALLPATH)/%.h: %.h.strip
	mkdir -vp $(dir $@)
	-rm -fv $@
252
	/bin/cp -vpd $< $@
thomas.forbriger's avatar
thomas.forbriger committed
253
254

# install header files
255
.PHONY: install-include
thomas.forbriger's avatar
thomas.forbriger committed
256
257
install-include: $(INSTHEADER)

258
259
260
261
262
263
264
265
266
267
268
269
270
#======================================================================
# 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

thomas.forbriger's avatar
tests    
thomas.forbriger committed
271
272
273
274
275
276
277
#======================================================================
# tests
# -----

cfftwtest: cfftwtest.c
	$(CC) -o $@ $< -ldrfftw -ldfftw -lm

thomas.forbriger's avatar
thomas.forbriger committed
278
cxxfftwtest: cxxfftwtest.cc libfourierxx.a
279
	$(CXX) -o $@ $< -ltfxx -lfourierxx -laff $(FFTWLIB) -lm \
280
        $(CPPFLAGS) $(LDFLAGS)
thomas.forbriger's avatar
tests    
thomas.forbriger committed
281

thomas.forbriger's avatar
thomas.forbriger committed
282
283
284
285
286
287
288
289
290
291
292
#======================================================================
# 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
293
# make doxyconf         edit the doxygen configuration file
thomas.forbriger's avatar
thomas.forbriger committed
294
#
295
# If you launch "make doxydoc" the documentation will be written to
thomas.forbriger's avatar
thomas.forbriger committed
296
297
298
299
300
# DOXYWWWPATH (see below). This is meant to export the documentation through
# your homepage. The doxyfull directory is just a symbolic link to this
# directory.
#

301
$(call CHECKVARS,TF_WWWBASEDIR TF_BROWSER)
thomas.forbriger's avatar
thomas.forbriger committed
302

303
304
305
306
DOXYWWWPATH=$(TF_WWWBASEDIR)/libfourier

.PHONY: doxyclean doxyview doxydoc doxyconf

307
doxyclean: ;/bin/rm -rfv $(DOXYWWWPATH) doxydoc.xxx
thomas.forbriger's avatar
thomas.forbriger committed
308
309
310

DOXYSRC=$(README) $(HEADERS) $(SRC) 

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

$(DOXYWWWPATH)/html/index.html: doxydoc.xxx $(DOXYSRC)
thomas.forbriger's avatar
thomas.forbriger committed
321
322
323
	mkdir -vp $(DOXYWWWPATH)
	doxygen $<

324
doxydoc: $(DOXYWWWPATH)/html/index.html
thomas.forbriger's avatar
thomas.forbriger committed
325

326
327
doxyview: $(DOXYWWWPATH)/html/index.html
	$(TF_BROWSER) file:$< &
thomas.forbriger's avatar
thomas.forbriger committed
328

329
330
331
332
333
334
335
336
337
#======================================================================
# create package
# --------------
# is delegated to Makefile.packages
# which still has to be coded
PACKAGE=libfourier
#ifdef TF_MAKEPKG
#include $(TF_MAKEPKG)
#endif
thomas.forbriger's avatar
thomas.forbriger committed
338

thomas.forbriger's avatar
new  
thomas.forbriger committed
339
# ----- END OF Makefile -----