comparison Makefile @ 0:d541e748cfd8

Initial revision
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Tue, 10 Feb 2015 11:29:54 +0100
parents
children e1309515d111
comparison
equal deleted inserted replaced
-1:000000000000 0:d541e748cfd8
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 #
23
24 PACKAGE = libpws
25 VERSION = 1.0.0
26 DISTNAME := $(PACKAGE)-$(VERSION)
27
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
49 DESTDIR ?=
50 prefix ?= /usr/local
51 bindir ?= $(prefix)/bin
52 libdir ?= $(prefix)/lib
53 includedir ?= $(prefix)/include
54 datadir ?= $(prefix)/share
55
56 OS_NAME := $(shell uname -s)
57 OS_RELEASE := $(shell uname -r)
58
59 ifeq ($(OS_NAME),Linux)
60 HAVE_ARC4RANDOM ?= 0
61 HAVE_ENDIAN_H ?= 1
62 HAVE_SYS_ENDIAN_H ?= 0
63 HAVE_GETENTROPY ?= 0
64 HAVE_SYS_TREE_H ?= 0
65 else ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly),)
66 HAVE_ARC4RANDOM ?= 1
67 HAVE_ENDIAN_H ?= 0
68 HAVE_SYS_ENDIAN_H ?= 1
69 HAVE_GETENTROPY ?= 0
70 HAVE_SYS_TREE_H ?= 1
71 else ifeq ($(OS_NAME),NetBSD)
72 HAVE_ARC4RANDOM ?= 1
73 HAVE_ENDIAN_H ?= 0
74 HAVE_SYS_ENDIAN_H ?= 1
75 HAVE_GETENTROPY ?= 0
76 HAVE_SYS_TREE_H ?= 1
77 else ifeq ($(OS_NAME),OpenBSD)
78 HAVE_ARC4RANDOM ?= 1
79 HAVE_ENDIAN_H ?= 0
80 HAVE_SYS_ENDIAN_H ?= 1
81 HAVE_GETENTROPY ?= 1
82 HAVE_SYS_TREE_H ?= 1
83 else ifeq ($(OS_NAME),SunOS)
84 HAVE_ARC4RANDOM ?= 0
85 HAVE_ENDIAN_H ?= 0
86 HAVE_SYS_ENDIAN_H ?= 0
87 HAVE_GETENTROPY ?= 0
88 HAVE_SYS_TREE_H ?= 0
89 else
90 HAVE_ARC4RANDOM ?= 0
91 HAVE_ENDIAN_H ?= 0
92 HAVE_SYS_ENDIAN_H ?= 0
93 HAVE_GETENTROPY ?= 0
94 HAVE_SYS_TREE_H ?= 0
95 endif
96
97 LIBPWS_OBJS = pws.o \
98 pws-file.o \
99 pws-record.o \
100 pws-field.o \
101 pws-random.o
102 LIBPWS_LIB = $(PACKAGE).a
103 LIBPWS_LIB_MEMBERS = $(LIBPWS_OBJS:%.o=$(LIBPWS_LIB)(%.o))
104
105 OBJS = $(LIBPWS_OBJS)
106
107 .DEFAULT_TARGET = all
108
109 .PHONY: all clean clobber dist install
110
111 all: $(LIBPWS_LIB)
112
113 XCPPFLAGS = -Iinclude
114 ifeq ($(HAVE_ARC4RANDOM),1)
115 XCPPFLAGS += -DHAVE_ARC4RANDOM
116 endif
117 ifeq ($(HAVE_ENDIAN_H),1)
118 XCPPFLAGS += -DHAVE_ENDIAN_H
119 else ifeq ($(HAVE_SYS_ENDIAN_H),1)
120 XCPPFLAGS += -DHAVE_SYS_ENDIAN_H
121 else
122 LIBPWS_OBJS += compat/endian.o
123 endif
124 ifeq ($(HAVE_GETENTROPY),1)
125 XCPPFLAGS += -DHAVE_GETENTROPY
126 else
127 LIBPWS_OBJS += compat/getentropy.o
128 endif
129 ifeq ($(HAVE_SYS_TREE_H),1)
130 XCPPFLAGS += -DHAVE_SYS_TREE_H
131 endif
132 ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),)
133 XCPPFLAGS += -I/usr/local/include
134 XLDFLAGS += -L/usr/local/lib
135 else ifeq ($(OS_NAME),NetBSD)
136 XCPPFLAGS += -I/usr/pkg/include
137 XLDFLAGS += -L/usr/pkg/lib
138 endif
139 ifeq ($(OS_NAME),SunOS)
140 XCPPFLAGS += -I/usr/xpg4/include -D__EXTENSIONS__
141 XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib
142 endif
143 ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),)
144 XCPPFLAGS += -D_XOPEN_SOURCE=600
145 endif
146
147 $(LIBPWS_LIB): $(LIBPWS_LIB_MEMBERS)
148
149 %.o: %.c
150 $(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
151 $(COMPILE.c) -o $@ $<
152
153 (%): %
154 $(AR) $(ARFLAGS) $@ $<
155 $(RANLIB) $@
156
157 install:
158 for header in include/*.h; do \
159 $(INSTALL.data) $${header} \
160 "$(DESTDIR)$(includedir)/$(PACKAGE)/$${header##*/}"; \
161 done
162 $(INSTALL.lib) $(LIBPWS_LIB) \
163 "$(DESTDIR)$(libdir)/$(notdir $(LIBPWS_LIB))"
164
165 clean:
166 rm -f $(LIBPWS_LIB) $(LIBPWS_OBJS)
167
168 clobber: clean
169 rm -f $(patsubst %.o,%.d,$(OBJS))
170
171 dist: clobber
172 $(PAX) -w -x ustar -s ',.*/\..*,,' -s ',./[^/]*\.tar\.gz,,' \
173 -s ',^\.$$,,' -s ',\./,$(DISTNAME)/,' . | \
174 $(GZIP) > $(DISTNAME).tar.gz
175
176 -include $(patsubst %.o,%.d,$(OBJS))