Makefile 5.31 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# this is <Makefile>
# ----------------------------------------------------------------------------
# $Id$
# 
# Copyright (c) 2010 by Thomas Forbriger (BFO Schiltach) 
# 
# A Fortran API to libdatreadxx and libdatwritexx
# 
# REVISIONS and CHANGES 
#    17/11/2010   V1.0   Thomas Forbriger
# 
# ============================================================================
#

all:
16
17
18
19
20
21
22
23
24
25
26
27
28
# check mandatory environment variable settings
# ---------------------------------------------

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)

INCINSTALLPATH=$(LOCINCLUDEDIR)/fapidxx
LIBINSTALLPATH=$(LOCLIBDIR)
HEADERS=$(wildcard *.h)
CCSRC=$(wildcard *.cc)
29
FSRC=$(wildcard *.f)
30
31
32
33
34
35
36
37
38
SRC=$(CCSRC)
README=README

FLAGS += $(MYFLAGS)
FFLAGS += -ff2c -Wall -ffixed-line-length-0 -fno-backslash $(FLAGS)
CFLAGS += $(FLAGS)
CXXFLAGS+=-Wall $(FLAGS)
LDFLAGS+=-L$(LOCLIBDIR)
CPPFLAGS+=-I$(LOCINCLUDEDIR) $(FLAGS)
thomas.forbriger's avatar
thomas.forbriger committed
39

thomas.forbriger's avatar
thomas.forbriger committed
40
41
#----------------------------------------------------------------------

42
flist: Makefile $(HEADERS) $(README) $(SRC) doxydoc.cfg $(FSRC)
thomas.forbriger's avatar
thomas.forbriger committed
43
44
45
46
47
48
49
50
	echo $^ | tr ' ' '\n' | sort > $@

.PHONY: edit
edit: flist; vim $<

.PHONY: clean
clean: ; 
	-find . -name \*.bak | xargs --no-run-if-empty /bin/rm -v
51
	-/bin/rm -vf flist *.o fapidtest 
thomas.forbriger's avatar
thomas.forbriger committed
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
#======================================================================
# 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 $@'

-include $(patsubst %.cc,%.d,$(SRCFILES)) 

#======================================================================
# 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
# -----------------
EMPTYPRINT=0
$(call CHECKVARS,TF_REMCMMNT EMPTYPRINT)

# 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; } }' $< > $@
	$(TF_REMCMMNT) $< | awk 'BEGIN {hot=0;} \
        /^ *$$/ { if ((hot) && ($(EMPTYPRINT))) { print ""; } next; } \
        /^#/ { hot=1; } { if (hot) print; }' >> $@

thomas.forbriger's avatar
thomas.forbriger committed
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
.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
INSTHEADER=$(addprefix $(INCINSTALLPATH)/,$(HEADERS))
.PHONY: install-include
install-include: $(INSTHEADER)

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

# INSTHEADER contains full qualified paths to library header files
# like /home/thof/include/aff/series.h
libfapidxx.a: $(INSTHEADER) $(LIBOBS)
	ar rcv $@ $(LIBOBS)
	ranlib $@
125
	/bin/mv -vf $@ $(LIBINSTALLPATH)
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

#======================================================================
# 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)/libfapidxx

.PHONY: doxyclean doxyview doxydoc doxyconf

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

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

# create doxygen intermediate configuration
PWD=$(shell env pwd)
doxydoc.xxx: doxydoc.cfg
	sed 's,<OUTPUTDIRECTORY>,$(DOXYWWWPATH),g;s,<STRIPFROMPATH>,$(PWD),g' \
	  $< > $@
161
162
163
# create commented version of doxygen configuration
doxycomm.xxx: doxydoc.cfg
	/bin/cp -vf $< $@; doxygen -u $@
164
165
166
167
168
169
170
171
172

$(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
173

174
175
176
177
178
#======================================================================
# test code

fapidtest: fapidtest.o libfapidxx.a
	$(FC) -o $@ $< -lfapidxx -ltf -L$(LOCLIBDIR) -lstdc++
thomas.forbriger's avatar
thomas.forbriger committed
179
180

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