Makefile 6.18 KB
Newer Older
thomas.forbriger's avatar
thomas.forbriger committed
1
2
# this is <Makefile>
# ----------------------------------------------------------------------------
thomas.forbriger's avatar
thomas.forbriger committed
3
# $Id$
thomas.forbriger's avatar
thomas.forbriger committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 
# Copyright (c) 2008 by Thomas Forbriger (BFO Schiltach) 
# 
# a small library to access serial ports in C++
#
# ----
# 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
# ----
# 
# REVISIONS and CHANGES 
#    24/11/2008   V1.0   Thomas Forbriger
27
28
29
30
31
32
#    19/09/2010   V1.1   start migration to SVN scheme
#                        - 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
33
34
# 
# ============================================================================
35
36
37
38
39
40
41
42
43

all: install doxydoc
install: install-include libserialxx.a

#=============================================================================

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

46
47
48
$(call CHECKVARS,LOCINCLUDEDIR LOCLIBDIR)
$(call CHECKVARS,TF_BROWSER TF_WWWBASEDIR)

thomas.forbriger's avatar
thomas.forbriger committed
49
50
51
52
HEADERS=$(wildcard *.h)

LIBSRC=$(wildcard *.cc)

thomas.forbriger's avatar
thomas.forbriger committed
53
TESTSRC=$(wildcard tests/*.cc)
thomas.forbriger's avatar
thomas.forbriger committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

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

# name of headers with comments stripped off
STRIPHEADER=$(addsuffix .strip,$(notdir $(HEADERS)))
# name of installed (exported) header files
INSTHEADER=$(addprefix $(INCINSTALLPATH)/,$(notdir $(HEADERS)))

# if defined, empty lines are kept in stripped comment headers
# to synchronize line numbers
EMPTYPRINT=1
#EMPTYPRINT=0

# define this to be cat in case you do not have remcmmnt available
69
70
71
ifndef TF_REMCMMNT
TF_REMCMMNT=cat
endif
thomas.forbriger's avatar
thomas.forbriger committed
72
73
74
75
76
77
78
79
80
81
82
83

#
# general part
# ------------
#

FLAGS=
CXXFLAGS=-fhonor-std -Wall $(FLAGS)
CXXFLAGS=-Wall $(FLAGS)
LDFLAGS=-L$(LOCLIBDIR)
CPPFLAGS=-I$(LOCINCLUDEDIR) $(FLAGS)

thomas.forbriger's avatar
thomas.forbriger committed
84
flist: Makefile $(wildcard *.cfg) $(HEADERS) $(LIBSRC) README $(TESTSRC)
thomas.forbriger's avatar
thomas.forbriger committed
85
86
87
88
89
90
91
92
93
94
95
96
97
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
125
126
127
128
129
130
131
	echo $^ | tr ' ' '\n' | sort > $@

.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 \*.strip | xargs --no-run-if-empty /bin/rm -v
	-/bin/rm -vf flist 

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

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

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

-include $(patsubst %.cc,%.d,$(LIBSRC) $(TESTSRC))

libserialxx.a: $(patsubst %.cc,%.o,$(LIBSRC))
	ar rcv $@ $^
	ranlib $@
	/bin/mv -fv $@ $(LOCLIBDIR)

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

%.hd: %.h; echo $(notdir $<.strip): $< > $@

-include $(patsubst %.h,%.hd,$(HEADERS))

# first awk rule assumes that the first non-comment line starts with '#'
# and that the first (copyright) comment end with pattern "^ */"
%.h.strip:
	awk 'BEGIN {hot=1;} /^ \*\// { if (hot) { hot=2; print; next;} }\
        /^#/ { hot=0; } \
        { if (hot==2) { print ""; } else if (hot) { print; } }' $< > $@
132
	$(TF_REMCMMNT) $< | awk 'BEGIN {hot=0;} \
thomas.forbriger's avatar
thomas.forbriger committed
133
134
135
136
137
138
139
140
        /^ *$$/ { if ((hot) && ($(EMPTYPRINT))) { print; } next; } \
        /^#/ { hot=1; } { if (hot) print; }' >> $@

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

$(INCINSTALLPATH)/%.h: %.h.strip
	mkdir -p $(INCINSTALLPATH)
	-rm -fv $@
141
	/bin/cp -vpd $< $@
thomas.forbriger's avatar
thomas.forbriger committed
142

143
.PHONY: install-include
thomas.forbriger's avatar
thomas.forbriger committed
144
install-include: $(INSTHEADER)
145

thomas.forbriger's avatar
thomas.forbriger committed
146
147
148
#======================================================================
# documentation part
# ------------------
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#
# 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)/libserialxx
thomas.forbriger's avatar
thomas.forbriger committed
168

169
170
171
.PHONY: doxyclean doxyview doxydoc doxyconf

doxyclean: ;/bin/rm -rfv $(DOXYWWWPATH)
thomas.forbriger's avatar
thomas.forbriger committed
172
173
174

DOXYSRC=$(LIBSRC) $(HEADERS) README

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

$(DOXYWWWPATH)/html/index.html: doxydoc.xxx $(DOXYSRC)
thomas.forbriger's avatar
thomas.forbriger committed
185
186
187
	mkdir -vp $(DOXYWWWPATH)
	doxygen $<

188
189
190
191
doxydoc: $(DOXYWWWPATH)/html/index.html

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

193
194
195
196
197
198
199
200
201
#======================================================================
# create package
# --------------
# is delegated to Makefile.packages
# which still has to be coded
PACKAGE=libserialxx
#ifdef TF_MAKEPKG
#include $(TF_MAKEPKG)
#endif
thomas.forbriger's avatar
thomas.forbriger committed
202
203
204
205
206

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

thomas.forbriger's avatar
thomas.forbriger committed
207
208
209
210
211
212
portread portwrite: %: tests/%.o libserialxx.a
	$(CXX) $(FLAGS) -o $@ $< -I$(LOCINCLUDEDIR) \
        -lserialxx -ltfxx \
        -L$(LOCLIBDIR)
	/bin/mv -fv $@ $(LOCBINDIR)

thomas.forbriger's avatar
thomas.forbriger committed
213
214

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