Makefile.in 9.68 KB
Newer Older
Michael R Sweet's avatar
Michael R Sweet committed
1
#
2
# Makefile for Mini-XML, a small XML-like file parsing library.
Michael R Sweet's avatar
Michael R Sweet committed
3
#
4
# Copyright 2003-2018 by Michael R Sweet.
Michael R Sweet's avatar
Michael R Sweet committed
5
#
6 7 8 9 10
# These coded instructions, statements, and computer programs are the
# property of Michael R Sweet and are protected by Federal copyright
# law.  Distribution and use rights are outlined in the file "COPYING"
# which should have been included with this file.  If this file is
# missing or damaged, see the license at:
Michael R Sweet's avatar
Michael R Sweet committed
11
#
Michael Sweet's avatar
Michael Sweet committed
12
#     https://michaelrsweet.github.io/mxml
Michael R Sweet's avatar
Michael R Sweet committed
13 14 15 16 17 18 19 20
#

#
# Compiler tools definitions...
#

AR		=	@AR@
ARFLAGS		=	@ARFLAGS@
21
ARCHFLAGS	=	@ARCHFLAGS@
Michael R Sweet's avatar
Michael R Sweet committed
22
CC		=	@CC@
23
CFLAGS		=	$(OPTIM) $(ARCHFLAGS) @CFLAGS@ @CPPFLAGS@ @PTHREAD_FLAGS@ -DZIPC_ONLY_WRITE
24
CP		=	@CP@
25 26
DSO		=	@DSO@
DSOFLAGS	=	@DSOFLAGS@
27
LDFLAGS		=	$(OPTIM) $(ARCHFLAGS) @LDFLAGS@
28
INSTALL		=	@INSTALL@
29
LIBMXML		=	@LIBMXML@
Michael R Sweet's avatar
Michael R Sweet committed
30
LIBS		=	@LIBS@ @PTHREAD_LIBS@
31
LN		=	@LN@ -s
32 33
MKDIR		=	@MKDIR@
OPTIM		=	@OPTIM@
Michael R Sweet's avatar
Michael R Sweet committed
34
RANLIB		=	@RANLIB@
35
RM		=	@RM@ -f
Michael R Sweet's avatar
Michael R Sweet committed
36 37 38 39 40 41 42 43 44
SHELL		=	/bin/sh


#
# Configured directories...
#

prefix		=	@prefix@
exec_prefix	=	@exec_prefix@
45
bindir		=	@bindir@
46
datarootdir	=	@datarootdir@
Michael R Sweet's avatar
Michael R Sweet committed
47 48
includedir	=	@includedir@
libdir		=	@libdir@
49 50 51 52 53
mandir		=	@mandir@
docdir		=	@docdir@
BUILDROOT	=	$(DSTROOT)


54 55 56 57
#
# Install commands...
#

58
INSTALL_BIN	=	$(LIBTOOL) $(INSTALL) -m 755
59 60 61 62 63 64 65
INSTALL_DATA	=	$(INSTALL) -m 644
INSTALL_DIR	=	$(INSTALL) -d
INSTALL_LIB	=	$(LIBTOOL) $(INSTALL) -m 755
INSTALL_MAN	=	$(INSTALL) -m 644
INSTALL_SCRIPT	=	$(INSTALL) -m 755


Michael R Sweet's avatar
Michael R Sweet committed
66 67 68 69
#
# Rules...
#

70
.SILENT:
71
.SUFFIXES:	.c .man .o
Michael R Sweet's avatar
Michael R Sweet committed
72
.c.o:
73 74
	echo Compiling $<
	$(CC) $(CFLAGS) -c -o $@ $<
Michael R Sweet's avatar
Michael R Sweet committed
75 76 77 78 79 80


#
# Targets...
#

81
DOCFILES	=	doc/mxml.html doc/mxmldoc.xsd README.md COPYING CHANGES.md
82 83
PUBLIBOBJS	=	mxml-attr.o mxml-entity.o mxml-file.o mxml-get.o \
			mxml-index.o mxml-node.o mxml-search.o mxml-set.o
