projects/pwm

annotate 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
rev   line source
guido+pwm@0 1 #
guido+pwm@6 2 # Copyright (C) 2017 Guido Berhoerster <guido+pwm@berhoerster.name>
guido+pwm@0 3 #
guido+pwm@0 4 # Permission is hereby granted, free of charge, to any person obtaining
guido+pwm@0 5 # a copy of this software and associated documentation files (the
guido+pwm@0 6 # "Software"), to deal in the Software without restriction, including
guido+pwm@0 7 # without limitation the rights to use, copy, modify, merge, publish,
guido+pwm@0 8 # distribute, sublicense, and/or sell copies of the Software, and to
guido+pwm@0 9 # permit persons to whom the Software is furnished to do so, subject to
guido+pwm@0 10 # the following conditions:
guido+pwm@0 11 #
guido+pwm@0 12 # The above copyright notice and this permission notice shall be included
guido+pwm@0 13 # in all copies or substantial portions of the Software.
guido+pwm@0 14 #
guido+pwm@0 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
guido+pwm@0 16 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
guido+pwm@0 17 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
guido+pwm@0 18 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
guido+pwm@0 19 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
guido+pwm@0 20 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
guido+pwm@0 21 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
guido+pwm@0 22 #
guido+pwm@0 23
guido+pwm@0 24 PACKAGE = pwm
guido+pwm@0 25 VERSION = 1
guido+pwm@0 26 DISTNAME := $(PACKAGE)-$(VERSION)
guido+pwm@0 27
guido+pwm@0 28 # gcc, clang, icc, Sun/Solaris Studio
guido+pwm@0 29 CC := $(CC) -std=c99
guido+pwm@0 30 COMPILE.c = $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(TARGET_ARCH) -c
guido+pwm@0 31 # gcc, clang, icc
guido+pwm@0 32 MAKEDEPEND.c = $(CC) -MM $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
guido+pwm@0 33 # Sun/Solaris Studio
guido+pwm@0 34 #MAKEDEPEND.c = $(CC) -xM1 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
guido+pwm@0 35 # X makedepend
guido+pwm@0 36 #MAKEDEPEND.c = makedepend -f- -Y -- $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) --
guido+pwm@0 37 LINK.c = $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
guido+pwm@0 38 LINK.o = $(CC) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
guido+pwm@24 39 AR := ar
guido+pwm@24 40 RANLIB := ranlib
guido+pwm@0 41 CP := cp
guido+pwm@0 42 INSTALL := install
guido+pwm@0 43 INSTALL.exec := $(INSTALL) -D -m 0755
guido+pwm@0 44 INSTALL.data := $(INSTALL) -D -m 0644
guido+pwm@0 45 INSTALL.link := $(CP) -f -P
guido+pwm@0 46 PAX := pax
guido+pwm@0 47 GZIP := gzip
guido+pwm@0 48 SED := sed
guido+pwm@1 49 XSLTPROC := xsltproc
guido+pwm@1 50 DOCBOOK5_MANPAGES_STYLESHEET = http://docbook.sourceforge.net/release/xsl-ns/current/manpages/docbook.xsl
guido+pwm@1 51 DOCBOOK5_MANPAGES_FLAGS = --stringparam man.authors.section.enabled 0 \
guido+pwm@1 52 --stringparam man.copyright.section.enabled 0
guido+pwm@1 53
guido+pwm@1 54 define generate-manpage-rule =
guido+pwm@1 55 $(addsuffix .%,$(basename $1)): $(addsuffix .%.xml,$(basename $(firstword $1))) docbook-update-source-data.xsl
guido+pwm@1 56 $$(XSLTPROC) \
guido+pwm@1 57 --xinclude \
guido+pwm@1 58 --stringparam package $$(PACKAGE) \
guido+pwm@1 59 --stringparam version $$(VERSION) \
guido+pwm@1 60 docbook-update-source-data.xsl $$< | \
guido+pwm@1 61 $$(XSLTPROC) \
guido+pwm@1 62 --xinclude \
guido+pwm@1 63 --output $(firstword $1) \
guido+pwm@1 64 $$(DOCBOOK5_MANPAGES_FLAGS) \
guido+pwm@1 65 $$(DOCBOOK5_MANPAGES_STYLESHEET) \
guido+pwm@1 66 -
guido+pwm@1 67 for alias in $(wordlist 2,$(words $1),$1); do \
guido+pwm@1 68 ln -sf $(notdir $(firstword $1)) $$$$alias; \
guido+pwm@1 69 done
guido+pwm@1 70 endef
guido+pwm@0 71
guido+pwm@0 72 DESTDIR ?=
guido+pwm@0 73 prefix ?= /usr/local
guido+pwm@0 74 bindir ?= $(prefix)/bin
guido+pwm@1 75 datadir ?= $(prefix)/share
guido+pwm@1 76 mandir ?= $(datadir)/man
guido+pwm@0 77
guido+pwm@0 78 OS_NAME := $(shell uname -s)
guido+pwm@0 79 OS_RELEASE := $(shell uname -r)
guido+pwm@0 80
guido+pwm@0 81 ifeq ($(OS_NAME),Linux)
guido+pwm@12 82 HAVE_ARC4RANDOM ?= 0
guido+pwm@0 83 HAVE_ASPRINTF ?= 1
guido+pwm@19 84 HAVE_CLOSEFROM ?= 0
guido+pwm@0 85 HAVE_ERR_H ?= 1
guido+pwm@26 86 HAVE_GETLINE ?= 0
guido+pwm@12 87 HAVE_GETRANDOM ?= 0
guido+pwm@17 88 HAVE_SYS_QUEUE_H ?= 0
guido+pwm@0 89 HAVE_SETPROGNAME ?= 0
guido+pwm@0 90 HAVE_SYS_TREE_H ?= 0
guido+pwm@0 91 else ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly),)
guido+pwm@12 92 HAVE_ARC4RANDOM ?= 1
guido+pwm@0 93 HAVE_ASPRINTF ?= 1
guido+pwm@19 94 HAVE_CLOSEFROM ?= 1
guido+pwm@0 95 HAVE_ERR_H ?= 1
guido+pwm@26 96 HAVE_GETLINE ?= 1
guido+pwm@12 97 HAVE_GETRANDOM ?= 0
guido+pwm@17 98 HAVE_SYS_QUEUE_H ?= 1
guido+pwm@0 99 HAVE_SETPROGNAME ?= 1
guido+pwm@0 100 HAVE_SYS_TREE_H ?= 1
guido+pwm@0 101 else ifeq ($(OS_NAME),NetBSD)
guido+pwm@12 102 HAVE_ARC4RANDOM ?= 1
guido+pwm@0 103 HAVE_ASPRINTF ?= 1
guido+pwm@19 104 HAVE_CLOSEFROM ?= 1
guido+pwm@0 105 HAVE_ERR_H ?= 1
guido+pwm@26 106 HAVE_GETLINE ?= 1
guido+pwm@12 107 HAVE_GETRANDOM ?= 0
guido+pwm@17 108 HAVE_SYS_QUEUE_H ?= 1
guido+pwm@0 109 HAVE_SYS_TREE_H ?= 1
guido+pwm@0 110 HAVE_SETPROGNAME ?= 1
guido+pwm@0 111 else ifeq ($(OS_NAME),OpenBSD)
guido+pwm@12 112 HAVE_ARC4RANDOM ?= 1
guido+pwm@0 113 HAVE_ASPRINTF ?= 1
guido+pwm@19 114 HAVE_CLOSEFROM ?= 1
guido+pwm@0 115 HAVE_ERR_H ?= 1
guido+pwm@26 116 HAVE_GETLINE ?= 1
guido+pwm@12 117 HAVE_GETRANDOM ?= 0
guido+pwm@17 118 HAVE_SYS_QUEUE_H ?= 1
guido+pwm@0 119 HAVE_SYS_TREE_H ?= 1
guido+pwm@0 120 HAVE_SETPROGNAME ?= 1
guido+pwm@0 121 else ifeq ($(OS_NAME),SunOS)
guido+pwm@0 122 ifeq ($(OS_RELEASE),5.10)
guido+pwm@12 123 HAVE_ARC4RANDOM ?= 0
guido+pwm@0 124 HAVE_ASPRINTF ?= 0
guido+pwm@0 125 HAVE_ERR_H ?= 0
guido+pwm@26 126 HAVE_GETLINE ?= 0
guido+pwm@12 127 HAVE_GETRANDOM ?= 0
guido+pwm@0 128 else
guido+pwm@12 129 HAVE_ARC4RANDOM ?= 1
guido+pwm@0 130 HAVE_ASPRINTF ?= 1
guido+pwm@0 131 HAVE_ERR_H ?= 1
guido+pwm@26 132 HAVE_GETLINE ?= 1
guido+pwm@12 133 HAVE_GETRANDOM ?= 1
guido+pwm@0 134 endif
guido+pwm@19 135 HAVE_CLOSEFROM ?= 1
guido+pwm@17 136 HAVE_SYS_QUEUE_H ?= 0
guido+pwm@0 137 HAVE_SYS_TREE_H ?= 0
guido+pwm@0 138 HAVE_SETPROGNAME ?= 0
guido+pwm@0 139 else
guido+pwm@12 140 HAVE_ARC4RANDOM ?= 0
guido+pwm@0 141 HAVE_ASPRINTF ?= 0
guido+pwm@19 142 HAVE_CLOSEFROM ?= 0
guido+pwm@0 143 HAVE_ERR_H ?= 0
guido+pwm@26 144 HAVE_GETLINE ?= 0
guido+pwm@12 145 HAVE_GETRANDOM ?= 0
guido+pwm@17 146 HAVE_SYS_QUEUE_H ?= 0
guido+pwm@0 147 HAVE_SETPROGNAME ?= 0
guido+pwm@0 148 HAVE_SYS_TREE_H ?= 0
guido+pwm@0 149 endif
guido+pwm@0 150
guido+pwm@24 151 LIBCOMPAT_OBJS = compat/compat.o
guido+pwm@24 152 LIBCOMPAT_LIB = compat/libcompat.a
guido+pwm@24 153 LIBCOMPAT_LIB_MEMBERS = $(LIBCOMPAT_OBJS:%.o=$(LIBCOMPAT_LIB)(%.o))
guido+pwm@24 154
guido+pwm@25 155 LIBPWM_OBJS = util.o
guido+pwm@25 156 LIBPWM_LIB = libpwm.a
guido+pwm@25 157 LIBPWM_LIB_MEMBERS = $(LIBPWM_OBJS:%.o=$(LIBPWM_LIB)(%.o))
guido+pwm@25 158
guido+pwm@26 159 PWM_CLIP_OBJS = pwm-clip.o
guido+pwm@26 160 PWM_CLIP_BIN = pwm-clip
guido+pwm@26 161 PWM_CLIP_MAN1 = pwm-clip.1
guido+pwm@26 162
guido+pwm@24 163 PWM_OBJS = cmd.o \
guido+pwm@24 164 io.o \
guido+pwm@24 165 pager.o \
guido+pwm@24 166 proc.o \
guido+pwm@24 167 pw.o \
guido+pwm@24 168 pwfile.o \
guido+pwm@24 169 pwm.o \
guido+pwm@25 170 tok.o
guido+pwm@24 171 PWM_BIN = $(PACKAGE)
guido+pwm@26 172 PWM_MAN1 = pwm.1
guido+pwm@24 173
guido+pwm@26 174 OBJS = $(LIBCOMPAT_OBJS) $(LIBPWM_OBJS) $(PWM_CLIP_OBJS) $(PWM_OBJS)
guido+pwm@0 175
guido+pwm@26 176 MANPAGES = $(PWM_MAN1) $(PWM_CLIP_MAN1)
guido+pwm@1 177
guido+pwm@0 178 .DEFAULT_TARGET = all
guido+pwm@0 179
guido+pwm@0 180 .PHONY: all clean clobber dist install
guido+pwm@0 181
guido+pwm@26 182 all: $(PWM_BIN) $(PWM_CLIP_BIN) $(MANPAGES)
guido+pwm@0 183
guido+pwm@24 184 $(PWM_BIN): XCPPFLAGS += -DPACKAGE=\"$(PACKAGE)\" \
guido+pwm@24 185 -DVERSION=\"$(VERSION)\"
guido+pwm@24 186 $(PWM_BIN): LDLIBS = -ltecla -lcurses -lpws -lnettle
guido+pwm@26 187 $(PWM_CLIP_BIN): XCPPFLAGS += -Icompat/include
guido+pwm@26 188 $(PWM_CLIP_BIN): LDLIBS = -lnettle
guido+pwm@8 189 ifeq ($(HAVE_ASPRINTF),1)
guido+pwm@24 190 XCPPFLAGS += -DHAVE_ASPRINTF
guido+pwm@8 191 else
guido+pwm@24 192 LIBCOMPAT_OBJS += compat/asprintf.o
guido+pwm@8 193 endif
guido+pwm@12 194 ifeq ($(HAVE_ARC4RANDOM),1)
guido+pwm@24 195 XCPPFLAGS += -DHAVE_ARC4RANDOM
guido+pwm@25 196 LIBPWM_OBJS += rand-arc4random.o
guido+pwm@12 197 else ifeq ($(HAVE_GETRANDOM),1)
guido+pwm@24 198 XCPPFLAGS += -DHAVE_GETRANDOM
guido+pwm@25 199 LIBPWM_OBJS += rand-getrandom.o
guido+pwm@12 200 else
guido+pwm@25 201 LIBPWM_OBJS += rand-dev-random.o
guido+pwm@12 202 endif
guido+pwm@19 203 ifeq ($(HAVE_CLOSEFROM),1)
guido+pwm@24 204 XCPPFLAGS += -DHAVE_CLOSEFROM
guido+pwm@19 205 else
guido+pwm@24 206 LIBCOMPAT_OBJS += compat/closefrom.o
guido+pwm@19 207 endif
guido+pwm@0 208 ifeq ($(HAVE_ERR_H),1)
guido+pwm@24 209 XCPPFLAGS += -DHAVE_ERR_H
guido+pwm@0 210 else
guido+pwm@24 211 LIBCOMPAT_OBJS += compat/err.o
guido+pwm@0 212 endif
guido+pwm@26 213 ifeq ($(HAVE_GETLINE),1)
guido+pwm@26 214 XCPPFLAGS += -DHAVE_GETLINE
guido+pwm@26 215 else
guido+pwm@26 216 LIBCOMPAT_OBJS += compat/getline.o
guido+pwm@26 217 endif
guido+pwm@0 218 ifeq ($(HAVE_SETPROGNAME),1)
guido+pwm@24 219 XCPPFLAGS += -DHAVE_SETPROGNAME
guido+pwm@0 220 else
guido+pwm@24 221 LIBCOMPAT_OBJS += compat/setprogname.o
guido+pwm@0 222 endif
guido+pwm@0 223 ifeq ($(HAVE_SYS_TREE_H),1)
guido+pwm@24 224 XCPPFLAGS += -DHAVE_SYS_TREE_H
guido+pwm@0 225 endif
guido+pwm@0 226 ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),)
guido+pwm@24 227 XCPPFLAGS += -I/usr/local/include
guido+pwm@24 228 XLDFLAGS += -L/usr/local/lib
guido+pwm@0 229 else ifeq ($(OS_NAME),NetBSD)
guido+pwm@24 230 XCPPFLAGS += -I/usr/pkg/include
guido+pwm@24 231 XLDFLAGS += -L/usr/pkg/lib
guido+pwm@0 232 endif
guido+pwm@0 233 ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),)
guido+pwm@24 234 XCPPFLAGS += -D_XOPEN_SOURCE=600
guido+pwm@0 235 endif
guido+pwm@0 236 ifeq ($(OS_NAME),SunOS)
guido+pwm@24 237 XCPPFLAGS += -I/usr/xpg4/include -D__EXTENSIONS__
guido+pwm@24 238 XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib
guido+pwm@0 239 endif
guido+pwm@0 240
guido+pwm@24 241 $(LIBCOMPAT_LIB): $(LIBCOMPAT_LIB_MEMBERS)
guido+pwm@24 242
guido+pwm@25 243 $(LIBPWM_LIB): $(LIBPWM_LIB_MEMBERS)
guido+pwm@25 244
guido+pwm@26 245 $(PWM_CLIP_BIN): $(PWM_CLIP_OBJS) $(LIBPWM_LIB) $(LIBCOMPAT_LIB)
guido+pwm@26 246 $(LINK.o) $^ $(LDLIBS) -o $@
guido+pwm@26 247
guido+pwm@26 248 $(eval $(call generate-manpage-rule,$(PWM_CLIP_MAN1)))
guido+pwm@26 249
guido+pwm@25 250 $(PWM_BIN): $(PWM_OBJS) $(LIBPWM_LIB) $(LIBCOMPAT_LIB)
guido+pwm@0 251 $(LINK.o) $^ $(LDLIBS) -o $@
guido+pwm@0 252
guido+pwm@26 253 $(eval $(call generate-manpage-rule,$(PWM_MAN1)))
guido+pwm@1 254
guido+pwm@0 255 %.o: %.c
guido+pwm@0 256 $(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
guido+pwm@0 257 $(COMPILE.c) -o $@ $<
guido+pwm@0 258
guido+pwm@24 259 (%): %
guido+pwm@24 260 $(AR) $(ARFLAGS) $@ $<
guido+pwm@24 261 $(RANLIB) $@
guido+pwm@24 262
guido+pwm@6 263 install: all
guido+pwm@24 264 $(INSTALL.exec) $(PWM_BIN) "$(DESTDIR)$(bindir)/$(PWM_BIN)"
guido+pwm@26 265 $(INSTALL.exec) $(PWM_CLIP_BIN) "$(DESTDIR)$(bindir)/$(PWM_CLIP_BIN)"
guido+pwm@1 266 for manpage in $(MANPAGES); do \
guido+pwm@1 267 if [ -L $${manpage} ]; then \
guido+pwm@1 268 $(INSTALL.link) $${manpage} \
guido+pwm@1 269 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
guido+pwm@1 270 else \
guido+pwm@1 271 $(INSTALL.data) $${manpage} \
guido+pwm@1 272 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
guido+pwm@1 273 fi \
guido+pwm@1 274 done
guido+pwm@0 275
guido+pwm@0 276 clean:
guido+pwm@26 277 rm -f $(LIBCOMPAT_LIB) $(LIBPWM_LIB) $(PWM_CLIP_BIN) $(PWM_BIN) \
guido+pwm@26 278 $(OBJS) $(MANPAGES)
guido+pwm@0 279
guido+pwm@0 280 clobber: clean
guido+pwm@0 281 rm -f $(patsubst %.o,%.d,$(OBJS))
guido+pwm@0 282
guido+pwm@0 283 dist: clobber
guido+pwm@0 284 $(PAX) -w -x ustar -s ',.*/\..*,,' -s ',./[^/]*\.tar\.gz,,' \
guido+pwm@0 285 -s ',^\.$$,,' -s ',\./,$(DISTNAME)/,' . | \
guido+pwm@0 286 $(GZIP) > $(DISTNAME).tar.gz
guido+pwm@0 287
guido+pwm@0 288 -include $(patsubst %.o,%.d,$(OBJS))