projects/pwm

view Makefile @ 34:34ada71ff3e5

Allow local makefile overrides in local.mk
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Wed Jul 31 11:21:54 2019 +0200 (2019-07-31)
parents 00d782cb45fa
children f9501248b6bd
line source
1 #
2 # Copyright (C) 2017 Guido Berhoerster <guido+pwm@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 = pwm
25 VERSION = 1
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 CP := cp
42 INSTALL := install
43 INSTALL.exec := $(INSTALL) -D -m 0755
44 INSTALL.data := $(INSTALL) -D -m 0644
45 INSTALL.link := $(CP) -f -P
46 PAX := pax
47 GZIP := gzip
48 SED := sed
49 XSLTPROC := xsltproc
50 DOCBOOK5_MANPAGES_STYLESHEET = http://docbook.sourceforge.net/release/xsl-ns/current/manpages/docbook.xsl
51 DOCBOOK5_MANPAGES_FLAGS = --stringparam man.authors.section.enabled 0 \
52 --stringparam man.copyright.section.enabled 0
54 define generate-manpage-rule =
55 $(addsuffix .%,$(basename $1)): $(addsuffix .%.xml,$(basename $(firstword $1))) docbook-update-source-data.xsl
56 $$(XSLTPROC) \
57 --xinclude \
58 --stringparam package $$(PACKAGE) \
59 --stringparam version $$(VERSION) \
60 docbook-update-source-data.xsl $$< | \
61 $$(XSLTPROC) \
62 --xinclude \
63 --output $(firstword $1) \
64 $$(DOCBOOK5_MANPAGES_FLAGS) \
65 $$(DOCBOOK5_MANPAGES_STYLESHEET) \
66 -
67 for alias in $(wordlist 2,$(words $1),$1); do \
68 ln -sf $(notdir $(firstword $1)) $$$$alias; \
69 done
70 endef
72 DESTDIR ?=
73 prefix ?= /usr/local
74 bindir ?= $(prefix)/bin
75 datadir ?= $(prefix)/share
76 mandir ?= $(datadir)/man
78 OS_NAME := $(shell uname -s)
79 OS_RELEASE := $(shell uname -r)
81 ifeq ($(OS_NAME),Linux)
82 HAVE_ARC4RANDOM ?= 0
83 HAVE_ASPRINTF ?= 1
84 HAVE_CLOSEFROM ?= 0
85 HAVE_ERR_H ?= 1
86 HAVE_GETLINE ?= 0
87 HAVE_GETRANDOM ?= 0
88 HAVE_SYS_QUEUE_H ?= 0
89 HAVE_SETPROGNAME ?= 0
90 HAVE_SYS_TREE_H ?= 0
91 else ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly),)
92 HAVE_ARC4RANDOM ?= 1
93 HAVE_ASPRINTF ?= 1
94 HAVE_CLOSEFROM ?= 1
95 HAVE_ERR_H ?= 1
96 HAVE_GETLINE ?= 1
97 HAVE_GETRANDOM ?= 0
98 HAVE_SYS_QUEUE_H ?= 1
99 HAVE_SETPROGNAME ?= 1
100 HAVE_SYS_TREE_H ?= 1
101 else ifeq ($(OS_NAME),NetBSD)
102 HAVE_ARC4RANDOM ?= 1
103 HAVE_ASPRINTF ?= 1
104 HAVE_CLOSEFROM ?= 1
105 HAVE_ERR_H ?= 1
106 HAVE_GETLINE ?= 1
107 HAVE_GETRANDOM ?= 0
108 HAVE_SYS_QUEUE_H ?= 1
109 HAVE_SYS_TREE_H ?= 1
110 HAVE_SETPROGNAME ?= 1
111 else ifeq ($(OS_NAME),OpenBSD)
112 HAVE_ARC4RANDOM ?= 1
113 HAVE_ASPRINTF ?= 1
114 HAVE_CLOSEFROM ?= 1
115 HAVE_ERR_H ?= 1
116 HAVE_GETLINE ?= 1
117 HAVE_GETRANDOM ?= 0
118 HAVE_SYS_QUEUE_H ?= 1
119 HAVE_SYS_TREE_H ?= 1
120 HAVE_SETPROGNAME ?= 1
121 else ifeq ($(OS_NAME),SunOS)
122 ifeq ($(OS_RELEASE),5.10)
123 HAVE_ARC4RANDOM ?= 0
124 HAVE_ASPRINTF ?= 0
125 HAVE_ERR_H ?= 0
126 HAVE_GETLINE ?= 0
127 HAVE_GETRANDOM ?= 0
128 else
129 HAVE_ARC4RANDOM ?= 1
130 HAVE_ASPRINTF ?= 1
131 HAVE_ERR_H ?= 1
132 HAVE_GETLINE ?= 1
133 HAVE_GETRANDOM ?= 1
134 endif
135 HAVE_CLOSEFROM ?= 1
136 HAVE_SYS_QUEUE_H ?= 0
137 HAVE_SYS_TREE_H ?= 0
138 HAVE_SETPROGNAME ?= 0
139 else
140 HAVE_ARC4RANDOM ?= 0
141 HAVE_ASPRINTF ?= 0
142 HAVE_CLOSEFROM ?= 0
143 HAVE_ERR_H ?= 0
144 HAVE_GETLINE ?= 0
145 HAVE_GETRANDOM ?= 0
146 HAVE_SYS_QUEUE_H ?= 0
147 HAVE_SETPROGNAME ?= 0
148 HAVE_SYS_TREE_H ?= 0
149 endif
151 LIBCOMPAT_OBJS = compat/compat.o
152 LIBCOMPAT_LIB = compat/libcompat.a
153 LIBCOMPAT_LIB_MEMBERS = $(LIBCOMPAT_OBJS:%.o=$(LIBCOMPAT_LIB)(%.o))
155 LIBPWM_OBJS = util.o
156 LIBPWM_LIB = libpwm.a
157 LIBPWM_LIB_MEMBERS = $(LIBPWM_OBJS:%.o=$(LIBPWM_LIB)(%.o))
159 PWM_CLIP_OBJS = pwm-clip.o
160 PWM_CLIP_BIN = pwm-clip
161 PWM_CLIP_MAN1 = pwm-clip.1
163 PWM_OBJS = cmd.o \
164 io.o \
165 macro.o \
166 pager.o \
167 proc.o \
168 pw.o \
169 pwfile.o \
170 pwm.o \
171 pwmrc.o \
172 tok.o
173 PWM_BIN = $(PACKAGE)
174 PWM_MAN1 = pwm.1
176 OBJS = $(LIBCOMPAT_OBJS) $(LIBPWM_OBJS) $(PWM_CLIP_OBJS) $(PWM_OBJS)
178 MANPAGES = $(PWM_MAN1) $(PWM_CLIP_MAN1)
180 .DEFAULT_TARGET = all
182 .PHONY: all clean clobber dist install
184 all: $(PWM_BIN) $(PWM_CLIP_BIN) $(MANPAGES)
186 $(PWM_BIN): XCPPFLAGS += -DPACKAGE=\"$(PACKAGE)\" \
187 -DVERSION=\"$(VERSION)\"
188 $(PWM_BIN): LDLIBS = -ltecla -lcurses -lpws -lnettle
189 $(PWM_CLIP_BIN): XCPPFLAGS += -Icompat/include
190 $(PWM_CLIP_BIN): LDLIBS = -lnettle
191 ifeq ($(HAVE_ASPRINTF),1)
192 XCPPFLAGS += -DHAVE_ASPRINTF
193 else
194 LIBCOMPAT_OBJS += compat/asprintf.o
195 endif
196 ifeq ($(HAVE_ARC4RANDOM),1)
197 XCPPFLAGS += -DHAVE_ARC4RANDOM
198 LIBPWM_OBJS += rand-arc4random.o
199 else ifeq ($(HAVE_GETRANDOM),1)
200 XCPPFLAGS += -DHAVE_GETRANDOM
201 LIBPWM_OBJS += rand-getrandom.o
202 else
203 LIBPWM_OBJS += rand-dev-random.o
204 endif
205 ifeq ($(HAVE_CLOSEFROM),1)
206 XCPPFLAGS += -DHAVE_CLOSEFROM
207 else
208 LIBCOMPAT_OBJS += compat/closefrom.o
209 endif
210 ifeq ($(HAVE_ERR_H),1)
211 XCPPFLAGS += -DHAVE_ERR_H
212 else
213 LIBCOMPAT_OBJS += compat/err.o
214 endif
215 ifeq ($(HAVE_GETLINE),1)
216 XCPPFLAGS += -DHAVE_GETLINE
217 else
218 LIBCOMPAT_OBJS += compat/getline.o
219 endif
220 ifeq ($(HAVE_SETPROGNAME),1)
221 XCPPFLAGS += -DHAVE_SETPROGNAME
222 else
223 LIBCOMPAT_OBJS += compat/setprogname.o
224 endif
225 ifeq ($(HAVE_SYS_TREE_H),1)
226 XCPPFLAGS += -DHAVE_SYS_TREE_H
227 endif
228 ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),)
229 XCPPFLAGS += -I/usr/local/include
230 XLDFLAGS += -L/usr/local/lib
231 else ifeq ($(OS_NAME),NetBSD)
232 XCPPFLAGS += -I/usr/pkg/include
233 XLDFLAGS += -L/usr/pkg/lib
234 endif
235 ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),)
236 XCPPFLAGS += -D_XOPEN_SOURCE=600
237 endif
238 ifeq ($(OS_NAME),SunOS)
239 XCPPFLAGS += -I/usr/xpg4/include -D__EXTENSIONS__
240 XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib
241 endif
243 $(LIBCOMPAT_LIB): $(LIBCOMPAT_LIB_MEMBERS)
245 $(LIBPWM_LIB): $(LIBPWM_LIB_MEMBERS)
247 $(PWM_CLIP_BIN): $(PWM_CLIP_OBJS) $(LIBPWM_LIB) $(LIBCOMPAT_LIB)
248 $(LINK.o) $^ $(LDLIBS) -o $@
250 $(eval $(call generate-manpage-rule,$(PWM_CLIP_MAN1)))
252 $(PWM_BIN): $(PWM_OBJS) $(LIBPWM_LIB) $(LIBCOMPAT_LIB)
253 $(LINK.o) $^ $(LDLIBS) -o $@
255 $(eval $(call generate-manpage-rule,$(PWM_MAN1)))
257 %.o: %.c
258 $(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
259 $(COMPILE.c) -o $@ $<
261 (%): %
262 $(AR) $(ARFLAGS) $@ $<
263 $(RANLIB) $@
265 install: all
266 $(INSTALL.exec) $(PWM_BIN) "$(DESTDIR)$(bindir)/$(PWM_BIN)"
267 $(INSTALL.exec) $(PWM_CLIP_BIN) "$(DESTDIR)$(bindir)/$(PWM_CLIP_BIN)"
268 for manpage in $(MANPAGES); do \
269 if [ -L $${manpage} ]; then \
270 $(INSTALL.link) $${manpage} \
271 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
272 else \
273 $(INSTALL.data) $${manpage} \
274 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
275 fi \
276 done
278 clean:
279 rm -f $(LIBCOMPAT_LIB) $(LIBPWM_LIB) $(PWM_CLIP_BIN) $(PWM_BIN) \
280 $(OBJS) $(MANPAGES)
282 clobber: clean
283 rm -f $(patsubst %.o,%.d,$(OBJS))
285 dist: clobber
286 $(PAX) -w -x ustar -s ',.*/\..*,,' -s ',./[^/]*\.tar\.gz,,' \
287 -s ',^\.$$,,' -s ',\./,$(DISTNAME)/,' . | \
288 $(GZIP) > $(DISTNAME).tar.gz
290 -include local.mk
292 -include $(patsubst %.o,%.d,$(OBJS))