84
LIBOBJS		=	$(PUBLIBOBJS) mxml-private.o mxml-string.o
85
OBJS		=	mmd.o mxmldoc.o testmxml.o zipc.o $(LIBOBJS)
86
ALLTARGETS	=	$(LIBMXML) mxmldoc testmxml mxml.xml @MXML_EPUB@
87 88
CROSSTARGETS	=	$(LIBMXML) mxmldoc
TARGETS		=	$(@TARGETS@)
Michael R Sweet's avatar
Michael R Sweet committed
89 90 91 92 93 94


#
# Make everything...
#

95
all:		$(TARGETS)
Michael R Sweet's avatar
Michael R Sweet committed
96 97 98 99 100 101 102


#
# Clean everything...
#

clean:
103
	echo Cleaning build files...
104
	$(RM) $(OBJS) $(ALLTARGETS)
105 106 107 108 109 110
	$(RM) mxmldoc-static
	$(RM) mxml1.dll
	$(RM) libmxml.a
	$(RM) libmxml.so.1.6
	$(RM) libmxml.sl.1
	$(RM) libmxml.1.dylib
Michael R Sweet's avatar
Michael R Sweet committed
111 112 113 114 115 116 117


#
# Really clean everything...
#

distclean:	clean
118
	echo Cleaning distribution files...
119
	$(RM) config.cache config.log config.status
Michael R Sweet's avatar
Michael R Sweet committed
120
	$(RM) Makefile config.h
121
	$(RM) -r autom4te*.cache
Michael R Sweet's avatar
Michael R Sweet committed
122
	$(RM) *.bck *.bak
123 124 125 126 127 128 129
	$(RM) -r clang


#
# Run the clang.llvm.org static code analysis tool on the C sources.
#

130
.PHONY: clang clang-changes
131
clang:
132
	echo Doing static code analysis of all code using CLANG...
133
	$(RM) -r clang
134 135
	scan-build -V -k -o `pwd`/clang $(MAKE) $(MFLAGS) clean all
clang-changes:
136
	echo Doing static code analysis of changed code using CLANG...
137
	scan-build -V -k -o `pwd`/clang $(MAKE) $(MFLAGS) all
Michael R Sweet's avatar
Michael R Sweet committed
138 139 140 141 142 143


#
# Install everything...
#

144
install:	$(TARGETS) install-$(LIBMXML) install-libmxml.a
145
	echo Installing mxmldoc in $(BUILDROOT)$(bindir)...
146
	$(INSTALL_DIR) $(BUILDROOT)$(bindir)
147 148
	$(INSTALL_BIN) mxmldoc $(BUILDROOT)$(bindir)
	echo Installing documentation in $(BUILDROOT)$(docdir)...
149 150
	$(INSTALL_DIR) $(BUILDROOT)$(docdir)
	for file in $(DOCFILES); do \
151
		$(INSTALL_MAN) $$file $(BUILDROOT)$(docdir)/`basename $$file .md`; \
152
	done
153
	echo Installing header files in $(BUILDROOT)$(includedir)...
154 155
	$(INSTALL_DIR) $(BUILDROOT)$(includedir)
	$(INSTALL_DATA) mxml.h $(BUILDROOT)$(includedir)
156
	echo Installing pkgconfig files in $(BUILDROOT)$(libdir)/pkgconfig...
157 158
	$(INSTALL_DIR) $(BUILDROOT)$(libdir)/pkgconfig
	$(INSTALL_DATA) mxml.pc $(BUILDROOT)$(libdir)/pkgconfig
159
	echo Installing man pages in $(BUILDROOT)$(mandir)...
160
	$(INSTALL_DIR) $(BUILDROOT)$(mandir)/man1
161
	$(INSTALL_MAN) doc/mxmldoc.man $(BUILDROOT)$(mandir)/man1/mxmldoc.1
162
	$(INSTALL_DIR) $(BUILDROOT)$(mandir)/man3
163
	$(INSTALL_MAN) doc/mxml.man $(BUILDROOT)$(mandir)/man3/mxml.3
Michael R Sweet's avatar
Michael R Sweet committed
164

165
install-libmxml.a:	libmxml.a
166
	echo Installing libmxml.a to $(BUILDROOT)$(libdir)...
