projects/pwm

view Makefile @ 43:969de79bb4b6

Added tag version-1 for changeset fb995e5d54e9
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Tue Aug 20 21:27:47 2019 +0200 (14 months ago)
parents 34ada71ff3e5
children
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 TESTS_OUTPUT_PATH = ./tests/output
56 define generate-manpage-rule =
57 $(addsuffix .%,$(basename $1)): $(addsuffix .%.xml,$(basename $(firstword $1))) docbook-update-source-data.xsl
58 $$(XSLTPROC) \
59 --xinclude \
60 --stringparam package $$(PACKAGE) \
61 --stringparam version $$(VERSION) \
62 docbook-update-source-data.xsl $$< | \
63 $$(XSLTPROC) \
64 --xinclude \
65 --output $(firstword $1) \
66 $$(DOCBOOK5_MANPAGES_FLAGS) \
67 $$(DOCBOOK5_MANPAGES_STYLESHEET) \
68 -
69 for alias in $(wordlist 2,$(words $1),$1); do \
70 ln -sf $(notdir $(firstword $1)) $$$$alias; \
71 done
72 endef
74 DESTDIR ?=
75 prefix ?= /usr/local
76 bindir ?= $(prefix)/bin
77 datadir ?= $(prefix)/share
78 mandir ?= $(datadir)/man
80 OS_NAME := $(shell uname -s)
81 OS_RELEASE := $(shell uname -r)
83 ifeq ($(OS_NAME),Linux)
84 HAVE_ARC4RANDOM ?= 0
85 HAVE_ASPRINTF ?= 1
86 HAVE_CLOSEFROM ?= 0
87 HAVE_ERR_H ?= 1
88 HAVE_GETLINE ?= 0
89 HAVE_GETRANDOM ?= 0
90 HAVE_SYS_QUEUE_H ?= 0
91 HAVE_SETPROGNAME ?= 0
92 HAVE_SYS_TREE_H ?= 0
93 else ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly),)
94 HAVE_ARC4RANDOM ?= 1
95 HAVE_ASPRINTF ?= 1
96 HAVE_CLOSEFROM ?= 1
97 HAVE_ERR_H ?= 1
98 HAVE_GETLINE ?= 1
99 HAVE_GETRANDOM ?= 0
100 HAVE_SYS_QUEUE_H ?= 1
101 HAVE_SETPROGNAME ?= 1
102 HAVE_SYS_TREE_H ?= 1
103 else ifeq ($(OS_NAME),NetBSD)
104 HAVE_ARC4RANDOM ?= 1
105 HAVE_ASPRINTF ?= 1
106 HAVE_CLOSEFROM ?= 1
107 HAVE_ERR_H ?= 1
108 HAVE_GETLINE ?= 1
109 HAVE_GETRANDOM ?= 0
110 HAVE_SYS_QUEUE_H ?= 1
111 HAVE_SYS_TREE_H ?= 1
112 HAVE_SETPROGNAME ?= 1
113 else ifeq ($(OS_NAME),OpenBSD)
114 HAVE_ARC4RANDOM ?= 1
115 HAVE_ASPRINTF ?= 1
116 HAVE_CLOSEFROM ?= 1
117 HAVE_ERR_H ?= 1
118 HAVE_GETLINE ?= 1
119 HAVE_GETRANDOM ?= 0
120 HAVE_SYS_QUEUE_H ?= 1
121 HAVE_SYS_TREE_H ?= 1
122 HAVE_SETPROGNAME ?= 1
123 else ifeq ($(OS_NAME),SunOS)
124 ifeq ($(OS_RELEASE),5.10)
125 HAVE_ARC4RANDOM ?= 0
126 HAVE_ASPRINTF ?= 0
127 HAVE_ERR_H ?= 0
128 HAVE_GETLINE ?= 0
129 HAVE_GETRANDOM ?= 0
130 else
131 HAVE_ARC4RANDOM ?= 1
132 HAVE_ASPRINTF ?= 1
133 HAVE_ERR_H ?= 1
134 HAVE_GETLINE ?= 1
135 HAVE_GETRANDOM ?= 1
136 endif
137 HAVE_CLOSEFROM ?= 1
138 HAVE_SYS_QUEUE_H ?= 0
139 HAVE_SYS_TREE_H ?= 0
140 HAVE_SETPROGNAME ?= 0
141 else
142 HAVE_ARC4RANDOM ?= 0
143 HAVE_ASPRINTF ?= 0
144 HAVE_CLOSEFROM ?= 0
145 HAVE_ERR_H ?= 0
146 HAVE_GETLINE ?= 0
147 HAVE_GETRANDOM ?= 0
148 HAVE_SYS_QUEUE_H ?= 0
149 HAVE_SETPROGNAME ?= 0
150 HAVE_SYS_TREE_H ?= 0
151 endif
153 LIBCOMPAT_OBJS = compat/compat.o
154 LIBCOMPAT_LIB = compat/libcompat.a
155 LIBCOMPAT_LIB_MEMBERS = $(LIBCOMPAT_OBJS:%.o=$(LIBCOMPAT_LIB)(%.o))
157 LIBPWM_OBJS = util.o
158 LIBPWM_LIB = libpwm.a
159 LIBPWM_LIB_MEMBERS = $(LIBPWM_OBJS:%.o=$(LIBPWM_LIB)(%.o))
161 PWM_CLIP_OBJS = pwm-clip.o
162 PWM_CLIP_BIN = pwm-clip
163 PWM_CLIP_MAN1 = pwm-clip.1
165 PWM_OBJS = cmd.o \
166 io.o \
167 macro.o \
168 pager.o \
169 proc.o \
170 pw.o \
171 pwfile.o \
172 pwm.o \
173 pwmrc.o \
174 tok.o
175 PWM_BIN = $(PACKAGE)
176 PWM_MAN1 = pwm.1
178 OBJS = $(LIBCOMPAT_OBJS) $(LIBPWM_OBJS) $(PWM_CLIP_OBJS) $(PWM_OBJS)
180 MANPAGES = $(PWM_MAN1) $(PWM_CLIP_MAN1)
182 .DEFAULT_TARGET = all
184 .PHONY: all check clean clobber dist install
186 all: $(PWM_BIN) $(PWM_CLIP_BIN) $(MANPAGES)
188 $(PWM_BIN): XCPPFLAGS += -DPACKAGE=\"$(PACKAGE)\" \
189 -DVERSION=\"$(VERSION)\"
190 $(PWM_BIN): LDLIBS = -ltecla -lcurses -lpws -lnettle
191 $(PWM_CLIP_BIN): XCPPFLAGS += -Icompat/include
192 $(PWM_CLIP_BIN): LDLIBS = -lnettle
193 ifeq ($(HAVE_ASPRINTF),1)
194 XCPPFLAGS += -DHAVE_ASPRINTF
195 else
196 LIBCOMPAT_OBJS += compat/asprintf.o
197 endif
198 ifeq ($(HAVE_ARC4RANDOM),1)
199 XCPPFLAGS += -DHAVE_ARC4RANDOM
200 LIBPWM_OBJS += rand-arc4random.o
201 else ifeq ($(HAVE_GETRANDOM),1)
202 XCPPFLAGS += -DHAVE_GETRANDOM
203 LIBPWM_OBJS += rand-getrandom.o
204 else
205 LIBPWM_OBJS += rand-dev-random.o
206 endif
207 ifeq ($(HAVE_CLOSEFROM),1)
208 XCPPFLAGS += -DHAVE_CLOSEFROM
209 else
210 LIBCOMPAT_OBJS += compat/closefrom.o
211 endif
212 ifeq ($(HAVE_ERR_H),1)
213 XCPPFLAGS += -DHAVE_ERR_H
214 else
215 LIBCOMPAT_OBJS += compat/err.o
216 endif
217 ifeq ($(HAVE_GETLINE),1)
218 XCPPFLAGS += -DHAVE_GETLINE
219 else
220 LIBCOMPAT_OBJS += compat/getline.o
221 endif
222 ifeq ($(HAVE_SETPROGNAME),1)
223 XCPPFLAGS += -DHAVE_SETPROGNAME
224 else
225 LIBCOMPAT_OBJS += compat/setprogname.o
226 endif
227 ifeq ($(HAVE_SYS_TREE_H),1)
228 XCPPFLAGS += -DHAVE_SYS_TREE_H
229 endif
230 ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),)
231 XCPPFLAGS += -I/usr/local/include
232 XLDFLAGS += -L/usr/local/lib
233 else ifeq ($(OS_NAME),NetBSD)
234 XCPPFLAGS += -I/usr/pkg/include
235 XLDFLAGS += -L/usr/pkg/lib
236 endif
237 ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),)
238 XCPPFLAGS += -D_XOPEN_SOURCE=600
239 endif
240 ifeq ($(OS_NAME),SunOS)
241 XCPPFLAGS += -I/usr/xpg4/include -D__EXTENSIONS__
242 XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib
243 endif
245 $(LIBCOMPAT_LIB): $(LIBCOMPAT_LIB_MEMBERS)
247 $(LIBPWM_LIB): $(LIBPWM_LIB_MEMBERS)
249 $(PWM_CLIP_BIN): $(PWM_CLIP_OBJS) $(LIBPWM_LIB) $(LIBCOMPAT_LIB)
250 $(LINK.o) $^ $(LDLIBS) -o $@
252 $(eval $(call generate-manpage-rule,$(PWM_CLIP_MAN1)))
254 $(PWM_BIN): $(PWM_OBJS) $(LIBPWM_LIB) $(LIBCOMPAT_LIB)
255 $(LINK.o) $^ $(LDLIBS) -o $@
257 $(eval $(call generate-manpage-rule,$(PWM_MAN1)))
259 %.o: %.c
260 $(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
261 $(COMPILE.c) -o $@ $<
263 (%): %
264 $(AR) $(ARFLAGS) $@ $<
265 $(RANLIB) $@
267 install: all
268 $(INSTALL.exec) $(PWM_BIN) "$(DESTDIR)$(bindir)/$(PWM_BIN)"
269 $(INSTALL.exec) $(PWM_CLIP_BIN) "$(DESTDIR)$(bindir)/$(PWM_CLIP_BIN)"
270 for manpage in $(MANPAGES); do \
271 if [ -L $${manpage} ]; then \
272 $(INSTALL.link) $${manpage} \
273 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
274 else \
275 $(INSTALL.data) $${manpage} \
276 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
277 fi \
278 done
280 check: $(PWM_BIN)
281 rm -rf $(TESTS_OUTPUT_PATH); \
282 SHELL=$(SHELL) PWM=./$(PWM_BIN) \
283 TESTS_OUTPUT_PATH=$(TESTS_OUTPUT_PATH) $(SHELL) tests/run-tests.sh
285 clean:
286 rm -f $(LIBCOMPAT_LIB) $(LIBPWM_LIB) $(PWM_CLIP_BIN) $(PWM_BIN) \
287 $(OBJS) $(MANPAGES)
289 clobber: clean
290 rm -f $(patsubst %.o,%.d,$(OBJS))
292 dist: clobber
293 $(PAX) -w -x ustar -s ',.*/\..*,,' -s ',./[^/]*\.tar\.gz,,' \
294 -s ',^\.$$,,' -s ',\./,$(DISTNAME)/,' . | \
295 $(GZIP) > $(DISTNAME).tar.gz
297 -include local.mk
299 -include $(patsubst %.o,%.d,$(OBJS))