projects/pwm

changeset 24:eb5ce870eb16

Build compatibility functions as a library that can be reused
author Guido Berhoerster <guido+pwm@berhoerster.name>
date Wed Sep 20 23:49:31 2017 +0200 (2017-09-20)
parents 1b89066d992c
children 616385fa1fd9
files Makefile compat/compat.c
line diff
     1.1 --- a/Makefile	Sun Sep 17 18:45:05 2017 +0200
     1.2 +++ b/Makefile	Wed Sep 20 23:49:31 2017 +0200
     1.3 @@ -36,6 +36,8 @@
     1.4  #MAKEDEPEND.c =	makedepend -f- -Y -- $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) --
     1.5  LINK.c =	$(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(XCPPFLAGS) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
     1.6  LINK.o =	$(CC) $(LDFLAGS) $(XLDFLAGS) $(TARGET_ARCH)
     1.7 +AR :=		ar
     1.8 +RANLIB :=	ranlib
     1.9  CP :=		cp
    1.10  INSTALL :=	install
    1.11  INSTALL.exec :=	$(INSTALL) -D -m 0755
    1.12 @@ -139,15 +141,22 @@
    1.13    HAVE_SYS_TREE_H ?=	0
    1.14  endif
    1.15  
    1.16 -OBJS =	cmd.o \
    1.17 -	io.o \
    1.18 -	pager.o \
    1.19 -	proc.o \
    1.20 -	pw.o \
    1.21 -	pwfile.o \
    1.22 -	pwm.o \
    1.23 -	tok.o \
    1.24 -	util.o
    1.25 +LIBCOMPAT_OBJS =	compat/compat.o
    1.26 +LIBCOMPAT_LIB =		compat/libcompat.a
    1.27 +LIBCOMPAT_LIB_MEMBERS =	$(LIBCOMPAT_OBJS:%.o=$(LIBCOMPAT_LIB)(%.o))
    1.28 +
    1.29 +PWM_OBJS =		cmd.o \
    1.30 +			io.o \
    1.31 +			pager.o \
    1.32 +			proc.o \
    1.33 +			pw.o \
    1.34 +			pwfile.o \
    1.35 +			pwm.o \
    1.36 +			tok.o \
    1.37 +			util.o
    1.38 +PWM_BIN =		$(PACKAGE)
    1.39 +
    1.40 +OBJS = $(LIBCOMPAT_OBJS) $(PWM_OBJS)
    1.41  
    1.42  MANPAGES = pwm.1
    1.43  
    1.44 @@ -155,59 +164,61 @@
    1.45  
    1.46  .PHONY: all clean clobber dist install
    1.47  
    1.48 -all: $(PACKAGE) $(MANPAGES)
    1.49 +all: $(PWM_BIN) $(MANPAGES)
    1.50  
    1.51 -XCPPFLAGS =	-DPACKAGE=\"$(PACKAGE)\" \
    1.52 -		-DVERSION=\"$(VERSION)\"
    1.53 -LDLIBS =	-ltecla -lcurses -lpws -lnettle
    1.54 +$(PWM_BIN): XCPPFLAGS += -DPACKAGE=\"$(PACKAGE)\" \
    1.55 +			-DVERSION=\"$(VERSION)\"
    1.56 +$(PWM_BIN): LDLIBS =	-ltecla -lcurses -lpws -lnettle
    1.57  ifeq ($(HAVE_ASPRINTF),1)
    1.58 -  XCPPFLAGS +=	-DHAVE_ASPRINTF
    1.59 +  XCPPFLAGS +=		-DHAVE_ASPRINTF
    1.60  else
    1.61 -  OBJS +=	compat/asprintf.o
    1.62 +  LIBCOMPAT_OBJS +=	compat/asprintf.o
    1.63  endif
    1.64  ifeq ($(HAVE_ARC4RANDOM),1)
    1.65 -  XCPPFLAGS +=	-DHAVE_ARC4RANDOM
    1.66 -  OBJS +=	rand-arc4random.o
    1.67 +  XCPPFLAGS +=		-DHAVE_ARC4RANDOM
    1.68 +  PWM_OBJS +=		rand-arc4random.o
    1.69  else ifeq ($(HAVE_GETRANDOM),1)
    1.70 -  XCPPFLAGS +=	-DHAVE_GETRANDOM
    1.71 -  OBJS +=	rand-getrandom.o
    1.72 +  XCPPFLAGS +=		-DHAVE_GETRANDOM
    1.73 +  PWM_OBJS +=		rand-getrandom.o
    1.74  else
    1.75 -  OBJS +=	rand-dev-random.o
    1.76 +  PWM_OBJS +=		rand-dev-random.o
    1.77  endif
    1.78  ifeq ($(HAVE_CLOSEFROM),1)
    1.79 -  XCPPFLAGS +=	-DHAVE_CLOSEFROM
    1.80 +  XCPPFLAGS +=		-DHAVE_CLOSEFROM
    1.81  else
    1.82 -  OBJS +=	compat/closefrom.o
    1.83 +  LIBCOMPAT_OBJS +=	compat/closefrom.o
    1.84  endif
    1.85  ifeq ($(HAVE_ERR_H),1)
    1.86 -  XCPPFLAGS +=	-DHAVE_ERR_H
    1.87 +  XCPPFLAGS +=		-DHAVE_ERR_H
    1.88  else
    1.89 -  OBJS +=	compat/err.o
    1.90 +  LIBCOMPAT_OBJS +=	compat/err.o
    1.91  endif
    1.92  ifeq ($(HAVE_SETPROGNAME),1)
    1.93 -  XCPPFLAGS +=	-DHAVE_SETPROGNAME
    1.94 +  XCPPFLAGS +=		-DHAVE_SETPROGNAME
    1.95  else
    1.96 -  OBJS +=	compat/setprogname.o
    1.97 +  LIBCOMPAT_OBJS +=	compat/setprogname.o
    1.98  endif
    1.99  ifeq ($(HAVE_SYS_TREE_H),1)
   1.100 -  XCPPFLAGS +=	-DHAVE_SYS_TREE_H
   1.101 +  XCPPFLAGS +=		-DHAVE_SYS_TREE_H
   1.102  endif
   1.103  ifneq ($(findstring $(OS_NAME),FreeBSD DragonFly OpenBSD),)
   1.104 -  XCPPFLAGS +=	-I/usr/local/include
   1.105 -  XLDFLAGS +=	-L/usr/local/lib
   1.106 +  XCPPFLAGS +=		-I/usr/local/include
   1.107 +  XLDFLAGS +=		-L/usr/local/lib
   1.108  else ifeq ($(OS_NAME),NetBSD)
   1.109 -  XCPPFLAGS +=	-I/usr/pkg/include
   1.110 -  XLDFLAGS +=	-L/usr/pkg/lib
   1.111 +  XCPPFLAGS +=		-I/usr/pkg/include
   1.112 +  XLDFLAGS +=		-L/usr/pkg/lib
   1.113  endif
   1.114  ifeq ($(findstring $(OS_NAME),FreeBSD DragonFly NetBSD OpenBSD),)
   1.115 -  XCPPFLAGS +=	-D_XOPEN_SOURCE=600
   1.116 +  XCPPFLAGS +=		-D_XOPEN_SOURCE=600
   1.117  endif
   1.118  ifeq ($(OS_NAME),SunOS)
   1.119 -  XCPPFLAGS +=	-I/usr/xpg4/include -D__EXTENSIONS__
   1.120 -  XLDFLAGS +=	-L/usr/xpg4/lib -R/usr/xpg4/lib
   1.121 +  XCPPFLAGS +=		-I/usr/xpg4/include -D__EXTENSIONS__
   1.122 +  XLDFLAGS +=		-L/usr/xpg4/lib -R/usr/xpg4/lib
   1.123  endif
   1.124  
   1.125 -$(PACKAGE): $(OBJS)
   1.126 +$(LIBCOMPAT_LIB): $(LIBCOMPAT_LIB_MEMBERS)
   1.127 +
   1.128 +$(PWM_BIN): $(PWM_OBJS) $(LIBCOMPAT_LIB)
   1.129  	$(LINK.o) $^ $(LDLIBS) -o $@
   1.130  
   1.131  $(eval $(call generate-manpage-rule,$(MANPAGES)))
   1.132 @@ -216,8 +227,12 @@
   1.133  	$(MAKEDEPEND.c) $< | $(SED) -f deps.sed >$*.d
   1.134  	$(COMPILE.c) -o $@ $<
   1.135  
   1.136 +(%): %
   1.137 +	$(AR) $(ARFLAGS) $@ $<
   1.138 +	$(RANLIB) $@
   1.139 +
   1.140  install: all
   1.141 -	$(INSTALL.exec) $(PACKAGE) "$(DESTDIR)$(bindir)/$(PACKAGE)"
   1.142 +	$(INSTALL.exec) $(PWM_BIN) "$(DESTDIR)$(bindir)/$(PWM_BIN)"
   1.143  	for manpage in $(MANPAGES); do \
   1.144  	    if [ -L $${manpage} ]; then \
   1.145  	        $(INSTALL.link) $${manpage} \
   1.146 @@ -229,7 +244,7 @@
   1.147  	done
   1.148  
   1.149  clean:
   1.150 -	rm -f $(PACKAGE) $(OBJS) $(MANPAGES)
   1.151 +	rm -f $(LIBCOMPAT_LIB) $(PWM_BIN) $(OBJS) $(MANPAGES)
   1.152  
   1.153  clobber: clean
   1.154  	rm -f $(patsubst %.o,%.d,$(OBJS))
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/compat/compat.c	Wed Sep 20 23:49:31 2017 +0200
     2.3 @@ -0,0 +1,22 @@
     2.4 +/*
     2.5 + * Copyright (C) 2017 Guido Berhoerster <guido+pwm@berhoerster.name>
     2.6 + *
     2.7 + * Permission is hereby granted, free of charge, to any person obtaining
     2.8 + * a copy of this software and associated documentation files (the
     2.9 + * "Software"), to deal in the Software without restriction, including
    2.10 + * without limitation the rights to use, copy, modify, merge, publish,
    2.11 + * distribute, sublicense, and/or sell copies of the Software, and to
    2.12 + * permit persons to whom the Software is furnished to do so, subject to
    2.13 + * the following conditions:
    2.14 + *
    2.15 + * The above copyright notice and this permission notice shall be included
    2.16 + * in all copies or substantial portions of the Software.
    2.17 + *
    2.18 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    2.19 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    2.20 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    2.21 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    2.22 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    2.23 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    2.24 + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    2.25 + */