comparison Makefile @ 24:eb5ce870eb16

Build compatibility functions as a library that can be reused
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Wed, 20 Sep 2017 23:49:31 +0200
parents 5c6155c8e9b6
children 616385fa1fd9
comparison
equal deleted inserted replaced
23:1b89066d992c 24:eb5ce870eb16
34 #MAKEDEPEND.c = $(CC) -xM1 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) 34 #MAKEDEPEND.c = $(CC) -xM1 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS)
35 # X makedepend 35 # X makedepend
36 #MAKEDEPEND.c = makedepend -f- -Y -- $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) -- 36 #MAKEDEPEND.c = makedepend -f- -Y -- $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) --
37 LINK.c = $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH) 37 LINK.c = $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
38 LINK.o = $(CC) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH) 38 LINK.o = $(CC) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
39 AR := ar
40 RANLIB := ranlib
39 CP := cp 41 CP := cp
40 INSTALL := install 42 INSTALL := install
41 INSTALL.exec := $(INSTALL) -D -m 0755 43 INSTALL.exec := $(INSTALL) -D -m 0755
42 INSTALL.data := $(INSTALL) -D -m 0644 44 INSTALL.data := $(INSTALL) -D -m 0644
43 INSTALL.link := $(CP) -f -P 45 INSTALL.link := $(CP) -f -P
137 HAVE_SYS_QUEUE_H ?= 0 139 HAVE_SYS_QUEUE_H ?= 0
138 HAVE_SETPROGNAME ?= 0 140 HAVE_SETPROGNAME ?= 0
139 HAVE_SYS_TREE_H ?= 0 141 HAVE_SYS_TREE_H ?= 0
140 endif 142 endif
141 143
142 OBJS = cmd.o \ 144 LIBCOMPAT_OBJS = compat/compat.o
143 io.o \ 145 LIBCOMPAT_LIB = compat/libcompat.a
144 pager.o \ 146 LIBCOMPAT_LIB_MEMBERS = $(LIBCOMPAT_OBJS:%.o=$(LIBCOMPAT_LIB)(%.o))
145 proc.o \ 147
146 pw.o \ 148 PWM_OBJS = cmd.o \
147 pwfile.o \ 149 io.o \
148 pwm.o \ 150 pager.o \
149 tok.o \ 151 proc.o \
150 util.o 152 pw.o \
153 pwfile.o \
154 pwm.o \
155 tok.o \
156 util.o
157 PWM_BIN = $(PACKAGE)
158
159 OBJS = $(LIBCOMPAT_OBJS) $(PWM_OBJS)
151 160
152 MANPAGES = pwm.1 161 MANPAGES = pwm.1
153 162
154 .DEFAULT_TARGET = all 163 .DEFAULT_TARGET = all
155 164
156 .PHONY: all clean clobber dist install 165 .PHONY: all clean clobber dist install
157 166
158 all: $(PACKAGE) $(MANPAGES) 167 all: $(PWM_BIN) $(MANPAGES)
159 168
160 XCPPFLAGS = -DPACKAGE=\"$(PACKAGE)\" \ 169 $(PWM_BIN): XCPPFLAGS += -DPACKAGE=\"$(PACKAGE)\" \
161 -DVERSION=\"$(VERSION)\" 170 -DVERSION=\"$(VERSION)\"
162 LDLIBS = -ltecla -lcurses -lpws -lnettle 171 $(PWM_BIN): LDLIBS = -ltecla -lcurses -lpws -lnettle
163 ifeq ($(HAVE_ASPRINTF),1) 172 ifeq ($(HAVE_ASPRINTF),1)
164 XCPPFLAGS += -DHAVE_ASPRINTF 173 XCPPFLAGS += -DHAVE_ASPRINTF
165 else 174 else
166 OBJS += compat/asprintf.o 175 LIBCOMPAT_OBJS += compat/asprintf.o
167 endif 176 endif
168 ifeq ($(HAVE_ARC4RANDOM),1) 177 ifeq ($(HAVE_ARC4RANDOM),1)
169 XCPPFLAGS += -DHAVE_ARC4RANDOM 178 XCPPFLAGS += -DHAVE_ARC4RANDOM
170 OBJS += rand-arc4random.o 179 PWM_OBJS += rand-arc4random.o
171 else ifeq ($(HAVE_GETRANDOM),1) 180 else ifeq ($(HAVE_GETRANDOM),1)
172 XCPPFLAGS += -DHAVE_GETRANDOM 181 XCPPFLAGS += -DHAVE_GETRANDOM
173 OBJS += rand-getrandom.o 182 PWM_OBJS += rand-getrandom.o
174 else 183 else
175 OBJS += rand-dev-random.o 184 PWM_OBJS += rand-dev-random.o
176 endif 185 endif
177 ifeq ($(HAVE_CLOSEFROM),1) 186 ifeq ($(HAVE_CLOSEFROM),1)
178 XCPPFLAGS += -DHAVE_CLOSEFROM 187 XCPPFLAGS += -DHAVE_CLOSEFROM
179 else 188 else
180 OBJS += compat/closefrom.o 189 LIBCOMPAT_OBJS += compat/closefrom.o
181 endif 190 endif
182 ifeq ($(HAVE_ERR_H),1) 191 ifeq ($(HAVE_ERR_H),1)
183 XCPPFLAGS += -DHAVE_ERR_H 192 XCPPFLAGS += -DHAVE_ERR_H
184 else 193 else
185 OBJS += compat/err.o 194 LIBCOMPAT_OBJS += compat/err.o
186 endif 195 endif
187 ifeq ($(HAVE_SETPROGNAME),1) 196 ifeq ($(HAVE_SETPROGNAME),1)
188 XCPPFLAGS += -DHAVE_SETPROGNAME 197 XCPPFLAGS += -DHAVE_SETPROGNAME
189 else 198 else
190 OBJS += compat/setprogname.o 199 LIBCOMPAT_OBJS += compat/setprogname.o
191 endif 200 endif
192 ifeq ($(HAVE_SYS_TREE_H),1) 201 ifeq ($(HAVE_SYS_TREE_H),1)
193 XCPPFLAGS += -DHAVE_SYS_TREE_H 202 XCPPFLAGS += -DHAVE_SYS_TREE_H
194 endif 203 endif
195 ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),) 204 ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),)
196 XCPPFLAGS += -I/usr/local/include 205 XCPPFLAGS += -I/usr/local/include
197 XLDFLAGS += -L/usr/local/lib 206 XLDFLAGS += -L/usr/local/lib
198 else ifeq ($(OS_NAME),NetBSD) 207 else ifeq ($(OS_NAME),NetBSD)
199 XCPPFLAGS += -I/usr/pkg/include 208 XCPPFLAGS += -I/usr/pkg/include
200 XLDFLAGS += -L/usr/pkg/lib 209 XLDFLAGS += -L/usr/pkg/lib
201 endif 210 endif
202 ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),) 211 ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),)
203 XCPPFLAGS += -D_XOPEN_SOURCE=600 212 XCPPFLAGS += -D_XOPEN_SOURCE=600
204 endif 213 endif
205 ifeq ($(OS_NAME),SunOS) 214 ifeq ($(OS_NAME),SunOS)
206 XCPPFLAGS += -I/usr/xpg4/include -D__EXTENSIONS__ 215 XCPPFLAGS += -I/usr/xpg4/include -D__EXTENSIONS__
207 XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib 216 XLDFLAGS += -L/usr/xpg4/lib -R/usr/xpg4/lib
208 endif 217 endif
209 218
210 $(PACKAGE): $(OBJS) 219 $(LIBCOMPAT_LIB): $(LIBCOMPAT_LIB_MEMBERS)
220
221 $(PWM_BIN): $(PWM_OBJS) $(LIBCOMPAT_LIB)
211 $(LINK.o) $^ $(LDLIBS) -o $@ 222 $(LINK.o) $^ $(LDLIBS) -o $@
212 223
213 $(eval $(call generate-manpage-rule,$(MANPAGES))) 224 $(eval $(call generate-manpage-rule,$(MANPAGES)))
214 225
215 %.o: %.c 226 %.o: %.c
216 $(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d 227 $(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
217 $(COMPILE.c) -o $@ $< 228 $(COMPILE.c) -o $@ $<
218 229
230 (%): %
231 $(AR) $(ARFLAGS) $@ $<
232 $(RANLIB) $@
233
219 install: all 234 install: all
220 $(INSTALL.exec) $(PACKAGE) "$(DESTDIR)$(bindir)/$(PACKAGE)" 235 $(INSTALL.exec) $(PWM_BIN) "$(DESTDIR)$(bindir)/$(PWM_BIN)"
221 for manpage in $(MANPAGES); do \ 236 for manpage in $(MANPAGES); do \
222 if [ -L $${manpage} ]; then \ 237 if [ -L $${manpage} ]; then \
223 $(INSTALL.link) $${manpage} \ 238 $(INSTALL.link) $${manpage} \
224 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \ 239 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
225 else \ 240 else \
227 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \ 242 "$(DESTDIR)$(mandir)/man$${manpage##*.}/$${manpage##*/}"; \
228 fi \ 243 fi \
229 done 244 done
230 245
231 clean: 246 clean:
232 rm -f $(PACKAGE) $(OBJS) $(MANPAGES) 247 rm -f $(LIBCOMPAT_LIB) $(PWM_BIN) $(OBJS) $(MANPAGES)
233 248
234 clobber: clean 249 clobber: clean
235 rm -f $(patsubst %.o,%.d,$(OBJS)) 250 rm -f $(patsubst %.o,%.d,$(OBJS))
236 251
237 dist: clobber 252 dist: clobber