projects/pwm

view Makefile @ 26:5bdea77d0c1d

Add pwm-clip utility for setting the X11 CLIPBOARD selection
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Thu Sep 21 09:45:59 2017 +0200 (2017-09-21)
parents 616385fa1fd9
children 722a45b4028b
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 pager.o \
166 proc.o \
167 pw.o \
168 pwfile.o \
169 pwm.o \
170 tok.o
171 PWM_BIN = $(PACKAGE)
172 PWM_MAN1 = pwm.1
174 OBJS = $(LIBCOMPAT_OBJS) $(LIBPWM_OBJS) $(PWM_CLIP_OBJS) $(PWM_OBJS)
176 MANPAGES = $(PWM_MAN1) $(PWM_CLIP_MAN1)
178 .DEFAULT_TARGET = all
180 .PHONY: all clean clobber dist install
182 all: $(PWM_BIN) $(PWM_CLIP_BIN) $(MANPAGES)
184 $(PWM_BIN): XCPPFLAGS += -DPACKAGE=\"$(PACKAGE)\" \
185 -DVERSION=\"$(VERSION)\"
186 $(PWM_BIN): LDLIBS = -ltecla -lcurses -lpws -lnettle
187 $(PWM_CLIP_BIN): XCPPFLAGS += -Icompat/include
188 $(PWM_CLIP_BIN): LDLIBS = -lnettle
189 ifeq ($(HAVE_ASPRINTF),1)
190 XCPPFLAGS += -DHAVE_ASPRINTF
191 else
192 LIBCOMPAT_OBJS += compat/asprintf.o
193 endif
194 ifeq ($(HAVE_ARC4RANDOM),1)
195 XCPPFLAGS += -DHAVE_ARC4RANDOM
196 LIBPWM_OBJS += rand-arc4random.o
197 else ifeq ($(HAVE_GETRANDOM),1)
198 XCPPFLAGS += -DHAVE_GETRANDOM
199 LIBPWM_OBJS += rand-getrandom.o
200 else
201 LIBPWM_OBJS += rand-dev-random.o
202 endif
203 ifeq ($(HAVE_CLOSEFROM),1)
204 XCPPFLAGS += -DHAVE_CLOSEFROM
205 else
206 LIBCOMPAT_OBJS += compat/closefrom.o
207 endif
208 ifeq ($(HAVE_ERR_H),1)
209 XCPPFLAGS += -DHAVE_ERR_H
210 else
211 LIBCOMPAT_OBJS += compat/err.o
212 endif
213 ifeq ($(HAVE_GETLINE),1)
214 XCPPFLAGS += -DHAVE_GETLINE
215 else
216 LIBCOMPAT_OBJS += compat/getline.o
217 endif
218 ifeq ($(HAVE_SETPROGNAME),1)
219 XCPPFLAGS += -DHAVE_SETPROGNAME
220 else
221 LIBCOMPAT_OBJS += compat/setprogname.o
222 endif
223 ifeq ($(HAVE_SYS_TREE_H),1)
224 XCPPFLAGS += -DHAVE_SYS_TREE_H
225 endif
226 ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),)
227 XCPPFLAGS += -I/usr/local/include
228 XLDFLAGS += -L/usr/local/lib
229 else ifeq ($(OS_NAME),NetBSD)
230 XCPPFLAGS += -I/usr/pkg/include
231 XLDFLAGS += -L/usr/pkg/lib
232 endif
233 ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),)
234 XCPPFLAGS += -D_XOPEN_SOURCE=600
235 endif
236 ifeq ($(OS_NAME),SunOS)
237 XCPPFLAGS += -I/usr/xpg4/include -D__EXTENSIONS__
238 XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib
239 endif
241 $(LIBCOMPAT_LIB): $(LIBCOMPAT_LIB_MEMBERS)
243 $(LIBPWM_LIB): $(LIBPWM_LIB_MEMBERS)
245 $(PWM_CLIP_BIN): $(PWM_CLIP_OBJS) $(LIBPWM_LIB) $(LIBCOMPAT_LIB)
246 $(LINK.o) $^ $(LDLIBS) -o $@
248 $(eval $(call generate-manpage-rule,$(PWM_CLIP_MAN1)))
250 $(PWM_BIN): $(PWM_OBJS) $(LIBPWM_LIB) $(LIBCOMPAT_LIB)
251 $(LINK.o) $^ $(LDLIBS) -o $@
253 $(eval $(call generate-manpage-rule,$(PWM_MAN1)))
255 %.o: %.c
256 $(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
257 $(COMPILE.c) -o $@ $<
259 (%): %
260 $(AR) $(ARFLAGS) $@ $<
261 $(RANLIB) $@
263 install: all
264 $(INSTALL.exec) $(PWM_BIN) "$(DESTDIR)$(bindir)/$(PWM_BIN)"
265 $(INSTALL.exec) $(PWM_CLIP_BIN) "$(DESTDIR)$(bindir)/$(PWM_CLIP_BIN)"
266 for manpage in $(MANPAGES); do \
267 if [ -L $${manpage} ]; then \
268 $(INSTALL.link) $${manpage} \
269 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
270 else \
271 $(INSTALL.data) $${manpage} \
272 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
273 fi \
274 done
276 clean:
277 rm -f $(LIBCOMPAT_LIB) $(LIBPWM_LIB) $(PWM_CLIP_BIN) $(PWM_BIN) \
278 $(OBJS) $(MANPAGES)
280 clobber: clean
281 rm -f $(patsubst %.o,%.d,$(OBJS))
283 dist: clobber
284 $(PAX) -w -x ustar -s ',.*/\..*,,' -s ',./[^/]*\.tar\.gz,,' \
285 -s ',^\.$$,,' -s ',\./,$(DISTNAME)/,' . | \
286 $(GZIP) > $(DISTNAME).tar.gz
288 -include $(patsubst %.o,%.d,$(OBJS))