167 168
	$(INSTALL_DIR) $(BUILDROOT)$(libdir)
	$(INSTALL_LIB) libmxml.a $(BUILDROOT)$(libdir)
169
	$(RANLIB) $(BUILDROOT)$(libdir)/libmxml.a
170

171
install-libmxml.so.1.6:	libmxml.so.1.6
172
	echo Installing libmxml.so to $(BUILDROOT)$(libdir)...
173
	$(INSTALL_DIR) $(BUILDROOT)$(libdir)
174
	$(INSTALL_LIB) libmxml.so.1.6 $(BUILDROOT)$(libdir)
175
	$(RM) $(BUILDROOT)$(libdir)/libmxml.so
176
	$(LN) libmxml.so.1.6 $(BUILDROOT)$(libdir)/libmxml.so
177
	$(RM) $(BUILDROOT)$(libdir)/libmxml.so.1
178
	$(LN) libmxml.so.1.6 $(BUILDROOT)$(libdir)/libmxml.so.1
179

180
install-libmxml.sl.1:	libmxml.sl.1
181
	echo Installing libmxml.sl to $(BUILDROOT)$(libdir)...
182 183
	$(INSTALL_DIR) $(BUILDROOT)$(libdir)
	$(INSTALL_LIB) libmxml.sl.1 $(BUILDROOT)$(libdir)
184 185 186
	$(RM) $(BUILDROOT)$(libdir)/libmxml.so
	$(LN) libmxml.sl.1 $(BUILDROOT)$(libdir)/libmxml.sl

187
install-libmxml.1.dylib: libmxml.1.dylib
188
	echo Installing libmxml.dylib to $(BUILDROOT)$(libdir)...
189 190
	$(INSTALL_DIR) $(BUILDROOT)$(libdir)
	$(INSTALL_LIB) libmxml.1.dylib $(BUILDROOT)$(libdir)
191 192 193
	$(RM) $(BUILDROOT)$(libdir)/libmxml.dylib
	$(LN) libmxml.1.dylib $(BUILDROOT)$(libdir)/libmxml.dylib

Michael R Sweet's avatar
Michael R Sweet committed
194

195 196 197 198
#
# Uninstall everything...
#

199
uninstall: uninstall-$(LIBMXML) uninstall-libmxml.a
200
	echo Uninstalling mxmldoc from $(BUILDROOT)$(bindir)...
Michael R Sweet's avatar
Michael R Sweet committed
201
	$(RM) $(BUILDROOT)$(bindir)/mxmldoc
202
	echo Uninstalling documentation from $(BUILDROOT)$(docdir)...
Michael R Sweet's avatar
Michael R Sweet committed
203
	$(RM) -r $(BUILDROOT)$(docdir)
204
	echo Uninstalling headers from $(BUILDROOT)$(includedir)...
Michael R Sweet's avatar
Michael R Sweet committed
205
	$(RM) $(BUILDROOT)$(includedir)/mxml.h
206
	echo Uninstalling pkgconfig files from $(BUILDROOT)$(libdir)/pkgconfig...
207
	$(RM) $(BUILDROOT)$(libdir)/pkgconfig/mxml.pc
208
	echo Uninstalling man pages from $(BUILDROOT)$(mandir)...
209 210
	$(RM) $(BUILDROOT)$(mandir)/man1/mxmldoc.1
	$(RM) $(BUILDROOT)$(mandir)/man3/mxml.3
211

212
uninstall-libmxml.a:
213
	echo Uninstalling libmxml.a from $(BUILDROOT)$(libdir)...
214 215
	$(RM) $(BUILDROOT)$(libdir)/libmxml.a

216
uninstall-libmxml.so.1.6:
217
	echo Uninstalling libmxml.so from $(BUILDROOT)$(libdir)...
218 219
	$(RM) $(BUILDROOT)$(libdir)/libmxml.so
	$(RM) $(BUILDROOT)$(libdir)/libmxml.so.1
Michael R Sweet's avatar
Michael R Sweet committed
220
	$(RM) $(BUILDROOT)$(libdir)/libmxml.so.1.4
221 222

