projects/libpws

view Makefile @ 13:2bb1bbac1d0a

Added tag version-1.0.0 for changeset 1926dfc9feb0
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Sun Aug 04 21:37:56 2019 +0200 (2019-08-04)
parents dfd3ddbdb201
children
line source
1 #
2 # Copyright (C) 2015 Guido Berhoerster <guido+libpws@berhoerster.name>
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #
24 PACKAGE = libpws
25 VERSION = 1.0.0
26 DISTNAME := $(PACKAGE)-$(VERSION)
28 # gcc, clang, icc, Sun/Solaris Studio
29 CC := $(CC) -std=c99
30 COMPILE.c = $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(TARGET_ARCH) -c
31 # gcc, clang, icc
32 MAKEDEPEND.c = $(CC) -MM $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
33 # Sun/Solaris Studio
34 #MAKEDEPEND.c = $(CC) -xM1 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
35 # X makedepend
36 #MAKEDEPEND.c = makedepend -f- -Y -- $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) --
37 LINK.c = $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
38 LINK.o = $(CC) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
39 AR := ar
40 RANLIB := ranlib
41 INSTALL := install
42 INSTALL.exec := $(INSTALL) -D -m 0755
43 INSTALL.lib := $(INSTALL) -D -m 0644
44 INSTALL.data := $(INSTALL) -D -m 0644
45 PAX := pax
46 GZIP := gzip
47 SED := sed
48 XSLTPROC := xsltproc
49 DOCBOOK5_MANPAGES_STYLESHEET = http://docbook.sourceforge.net/release/xsl-ns/current/manpages/docbook.xsl
50 DOCBOOK5_MANPAGES_FLAGS = --stringparam funcsynopsis.style 'ansi' \
51 --stringparam man.authors.section.enabled 0 \
52 --stringparam man.copyright.section.enabled 0
53 DOCBOOK5_XHTML_STYLESHEET = http://docbook.sourceforge.net/release/xsl-ns/current/xhtml/docbook.xsl
54 DOCBOOK5_XHTML_FLAGS = --stringparam funcsynopsis.style 'ansi' \
55 --stringparam generate.consistent.ids 1 \
56 --stringparam refentry.generate.name 1 \
57 --stringparam refentry.generate.title 0 \
58 --stringparam refentry.xref.manvolnum 1 \
59 --stringparam generate.id.attributes 1 \
60 --stringparam make.valid.html 1 \
61 --stringparam make.clean.html 1 \
62 --stringparam html.cleanup 1 \
63 --stringparam html.longdesc 0 \
64 --stringparam ulink.target '' \
65 --stringparam docbook.css.source '' \
66 --stringparam css.decoration 0 \
67 --stringparam default.table.width '100%'
69 TESTS_OUTPUT_PATH = ./tests/output
71 define generate-manpage-rule =
72 $(addsuffix .%,$(basename $1)): $(addsuffix .%.xml,$(basename $(firstword $1))) docbook-update-source-data.xsl
73 $$(XSLTPROC) \
74 --xinclude \
75 --stringparam package $$(PACKAGE) \
76 --stringparam version $$(VERSION) \
77 docbook-update-source-data.xsl $$< | \
78 $$(XSLTPROC) \
79 --xinclude \
80 --output $(firstword $1) \
81 $$(DOCBOOK5_MANPAGES_FLAGS) \
82 $$(DOCBOOK5_MANPAGES_STYLESHEET) \
83 -
84 $$(SED) 's,^\.HP \\w.*$$$$,.HP 4n,' $$@ >$$(@).tmp && mv $$(@).tmp $$@
85 for alias in $(wordlist 2,$(words $1),$1); do \
86 ln -sf $(notdir $(firstword $1)) $$$$alias; \
87 done
88 endef
90 DESTDIR ?=
91 prefix ?= /usr/local
92 bindir ?= $(prefix)/bin
93 libdir ?= $(prefix)/lib
94 includedir ?= $(prefix)/include
95 datadir ?= $(prefix)/share
97 OS_NAME := $(shell uname -s)
98 OS_RELEASE := $(shell uname -r)
100 ifeq ($(OS_NAME),Linux)
101 HAVE_ARC4RANDOM ?= 0
102 HAVE_ENDIAN_H ?= 1
103 HAVE_SYS_ENDIAN_H ?= 0
104 HAVE_ERR_H ?= 1
105 HAVE_GETENTROPY ?= 0
106 HAVE_GETLINE ?= 0
107 HAVE_SETPROGNAME ?= 0
108 HAVE_READPASSPHRASE_H ?= 0
109 HAVE_SYS_TREE_H ?= 0
110 HAVE_VIS_H ?= 0
111 else ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly),)
112 HAVE_ARC4RANDOM ?= 1
113 HAVE_ENDIAN_H ?= 0
114 HAVE_SYS_ENDIAN_H ?= 1
115 HAVE_ERR_H ?= 1
116 HAVE_GETENTROPY ?= 0
117 HAVE_GETLINE ?= 1
118 HAVE_SETPROGNAME ?= 1
119 HAVE_READPASSPHRASE_H ?= 1
120 HAVE_SYS_TREE_H ?= 1
121 HAVE_VIS_H ?= 1
122 else ifeq ($(OS_NAME),NetBSD)
123 HAVE_ARC4RANDOM ?= 1
124 HAVE_ENDIAN_H ?= 0
125 HAVE_SYS_ENDIAN_H ?= 1
126 HAVE_ERR_H ?= 1
127 HAVE_GETENTROPY ?= 0
128 HAVE_GETLINE ?= 1
129 HAVE_SETPROGNAME ?= 1
130 HAVE_READPASSPHRASE_H ?= 0
131 HAVE_SYS_TREE_H ?= 1
132 HAVE_VIS_H ?= 1
133 else ifeq ($(OS_NAME),OpenBSD)
134 HAVE_ARC4RANDOM ?= 1
135 HAVE_ENDIAN_H ?= 0
136 HAVE_SYS_ENDIAN_H ?= 1
137 HAVE_ERR_H ?= 1
138 HAVE_GETENTROPY ?= 1
139 HAVE_GETLINE ?= 1
140 HAVE_SETPROGNAME ?= 1
141 HAVE_READPASSPHRASE_H ?= 1
142 HAVE_SYS_TREE_H ?= 1
143 HAVE_VIS_H ?= 1
144 else ifeq ($(OS_NAME),SunOS)
145 HAVE_ARC4RANDOM ?= 0
146 HAVE_ENDIAN_H ?= 0
147 HAVE_SYS_ENDIAN_H ?= 0
148 HAVE_GETENTROPY ?= 0
149 ifeq ($(OS_RELEASE),5.10)
150 HAVE_ERR_H ?= 0
151 HAVE_GETLINE ?= 0
152 else
153 HAVE_ERR_H ?= 1
154 HAVE_GETLINE ?= 1
155 endif
156 HAVE_SETPROGNAME ?= 0
157 HAVE_READPASSPHRASE_H ?= 0
158 HAVE_SYS_TREE_H ?= 0
159 HAVE_VIS_H ?= 0
160 else
161 HAVE_ARC4RANDOM ?= 0
162 HAVE_ENDIAN_H ?= 0
163 HAVE_SYS_ENDIAN_H ?= 0
164 HAVE_ERR_H ?= 0
165 HAVE_GETENTROPY ?= 0
166 HAVE_GETLINE ?= 0
167 HAVE_SETPROGNAME ?= 0
168 HAVE_READPASSPHRASE_H ?= 0
169 HAVE_SYS_TREE_H ?= 0
170 HAVE_VIS_H ?= 0
171 endif
173 LIBPWS_OBJS = pws.o \
174 pws-file.o \
175 pws-record.o \
176 pws-field.o \
177 pws-random.o
178 LIBPWS_LIB = $(PACKAGE).a
179 LIBPWS_LIB_MEMBERS = $(LIBPWS_OBJS:%.o=$(LIBPWS_LIB)(%.o))
181 PWSDUMP_BIN = pwsdump
182 PWSDUMP_OBJS = pwsdump.o
184 OBJS = $(LIBPWS_OBJS) $(PWSDUMP_OBJS)
186 LIBPWS_MANPAGES = libpws.3
188 PWS_INIT_MANPAGES = pws_init.3 \
189 pws_finalize.3 \
190 pws_set_alloc_functions.3 \
191 pws_generate_uuid.3
193 PWS3_FILE_CREATE_MANPAGES = pws3_file_create.3 \
194 pws3_file_destroy.3 \
195 pws3_file_get_error_code.3 \
196 pws3_file_get_error_message.3 \
197 pws3_file_read_mem.3 \
198 pws3_file_read_stream.3 \
199 pws3_file_write_mem.3 \
200 pws3_file_write_stream.3 \
201 pws3_file_set_header_field.3 \
202 pws3_file_get_header_field.3 \
203 pws3_file_remove_header_field.3 \
204 pws3_file_insert_empty_group.3 \
205 pws3_file_get_empty_group.3 \
206 pws3_file_remove_empty_group.3 \
207 pws3_file_first_empty_group.3 \
208 pws3_file_last_empty_group.3 \
209 pws3_file_next_empty_group.3 \
210 pws3_file_prev_empty_group.3 \
211 pws3_file_insert_record.3 \
212 pws3_file_get_record.3 \
213 pws3_file_remove_record.3 \
214 pws3_file_first_record.3 \
215 pws3_file_last_record.3 \
216 pws3_file_next_record.3 \
217 pws3_file_prev_record.3 \
218 pws3_field_create.3 \
219 pws3_field_destroy.3 \
220 pws3_field_is_header.3 \
221 pws3_field_get_type.3 \
222 pws3_field_get_data_type.3 \
223 pws3_field_set_uuid.3 \
224 pws3_field_set_text.3 \
225 pws3_field_set_time.3 \
226 pws3_field_set_uint8.3 \
227 pws3_field_set_uint16.3 \
228 pws3_field_set_uint32.3 \
229 pws3_field_set_bytes.3 \
230 pws3_field_get_uuid.3 \
231 pws3_field_get_text.3 \
232 pws3_field_get_time.3 \
233 pws3_field_get_uint8.3 \
234 pws3_field_get_uint16.3 \
235 pws3_field_get_uint32.3 \
236 pws3_field_get_bytes.3 \
237 pws3_record_create.3 \
238 pws3_record_destroy.3 \
239 pws3_record_set_field.3 \
240 pws3_record_get_field.3 \
241 pws3_record_remove_field.3
243 MANPAGES = $(LIBPWS_MANPAGES) \
244 $(PWS_INIT_MANPAGES) \
245 $(PWS3_FILE_CREATE_MANPAGES)
247 XHTML_DOCUMENTATION = $(addsuffix .xhtml,$(firstword $(LIBPWS_MANPAGES)) \
248 $(firstword $(PWS_INIT_MANPAGES)) \
249 $(firstword $(PWS3_FILE_CREATE_MANPAGES)))
251 .DEFAULT_TARGET = all
253 .PHONY: all clean clobber dist install check
255 all: $(PWSDUMP_BIN) $(LIBPWS_LIB) $(MANPAGES)
257 doc: $(MANPAGES) $(XHTML_DOCUMENTATION)
259 XCPPFLAGS = -Iinclude
260 ifeq ($(HAVE_ARC4RANDOM),1)
261 XCPPFLAGS += -DHAVE_ARC4RANDOM
262 endif
263 ifeq ($(HAVE_ENDIAN_H),1)
264 XCPPFLAGS += -DHAVE_ENDIAN_H
265 else ifeq ($(HAVE_SYS_ENDIAN_H),1)
266 XCPPFLAGS += -DHAVE_SYS_ENDIAN_H
267 else
268 LIBPWS_OBJS += compat/endian.o
269 PWSDUMP_OBJS += compat/endian.o
270 endif
271 ifeq ($(HAVE_ERR_H),1)
272 XCPPFLAGS += -DHAVE_ERR_H
273 else
274 PWSDUMP_OBJS += compat/err.o
275 endif
276 ifeq ($(HAVE_GETENTROPY),1)
277 XCPPFLAGS += -DHAVE_GETENTROPY
278 else
279 LIBPWS_OBJS += compat/getentropy.o
280 endif
281 ifeq ($(HAVE_GETLINE),1)
282 XCPPFLAGS += -DHAVE_GETLINE
283 else
284 PWSDUMP_OBJS += compat/getline.o
285 endif
286 ifeq ($(HAVE_READPASSPHRASE_H),1)
287 XCPPFLAGS += -DHAVE_READPASSPHRASE_H
288 else
289 PWSDUMP_OBJS += compat/readpassphrase.o
290 endif
291 ifeq ($(HAVE_SETPROGNAME),1)
292 XCPPFLAGS += -DHAVE_SETPROGNAME
293 else
294 PWSDUMP_OBJS += compat/setprogname.o
295 endif
296 ifeq ($(HAVE_SYS_TREE_H),1)
297 XCPPFLAGS += -DHAVE_SYS_TREE_H
298 endif
299 ifeq ($(HAVE_VIS_H),1)
300 XCPPFLAGS += -DHAVE_VIS_H
301 else
302 PWSDUMP_OBJS += compat/vis.o compat/unvis.o
303 endif
304 ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),)
305 XCPPFLAGS += -I/usr/local/include
306 XLDFLAGS += -L/usr/local/lib
307 else ifeq ($(OS_NAME),NetBSD)
308 XCPPFLAGS += -I/usr/pkg/include
309 XLDFLAGS += -L/usr/pkg/lib
310 endif
311 ifeq ($(OS_NAME),SunOS)
312 XCPPFLAGS += -I/usr/xpg4/include -D__EXTENSIONS__
313 XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib
314 endif
315 ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),)
316 XCPPFLAGS += -D_XOPEN_SOURCE=600
317 endif
319 $(LIBPWS_LIB): $(LIBPWS_LIB_MEMBERS)
321 $(eval $(call generate-manpage-rule,$(LIBPWS_MANPAGES)))
323 $(eval $(call generate-manpage-rule,$(PWS_INIT_MANPAGES)))
325 $(eval $(call generate-manpage-rule,$(PWS3_FILE_CREATE_MANPAGES)))
327 $(PWSDUMP_BIN): $(PWSDUMP_OBJS) $(LIBPWS_LIB) -lnettle
329 %.o: %.c
330 $(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
331 $(COMPILE.c) -o $@ $<
333 (%): %
334 $(AR) $(ARFLAGS) $@ $<
335 $(RANLIB) $@
337 %.xhtml: %.xml docbook-update-source-data.xsl
338 $(XSLTPROC) \
339 --xinclude \
340 --stringparam package $(PACKAGE) \
341 --stringparam version $(VERSION) \
342 docbook-update-source-data.xsl $< | \
343 $(XSLTPROC) \
344 --xinclude \
345 --output $@ \
346 $(DOCBOOK5_XHTML_FLAGS) \
347 $(DOCBOOK5_XHTML_STYLESHEET) \
348 -
350 install:
351 for header in include/*.h; do \
352 $(INSTALL.data) $${header} \
353 "$(DESTDIR)$(includedir)/$${header##*/}"; \
354 done
355 $(INSTALL.lib) $(LIBPWS_LIB) \
356 "$(DESTDIR)$(libdir)/$(notdir $(LIBPWS_LIB))"
357 for manpage in $(MANPAGES); do \
358 if [ -L $${manpage} ]; then \
359 $(INSTALL.link) $${manpage} \
360 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
361 else \
362 $(INSTALL.data) $${manpage} \
363 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
364 fi \
365 done
367 check: $(PWSDUMP_BIN)
368 rm -rf $(TESTS_OUTPUT_PATH); \
369 SHELL=$(SHELL) PWSDUMP=$(PWSDUMP_BIN) \
370 TESTS_OUTPUT_PATH=$(TESTS_OUTPUT_PATH) $(SHELL) tests/run-tests.sh
372 clean:
373 rm -f $(LIBPWS_LIB) $(PWSDUMP_BIN) $(OBJS) $(MANPAGES) \
374 $(XHTML_DOCUMENTATION)
375 rm -rf $(TESTS_OUTPUT_PATH)
377 clobber: clean
378 rm -f $(patsubst %.o,%.d,$(OBJS))
380 dist: clobber
381 $(PAX) -w -x ustar -s ',.*/\..*,,' -s ',./[^/]*\.tar\.gz,,' \
382 -s ',^\.$$,,' -s ',\./,$(DISTNAME)/,' . | \
383 $(GZIP) > $(DISTNAME).tar.gz
385 -include local.mk
387 -include $(patsubst %.o,%.d,$(OBJS))