1#
2#	Makefile for mkreadmes
3#
4#	$Id: Makefile,v 1.69 2012/05/04 20:53:10 conrads Exp $
5#
6###############################################################################
7
8PROGRAM=		mkreadmes
9VERSION=		1.3
10PREFIX?=		/usr/local				# allow user to override install prefix
11BINDIR=			${DESTDIR}${PREFIX}/sbin
12DATADIR=		${DESTDIR}${PREFIX}/share/${PROGRAM}
13MANDIR=			${DESTDIR}${PREFIX}/man/man1
14TEMPLATESDIR=	${DATADIR}/Templates
15SRCS=			index.c init.c main.c ${PROGRAM}.c util.c ${PROGRAM}.h
16INCLUDES=		/usr/include
17CTAGS=			ctags
18CXREF=			cxref
19GZIP=			gzip
20MKDIR=			mkdir
21RM=				rm
22STRIP=			strip
23
24###############################################################################
25#
26# everything between here and the next "banner" line
27# will have no effect if building as a FreeBSD port
28#
29ASMFLAGS=		-S -fverbose-asm
30GCOV_FLAGS=		-fprofile-arcs -ftest-coverage
31GPROF_FLAGS=	-pg
32OPTIMIZE=		-O3
33
34.ifndef (DEBUG)
35OPTIMIZE+=   	-fomit-frame-pointer
36.endif
37
38CFLAGS?=	-march=native -pipe -fno-strict-aliasing ${OPTIMIZE}
39
40# end of FreeBSD port-dependent section
41#
42###############################################################################
43
44#
45# targets for building and installing the package
46#
47
48#
49# default target (build the program)
50#
51all:			${PROGRAM}
52
53#
54# target to build the finished program
55#
56${PROGRAM}:		index.o init.o main.o ${PROGRAM}.o util.o
57				${CC} ${OPTIMIZE} ${CFLAGS} -o ${PROGRAM} index.o init.o \
58					main.o ${PROGRAM}.o util.o
59#
60# targets for building the individual object files
61#
62index.o:		index.c ${PROGRAM}.h
63				${CC} ${DEBUG} ${OPTIMIZE} ${CFLAGS} -c index.c
64
65init.o:			init.c ${PROGRAM}.h
66				${CC} ${DEBUG} ${OPTIMIZE} ${CFLAGS} -c init.c
67
68main.o:			main.c ${PROGRAM}.h
69				${CC} ${DEBUG} ${OPTIMIZE} ${CFLAGS} -c main.c
70
71${PROGRAM}.o:	${PROGRAM}.c ${PROGRAM}.h
72				${CC} ${DEBUG} ${OPTIMIZE} ${CFLAGS} -c ${PROGRAM}.c
73
74util.o:			util.c ${PROGRAM}.h
75				${CC} ${DEBUG} ${OPTIMIZE} ${CFLAGS} -c util.c
76
77#
78# install everything -- the program, template files, README and man page
79#
80install:	all install-bin install-data install-man
81
82#
83# install the program
84#
85install-bin:
86			${MKDIR} -p ${BINDIR}
87.ifndef DEBUG
88			${STRIP} ${PROGRAM}
89.endif
90			${INSTALL}  -m 0755 ${PROGRAM} ${BINDIR}
91#
92# install the program's data files (templates and README file)
93#
94install-data:
95			${MKDIR} -p ${DATADIR}
96			${INSTALL}  -m 0644 README ${DATADIR}
97			${MKDIR} -p ${TEMPLATESDIR}
98			${INSTALL}  -m 0644 README.* ${TEMPLATESDIR}
99#
100# install the program's man page
101#
102install-man:
103			${MKDIR} -p ${MANDIR}
104.ifdef (NO_MANCOMPRESS)			# user wants the man page uncompressed
105			${INSTALL}  -m 644 mkreadmes.1 ${MANDIR}
106.else							# otherwise, compress it first
107			${GZIP} -fk mkreadmes.1
108			${INSTALL}  -m 644 mkreadmes.1.gz ${MANDIR}
109.endif
110
111#
112# uninstall everything
113#
114uninstall:
115			${RM} -f ${BINDIR}/${PROGRAM}
116			${RM} -rf ${TEMPLATESDIR}
117			${RM} -rf ${DATADIR}
118			${RM} -f ${MANDIR}/mkreadmes.1*
119#
120# remove compiled program and its intermediate object files (and possibly the
121# gzipped man page as well) from source directory
122#
123clean:
124			${RM} -f ${PROGRAM} ${PROGRAM}.1.gz *.o
125
126#
127# same as above, plus any HTML cross-reference files which may have been built,
128# as well as any gcov or gprof-related files, and the tags file
129#
130distclean:	clean
131			${RM} -f *.gcda *.gcno *.gcov *.gch *.gmon *.gprof tags
132			${RM} -rf ${CXREF}
133
134###############################################################################
135#
136# the remaining targets are for development purposes only
137#
138###############################################################################
139
140#
141# do a cvs update
142#
143update:
144		cvs update
145
146commit:
147		cvs commit
148diff:
149		cvs diff
150
151#
152# make a tags file using ctags
153#
154tags:		${SRCS}
155			@${ECHO} "Building ctags file..." && \
156				${RM} -f tags && \
157				${CTAGS} -d *.c *.h
158#
159# build cross-reference HTML files (very useful during development)
160#
161# requires the devel/cxref port
162#
163${CXREF}:		${CXREF}-html
164
165${CXREF}-html:	${CXREF}-data
166				@${ECHO} "Building ${CXREF} HTML files..." && \
167					${CXREF} -N${PROGRAM} -O${CXREF} -I${INCLUDES} -I. \
168					-index-all -xref-all *.c *.h -html -html-src && \
169					./expand-tabs
170
171${CXREF}-data:	${SRCS}
172				@${ECHO} "Gathering ${CXREF} data..." && \
173					${RM} -rf ${CXREF} && mkdir -p ${CXREF} && \
174					${CXREF} -N${PROGRAM} -O${CXREF} -I${INCLUDES} -I. \
175					-index-all -xref-all *.c *.h
176#
177# the *.s targets are for genrating assembly language output files, to
178# possibly determine whether a given attempt at optimization actually produces
179# better code or not
180#
181index.s:	index.c ${PROGRAM}.h
182			${CC} ${DEBUG} ${OPTIMIZE} ${CFLAGS} ${ASMFLAGS} index.c
183
184init.s:		init.c ${PROGRAM}.h
185			${CC} ${DEBUG} ${OPTIMIZE} ${CFLAGS} ${ASMFLAGS} init.c
186
187main.s:		main.c ${PROGRAM}.h
188			${CC} ${DEBUG} ${OPTIMIZE} ${CFLAGS} ${ASMFLAGS} main.c
189
190${PROGRAM}.s:	${PROGRAM}.c ${PROGRAM}.h
191				${CC} ${DEBUG} ${OPTIMIZE} ${CFLAGS} ${ASMFLAGS} ${PROGRAM}.c
192
193util.s:		util.c ${PROGRAM}.h
194			${CC} ${DEBUG} ${OPTIMIZE} ${CFLAGS} ${ASMFLAGS} util.c
195
196#
197# this target uses lots of compiler warning options to try to identify any
198# questionable code we might have overlooked.  works with both gcc and clang
199# (just change ${CC}).  don't set ${OPTIMIZE} higher than -O3 if using clang,
200# as the linking stage will fail
201#
202lint:		clean
203			${CC} -W -Wall -pedantic -Waggregate-return \
204			-Wbad-function-cast -Wcast-align -Wcast-qual -Wchar-subscripts \
205			-Wconversion -Wimplicit -Winline -Wmissing-prototypes \
206			-Wnested-externs -Wpointer-arith -Wredundant-decls -Wshadow \
207			-Wstrict-prototypes -Wuninitialized -Wunreachable-code -Wunused \
208			-Wwrite-strings -fshort-enums -fno-common \
209			${OPTIMIZE} -g -o mkreadmes *.c
210
211#
212# build a profiled version of the program for use with gprof
213#
214
215#CC=gcc46
216
217gprof:			clean.gprof ${PROGRAM}.gprof
218
219clean.gprof:
220			${RM} -f ${PROGRAM}.gprof *.o *.gmon
221
222${PROGRAM}.gprof:	index.o.gprof init.o.gprof main.o.gprof \
223						${PROGRAM}.o.gprof util.o.gprof
224				${CC} ${CFLAGS} ${GPROF_FLAGS} -o ${PROGRAM}.gprof \
225					-lc_p index.o init.o main.o ${PROGRAM}.o util.o
226#
227# targets for building individual profiled object files
228#
229index.o.gprof:	index.c ${PROGRAM}.h
230				${CC} ${DEBUG} ${CFLAGS} ${GPROF_FLAGS} -c index.c
231
232init.o.gprof:	init.c ${PROGRAM}.h
233				${CC} ${DEBUG} ${CFLAGS} ${GPROF_FLAGS} -c init.c
234
235main.o.gprof:	main.c ${PROGRAM}.h
236				${CC} ${DEBUG} ${CFLAGS} ${GPROF_FLAGS} -c main.c
237
238${PROGRAM}.o.gprof:	${PROGRAM}.c ${PROGRAM}.h
239				${CC} ${DEBUG} ${CFLAGS} ${GPROF_FLAGS} -c ${PROGRAM}.c
240
241util.o.gprof:	util.c ${PROGRAM}.h
242				${CC} ${DEBUG} ${CFLAGS} ${GPROF_FLAGS} -c util.c
243
244#
245# build a version of the program for use with gcov
246#
247gcov:			clean.gcov ${PROGRAM}.gcov
248
249clean.gcov:
250			${RM} -f ${PROGRAM}.gcov *.o
251			${RM} -f *.gcda *.gcno *.gcov *.gch
252
253${PROGRAM}.gcov:	index.o.gcov init.o.gcov main.o.gcov ${PROGRAM}.o.gcov \
254						util.o.gcov
255					CC=gcc46 \
256					${CC} ${CFLAGS} ${GCOV_FLAGS} -o ${PROGRAM}.gcov \
257						index.o init.o main.o ${PROGRAM}.o util.o
258#
259# targets for building individual gcov object files
260#
261index.o.gcov:	index.c ${PROGRAM}.h
262				${CC} ${DEBUG} ${CFLAGS} ${GCOV_FLAGS} -c index.c
263
264init.o.gcov:	init.c ${PROGRAM}.h
265				${CC} ${DEBUG} ${CFLAGS} ${GCOV_FLAGS} -c init.c
266
267main.o.gcov:	main.c ${PROGRAM}.h
268				${CC} ${DEBUG} ${CFLAGS} ${GCOV_FLAGS} -c main.c
269
270${PROGRAM}.o.gcov:	${PROGRAM}.c ${PROGRAM}.h
271				${CC} ${DEBUG} ${CFLAGS} ${GCOV_FLAGS} -c ${PROGRAM}.c
272
273util.o.gcov:	util.c ${PROGRAM}.h
274				${CC} ${DEBUG} ${CFLAGS} ${GCOV_FLAGS} -c util.c
275
276