projects/pwm

view Makefile @ 27:722a45b4028b

Add define command for defining macros

Macros are parsed when they are defined with the D command and can
subsequently be used as arguments for other commands.
Handle out of memory errors directly in tok.c.
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Mon Sep 25 21:21:25 2017 +0200 (2017-09-25)
parents 5bdea77d0c1d
children 00d782cb45fa
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 tok.o
172 PWM_BIN = $(PACKAGE)
173 PWM_MAN1 = pwm.1
175 OBJS = $(LIBCOMPAT_OBJS) $(LIBPWM_OBJS) $(PWM_CLIP_OBJS) $(PWM_OBJS)
177 MANPAGES = $(PWM_MAN1) $(PWM_CLIP_MAN1)
179 .DEFAULT_TARGET = all
181 .PHONY: all clean clobber dist install
183 all: $(PWM_BIN) $(PWM_CLIP_BIN) $(MANPAGES)
185 $(PWM_BIN): XCPPFLAGS += -DPACKAGE=\"$(PACKAGE)\" \
186 -DVERSION=\"$(VERSION)\"
187 $(PWM_BIN): LDLIBS = -ltecla -lcurses -lpws -lnettle
188 $(PWM_CLIP_BIN): XCPPFLAGS += -Icompat/include
189 $(PWM_CLIP_BIN): LDLIBS = -lnettle
190 ifeq ($(HAVE_ASPRINTF),1)
191 XCPPFLAGS += -DHAVE_ASPRINTF
192 else
193 LIBCOMPAT_OBJS += compat/asprintf.o
194 endif
195 ifeq ($(HAVE_ARC4RANDOM),1)
196 XCPPFLAGS += -DHAVE_ARC4RANDOM
197 LIBPWM_OBJS += rand-arc4random.o
198 else ifeq ($(HAVE_GETRANDOM),1)
199 XCPPFLAGS += -DHAVE_GETRANDOM
200 LIBPWM_OBJS += rand-getrandom.o
201 else
202 LIBPWM_OBJS += rand-dev-random.o
203 endif
204 ifeq ($(HAVE_CLOSEFROM),1)
205 XCPPFLAGS += -DHAVE_CLOSEFROM
206 else
207 LIBCOMPAT_OBJS += compat/closefrom.o
208 endif
209 ifeq ($(HAVE_ERR_H),1)
210 XCPPFLAGS += -DHAVE_ERR_H
211 else
212 LIBCOMPAT_OBJS += compat/err.o
213 endif
214 ifeq ($(HAVE_GETLINE),1)
215 XCPPFLAGS += -DHAVE_GETLINE
216 else
217 LIBCOMPAT_OBJS += compat/getline.o
218 endif
219 ifeq ($(HAVE_SETPROGNAME),1)
220 XCPPFLAGS += -DHAVE_SETPROGNAME
221 else
222 LIBCOMPAT_OBJS += compat/setprogname.o
223 endif
224 ifeq ($(HAVE_SYS_TREE_H),1)
225 XCPPFLAGS += -DHAVE_SYS_TREE_H
226 endif
227 ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),)
228 XCPPFLAGS += -I/usr/local/include
229 XLDFLAGS += -L/usr/local/lib
230 else ifeq ($(OS_NAME),NetBSD)
231 XCPPFLAGS += -I/usr/pkg/include
232 XLDFLAGS += -L/usr/pkg/lib
233 endif
234 ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),)
235 XCPPFLAGS += -D_XOPEN_SOURCE=600
236 endif
237 ifeq ($(OS_NAME),SunOS)
238 XCPPFLAGS += -I/usr/xpg4/include -D__EXTENSIONS__
239 XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib
240 endif
242 $(LIBCOMPAT_LIB): $(LIBCOMPAT_LIB_MEMBERS)
244 $(LIBPWM_LIB): $(LIBPWM_LIB_MEMBERS)
246 $(PWM_CLIP_BIN): $(PWM_CLIP_OBJS) $(LIBPWM_LIB) $(LIBCOMPAT_LIB)
247 $(LINK.o) $^ $(LDLIBS) -o $@
249 $(eval $(call generate-manpage-rule,$(PWM_CLIP_MAN1)))
251 $(PWM_BIN): $(PWM_OBJS) $(LIBPWM_LIB) $(LIBCOMPAT_LIB)
252 $(LINK.o) $^ $(LDLIBS) -o $@
254 $(eval $(call generate-manpage-rule,$(PWM_MAN1)))
256 %.o: %.c
257 $(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
258 $(COMPILE.c) -o $@ $<
260 (%): %
261 $(AR) $(ARFLAGS) $@ $<
262 $(RANLIB) $@
264 install: all
265 $(INSTALL.exec) $(PWM_BIN) "$(DESTDIR)$(bindir)/$(PWM_BIN)"
266 $(INSTALL.exec) $(PWM_CLIP_BIN) "$(DESTDIR)$(bindir)/$(PWM_CLIP_BIN)"
267 for manpage in $(MANPAGES); do \
268 if [ -L $${manpage} ]; then \
269 $(INSTALL.link) $${manpage} \
270 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
271 else \
272 $(INSTALL.data) $${manpage} \
273 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
274 fi \
275 done
277 clean:
278 rm -f $(LIBCOMPAT_LIB) $(LIBPWM_LIB) $(PWM_CLIP_BIN) $(PWM_BIN) \
279 $(OBJS) $(MANPAGES)
281 clobber: clean
282 rm -f $(patsubst %.o,%.d,$(OBJS))
284 dist: clobber
285 $(PAX) -w -x ustar -s ',.*/\..*,,' -s ',./[^/]*\.tar\.gz,,' \
286 -s ',^\.$$,,' -s ',\./,$(DISTNAME)/,' . | \
287 $(GZIP) > $(DISTNAME).tar.gz
289 -include $(patsubst %.o,%.d,$(OBJS))