uninstall-libmxml.sl.1:
223
	echo Uninstalling libmxml.sl from $(BUILDROOT)$(libdir)...
224 225 226 227
	$(RM) $(BUILDROOT)$(libdir)/libmxml.sl
	$(RM) $(BUILDROOT)$(libdir)/libmxml.sl.1

uninstall-libmxml.1.dylib:
228
	echo Uninstalling libmxml.dylib from $(BUILDROOT)$(libdir)...
229 230 231
	$(RM) $(BUILDROOT)$(libdir)/libmxml.dylib
	$(RM) $(BUILDROOT)$(libdir)/libmxml.1.dylib

232

233 234 235 236 237 238 239 240 241 242 243 244
#
# Figure out lines-of-code...
#

.PHONY: sloc

sloc:
	echo "libmxml: \c"
	sloccount $(LIBOBJS:.o=.c) mxml-private.c mxml.h 2>/dev/null | \
		grep "Total Physical" | awk '{print $$9}'


Michael R Sweet's avatar
Michael R Sweet committed
245 246 247 248 249
#
# libmxml.a
#

libmxml.a:	$(LIBOBJS)
250
	echo Creating $@...
251
	$(RM) $@
Michael R Sweet's avatar
Michael R Sweet committed
252 253 254 255
	$(AR) $(ARFLAGS) $@ $(LIBOBJS)
	$(RANLIB) $@

$(LIBOBJS):	mxml.h
256
mxml-entity.o mxml-file.o mxml-private.o: mxml-private.h
Michael R Sweet's avatar
Michael R Sweet committed
257 258


259
#
260
# mxml1.dll
261 262
#

263
mxml1.dll:	$(LIBOBJS)
264
	echo Creating $@...
265
	$(DSO) $(DSOFLAGS) $(LDFLAGS) -o $@ $(LIBOBJS) $(LIBS)
266 267


268
#
269
# libmxml.so.1.6
270 271
#

272
libmxml.so.1.6:	$(LIBOBJS)
273
	echo Creating $@...
274
	$(DSO) $(DSOFLAGS) $(LDFLAGS) -o libmxml.so.1.6 $(LIBOBJS) $(LIBS)
275
	$(RM) libmxml.so libmxml.so.1
276 277
	$(LN) libmxml.so.1.6 libmxml.so
	$(LN) libmxml.so.1.6 libmxml.so.1
278 279 280 281 282 283 284


#
# libmxml.sl.1
#

libmxml.sl.1:	$(LIBOBJS)
285
	echo Creating $@...
286
	$(DSO) $(DSOFLAGS) $(LDFLAGS) -o libmxml.sl.1 $(LIBOBJS) $(LIBS)
287
	$(RM) libmxml.sl
288 289 290 291 292 293 294 295
	$(LN) libmxml.sl.1 libmxml.sl


#
# libmxml.1.dylib
#

libmxml.1.dylib:	$(LIBOBJS)
296
	echo Creating $@...
297
	$(DSO) $(DSOFLAGS) $(LDFLAGS) -o libmxml.1.dylib \
298
		-install_name $(libdir)/libmxml.dylib \
299
		-current_version 1.6.0 \
300
		-compatibility_version 1.0.0 \
301
		$(LIBOBJS) $(LIBS)
302
	$(RM) libmxml.dylib
303 304 305
	$(LN) libmxml.1.dylib libmxml.dylib


306 307 308 309
#
# mxmldoc
#

310
mxmldoc:	$(LIBMXML) mxmldoc.o mmd.o @ZIPC@
311
	echo Linking $@...
312
	$(CC) -L. $(LDFLAGS) -o $@ mxmldoc.o mmd.o @ZIPC@ -lmxml $(LIBS)
313

314
mxmldoc-static:	libmxml.a mxmldoc.o mmd.o @ZIPC@
315
	echo Linking $@...
316
	$(CC) $(LDFLAGS) -o $@ mxmldoc.o mmd.o @ZIPC@ libmxml.a $(LIBS)
317

318
mxmldoc.o:	mxml.h zipc.h mmd.h
319
zipc.o:		zipc.h
320
mmd.o:		mmd.h
321 322


