projects/libpws

view Makefile @ 1:e1309515d111

Add README file and manpages
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Wed Mar 25 17:10:23 2015 +0100 (2015-03-25)
parents d541e748cfd8
children 97097b4b6bfb
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 define generate-manpage-rule =
70 $(addsuffix .%,$(basename $1)): $(addsuffix .%.xml,$(basename $(firstword $1))) docbook-update-source-data.xsl
71 $$(XSLTPROC) \
72 --xinclude \
73 --stringparam package $$(PACKAGE) \
74 --stringparam version $$(VERSION) \
75 docbook-update-source-data.xsl $$< | \
76 $$(XSLTPROC) \
77 --xinclude \
78 --output $(firstword $1) \
79 $$(DOCBOOK5_MANPAGES_FLAGS) \
80 $$(DOCBOOK5_MANPAGES_STYLESHEET) \
81 -
82 $$(SED) 's,^\.HP \\w.*$$$$,.HP 4n,' $$@ >$$(@).tmp && mv $$(@).tmp $$@
83 for alias in $(wordlist 2,$(words $1),$1); do \
84 ln -sf $(notdir $(firstword $1)) $$$$alias; \
85 done
86 endef
88 DESTDIR ?=
89 prefix ?= /usr/local
90 bindir ?= $(prefix)/bin
91 libdir ?= $(prefix)/lib
92 includedir ?= $(prefix)/include
93 datadir ?= $(prefix)/share
95 OS_NAME := $(shell uname -s)
96 OS_RELEASE := $(shell uname -r)
98 ifeq ($(OS_NAME),Linux)
99 HAVE_ARC4RANDOM ?= 0
100 HAVE_ENDIAN_H ?= 1
101 HAVE_SYS_ENDIAN_H ?= 0
102 HAVE_GETENTROPY ?= 0
103 HAVE_SYS_TREE_H ?= 0
104 else ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly),)
105 HAVE_ARC4RANDOM ?= 1
106 HAVE_ENDIAN_H ?= 0
107 HAVE_SYS_ENDIAN_H ?= 1
108 HAVE_GETENTROPY ?= 0
109 HAVE_SYS_TREE_H ?= 1
110 else ifeq ($(OS_NAME),NetBSD)
111 HAVE_ARC4RANDOM ?= 1
112 HAVE_ENDIAN_H ?= 0
113 HAVE_SYS_ENDIAN_H ?= 1
114 HAVE_GETENTROPY ?= 0
115 HAVE_SYS_TREE_H ?= 1
116 else ifeq ($(OS_NAME),OpenBSD)
117 HAVE_ARC4RANDOM ?= 1
118 HAVE_ENDIAN_H ?= 0
119 HAVE_SYS_ENDIAN_H ?= 1
120 HAVE_GETENTROPY ?= 1
121 HAVE_SYS_TREE_H ?= 1
122 else ifeq ($(OS_NAME),SunOS)
123 HAVE_ARC4RANDOM ?= 0
124 HAVE_ENDIAN_H ?= 0
125 HAVE_SYS_ENDIAN_H ?= 0
126 HAVE_GETENTROPY ?= 0
127 HAVE_SYS_TREE_H ?= 0
128 else
129 HAVE_ARC4RANDOM ?= 0
130 HAVE_ENDIAN_H ?= 0
131 HAVE_SYS_ENDIAN_H ?= 0
132 HAVE_GETENTROPY ?= 0
133 HAVE_SYS_TREE_H ?= 0
134 endif
136 LIBPWS_OBJS = pws.o \
137 pws-file.o \
138 pws-record.o \
139 pws-field.o \
140 pws-random.o
141 LIBPWS_LIB = $(PACKAGE).a
142 LIBPWS_LIB_MEMBERS = $(LIBPWS_OBJS:%.o=$(LIBPWS_LIB)(%.o))
144 OBJS = $(LIBPWS_OBJS)
146 LIBPWS_MANPAGES = libpws.3
148 PWS_INIT_MANPAGES = pws_init.3 \
149 pws_finalize.3 \
150 pws_set_alloc_functions.3 \
151 pws_generate_uuid.3
153 PWS3_FILE_CREATE_MANPAGES = pws3_file_create.3 \
154 pws3_file_destroy.3 \
155 pws3_file_get_error_code.3 \
156 pws3_file_get_error_message.3 \
157 pws3_file_read_mem.3 \
158 pws3_file_read_stream.3 \
159 pws3_file_write_mem.3 \
160 pws3_file_write_stream.3 \
161 pws3_file_set_header_field.3 \
162 pws3_file_get_header_field.3 \
163 pws3_file_remove_header_field.3 \
164 pws3_file_insert_empty_group.3 \
165 pws3_file_get_empty_group.3 \
166 pws3_file_remove_empty_group.3 \
167 pws3_file_first_empty_group.3 \
168 pws3_file_last_empty_group.3 \
169 pws3_file_next_empty_group.3 \
170 pws3_file_prev_empty_group.3 \
171 pws3_file_insert_record.3 \
172 pws3_file_get_record.3 \
173 pws3_file_remove_record.3 \
174 pws3_file_first_record.3 \
175 pws3_file_last_record.3 \
176 pws3_file_next_record.3 \
177 pws3_file_prev_record.3 \
178 pws3_field_create.3 \
179 pws3_field_destroy.3 \
180 pws3_field_is_header.3 \
181 pws3_field_get_type.3 \
182 pws3_field_get_data_type.3 \
183 pws3_field_set_uuid.3 \
184 pws3_field_set_text.3 \
185 pws3_field_set_time.3 \
186 pws3_field_set_uint8.3 \
187 pws3_field_set_uint16.3 \
188 pws3_field_set_uint32.3 \
189 pws3_field_set_bytes.3 \
190 pws3_field_get_uuid.3 \
191 pws3_field_get_text.3 \
192 pws3_field_get_time.3 \
193 pws3_field_get_uint8.3 \
194 pws3_field_get_uint16.3 \
195 pws3_field_get_uint32.3 \
196 pws3_field_get_bytes.3 \
197 pws3_record_create.3 \
198 pws3_record_destroy.3 \
199 pws3_record_set_field.3 \
200 pws3_record_get_field.3 \
201 pws3_record_remove_field.3
203 MANPAGES = $(LIBPWS_MANPAGES) \
204 $(PWS_INIT_MANPAGES) \
205 $(PWS3_FILE_CREATE_MANPAGES)
207 XHTML_DOCUMENTATION = $(addsuffix .xhtml,$(firstword $(LIBPWS_MANPAGES)) \
208 $(firstword $(PWS_INIT_MANPAGES)) \
209 $(firstword $(PWS3_FILE_CREATE_MANPAGES)))
211 .DEFAULT_TARGET = all
213 .PHONY: all clean clobber dist install
215 all: $(LIBPWS_LIB) $(MANPAGES)
217 doc: $(MANPAGES) $(XHTML_DOCUMENTATION)
219 XCPPFLAGS = -Iinclude
220 ifeq ($(HAVE_ARC4RANDOM),1)
221 XCPPFLAGS += -DHAVE_ARC4RANDOM
222 endif
223 ifeq ($(HAVE_ENDIAN_H),1)
224 XCPPFLAGS += -DHAVE_ENDIAN_H
225 else ifeq ($(HAVE_SYS_ENDIAN_H),1)
226 XCPPFLAGS += -DHAVE_SYS_ENDIAN_H
227 else
228 LIBPWS_OBJS += compat/endian.o
229 endif
230 ifeq ($(HAVE_GETENTROPY),1)
231 XCPPFLAGS += -DHAVE_GETENTROPY
232 else
233 LIBPWS_OBJS += compat/getentropy.o
234 endif
235 ifeq ($(HAVE_SYS_TREE_H),1)
236 XCPPFLAGS += -DHAVE_SYS_TREE_H
237 endif
238 ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),)
239 XCPPFLAGS += -I/usr/local/include
240 XLDFLAGS += -L/usr/local/lib
241 else ifeq ($(OS_NAME),NetBSD)
242 XCPPFLAGS += -I/usr/pkg/include
243 XLDFLAGS += -L/usr/pkg/lib
244 endif
245 ifeq ($(OS_NAME),SunOS)
246 XCPPFLAGS += -I/usr/xpg4/include -D__EXTENSIONS__
247 XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib
248 endif
249 ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),)
250 XCPPFLAGS += -D_XOPEN_SOURCE=600
251 endif
253 $(LIBPWS_LIB): $(LIBPWS_LIB_MEMBERS)
255 $(eval $(call generate-manpage-rule,$(LIBPWS_MANPAGES)))
257 $(eval $(call generate-manpage-rule,$(PWS_INIT_MANPAGES)))
259 $(eval $(call generate-manpage-rule,$(PWS3_FILE_CREATE_MANPAGES)))
261 %.o: %.c
262 $(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
263 $(COMPILE.c) -o $@ $<
265 (%): %
266 $(AR) $(ARFLAGS) $@ $<
267 $(RANLIB) $@
269 %.xhtml: %.xml docbook-update-source-data.xsl
270 $(XSLTPROC) \
271 --xinclude \
272 --stringparam package $(PACKAGE) \
273 --stringparam version $(VERSION) \
274 docbook-update-source-data.xsl $< | \
275 $(XSLTPROC) \
276 --xinclude \
277 --output $@ \
278 $(DOCBOOK5_XHTML_FLAGS) \
279 $(DOCBOOK5_XHTML_STYLESHEET) \
280 -
282 install:
283 for header in include/*.h; do \
284 $(INSTALL.data) $${header} \
285 "$(DESTDIR)$(includedir)/$${header##*/}"; \
286 done
287 $(INSTALL.lib) $(LIBPWS_LIB) \
288 "$(DESTDIR)$(libdir)/$(notdir $(LIBPWS_LIB))"
289 for manpage in $(MANPAGES); do \
290 if [ -L $${manpage} ]; then \
291 $(INSTALL.link) $${manpage} \
292 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
293 else \
294 $(INSTALL.data) $${manpage} \
295 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
296 fi \
297 done
299 clean:
300 rm -f $(LIBPWS_LIB) $(LIBPWS_OBJS) $(MANPAGES) \
301 $(XHTML_DOCUMENTATION)
303 clobber: clean
304 rm -f $(patsubst %.o,%.d,$(OBJS))
306 dist: clobber
307 $(PAX) -w -x ustar -s ',.*/\..*,,' -s ',./[^/]*\.tar\.gz,,' \
308 -s ',^\.$$,,' -s ',\./,$(DISTNAME)/,' . | \
309 $(GZIP) > $(DISTNAME).tar.gz
311 -include $(patsubst %.o,%.d,$(OBJS))