Michael R Sweet's avatar
Michael R Sweet committed
323 324 325 326 327
#
# testmxml
#

testmxml:	libmxml.a testmxml.o
328
	echo Linking $@...
Michael R Sweet's avatar
Michael R Sweet committed
329
	$(CC) $(LDFLAGS) -o $@ testmxml.o libmxml.a $(LIBS)
Michael R Sweet's avatar
Michael R Sweet committed
330
	@echo Testing library...
331 332
	./testmxml test.xml temp1s.xml >temp1.xml
	./testmxml temp1.xml temp2s.xml >temp2.xml
Michael R Sweet's avatar
Michael R Sweet committed
333
	@if cmp temp1.xml temp2.xml; then \
Michael R Sweet's avatar
Michael R Sweet committed
334
		echo Stdio file test passed!; \
335
		$(RM) temp2.xml temp2s.xml; \
Michael R Sweet's avatar
Michael R Sweet committed
336
	else \
Michael R Sweet's avatar
Michael R Sweet committed
337
		echo Stdio file test failed!; \
338 339 340 341 342 343
	fi
	@if cmp temp1.xml temp1s.xml; then \
		echo String test passed!; \
		$(RM) temp1.xml temp1s.xml; \
	else \
		echo String test failed!; \
Michael R Sweet's avatar
Michael R Sweet committed
344
	fi
Michael R Sweet's avatar
Michael R Sweet committed
345 346 347 348 349 350
	@if cmp test.xml test.xmlfd; then \
		echo File descriptor test passed!; \
		$(RM) test.xmlfd; \
	else \
		echo File descriptor test failed!; \
	fi
Michael R Sweet's avatar
Michael R Sweet committed
351

352 353 354 355
testmxml-vg:	$(LIBOBJS) testmxml.o
	echo Linking $@...
	$(CC) $(LDFLAGS) -o $@ testmxml.o $(LIBOBJS) $(LIBS)

Michael R Sweet's avatar
Michael R Sweet committed
356 357
testmxml.o:	mxml.h

358

Michael R Sweet's avatar
Michael R Sweet committed
359 360 361 362
#
# mxml.xml
#

363
mxml.xml:	mxmldoc-static mxml.h $(PUBLIBOBJS:.o=.c) \
364
		doc/body.man doc/footer.man \
365
		doc/reference.header
366
	echo Generating API documentation...
367
	$(RM) mxml.xml
368
	./mxmldoc-static --header doc/reference.header \
369
		--docversion @VERSION@ --author "Michael R Sweet" \
370
		--copyright "Copyright 2003-2018, All Rights Reserved." \
371
		--title "Mini-XML API Reference" \
372
		mxml.xml mxml.h $(PUBLIBOBJS:.o=.c) >doc/reference.html
373
	./mxmldoc-static --man mxml --title "Mini-XML API" \
374
		--body doc/body.man --footer doc/footer.man \
375
		mxml.xml >doc/mxml.man
Michael R Sweet's avatar
Michael R Sweet committed
376

377 378 379 380 381

#
# mxml.epub
#

382
mxml.epub:	mxml.xml mxmldoc-static doc/body.md doc/mxml-cover.png
383
	echo Generating EPUB API documentation...
384
	./mxmldoc-static --body doc/body.md \
385 386
		--coverimage doc/mxml-cover.png \
		--epub mxml.epub mxml.xml
387 388 389 390 391 392


#
# Use Valgrind (http://valgrind.org) to check for problems in mxmldoc.
#

393
valgrind:	mxmldoc-static
394
	echo Doing dynamic code analysis using Valgrind...
Michael R Sweet's avatar
Michael R Sweet committed
395
	$(RM) valgrind.xml
396 397 398
	valgrind --tool=memcheck --leak-check=yes ./mxmldoc-static \
		valgrind.xml mxml.h $(PUBLIBOBJS:.o=.c) \
		>valgrind.html 2>valgrind.out
Michael R Sweet's avatar
Michael R Sweet committed
399

Michael R Sweet's avatar
Michael R Sweet committed
400

401
#
402
# All object files depend on the makefile and config header...
403 404
#

405
$(OBJS):	Makefile config.h