1# Copyright (c) 2008, 2009, 2011 - 2013, 2016, 2017, 2021 Peter Pentchev 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions 6# are met: 7# 1. Redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer. 9# 2. Redistributions in binary form must reproduce the above copyright 10# notice, this list of conditions and the following disclaimer in the 11# documentation and/or other materials provided with the distribution. 12# 13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23# SUCH DAMAGE. 24 25LOCALBASE?= /usr/local 26PREFIX?= ${LOCALBASE} 27BINDIR?= ${PREFIX}/bin 28MANDIR?= ${PREFIX}/man/man 29EXAMPLESDIR?= ${PREFIX}/share/examples/${PROG} 30 31STD_CPPFLAGS?= -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 32 33LFS_CPPFLAGS?= -D_FILE_OFFSET_BITS=64 34LFS_LDFLAGS?= 35 36PCRE_CPPFLAGS?= -DHAVE_PCRE -I${LOCALBASE}/include 37PCRE_LIBS?= -L${LOCALBASE}/lib -lpcre 38 39STD_CFLAGS?= -std=c99 40WARN_CFLAGS?= -Wall -W 41 42CC?= gcc 43CPPFLAGS?= 44CPPFLAGS+= ${STD_CPPFLAGS} ${LFS_CPPFLAGS} ${PCRE_CPPFLAGS} 45CFLAGS?= -g -pipe 46CFLAGS+= ${STD_CFLAGS} ${WARN_CFLAGS} 47LDFLAGS?= 48LDFLAGS+= ${LFS_LDFLAGS} 49LIBS?= 50 51RM= rm -f 52MKDIR?= mkdir -p 53SETENV?= env 54 55PROG= confget 56OBJS= confget.o confget_common.o confget_ini.o 57SRCS= confget.c confget_common.c confget_ini.c 58DEPENDFILE= .depend 59 60MAN1= confget.1 61MAN1GZ= ${MAN1}.gz 62 63BINOWN?= root 64BINGRP?= wheel 65BINMODE?= 555 66 67SHAREOWN?= ${BINOWN} 68SHAREGRP?= ${BINGRP} 69SHAREMODE?= 644 70 71INSTALL?= install 72COPY?= -c 73STRIP?= -s 74 75INSTALL_PROGRAM?= ${INSTALL} ${COPY} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} 76INSTALL_SCRIPT?= ${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} 77INSTALL_DATA?= ${INSTALL} ${COPY} -o ${SHAREOWN} -g ${SHAREGRP} -m ${SHAREMODE} 78 79# development/debugging flags, you may safely ignore them 80BDECFLAGS= -W -Wall -std=c99 -pedantic -Wbad-function-cast -Wcast-align \ 81 -Wcast-qual -Wchar-subscripts -Winline \ 82 -Wmissing-prototypes -Wnested-externs -Wpointer-arith \ 83 -Wredundant-decls -Wshadow -Wstrict-prototypes -Wwrite-strings 84#CFLAGS+= ${BDECFLAGS} 85#CFLAGS+= -ggdb -g3 86 87TESTEXEC= test-getline test-fgetln 88 89all: ${PROG} 90 [ -n '${NO_DOC_BUILD}' ] || ${MAKE} ${MAN1GZ} 91 92clean: 93 ${RM} ${PROG} ${OBJS} ${MAN1GZ} 94 ${RM} ${TESTEXEC} readaline.h 95 96${PROG}: ${OBJS} 97 ${CC} ${LDFLAGS} -o ${PROG} ${OBJS} ${PCRE_LIBS} 98 99.c.o: 100 ${CC} ${CPPFLAGS} ${CFLAGS} -c $< 101 102${MAN1GZ}: ${MAN1} 103 gzip -c9 ${MAN1} > ${MAN1GZ}.tmp 104 mv ${MAN1GZ}.tmp ${MAN1GZ} 105 106install: all install-bin 107 [ -n '${NO_DOC_BUILD}' ] || ${MAKE} install-man install-examples 108 109install-bin: 110 -${MKDIR} ${DESTDIR}${BINDIR} 111 ${INSTALL_PROGRAM} ${PROG} ${DESTDIR}${BINDIR}/ 112 113install-man: 114 -${MKDIR} ${DESTDIR}${MANDIR}1 115 ${INSTALL_DATA} ${MAN1GZ} ${DESTDIR}${MANDIR}1/ 116 117install-examples: 118 -${MKDIR} ${DESTDIR}${EXAMPLESDIR}/tests 119 ${INSTALL_SCRIPT} t/*.t ${DESTDIR}${EXAMPLESDIR}/tests/ 120 ${INSTALL_DATA} t/*.ini ${DESTDIR}${EXAMPLESDIR}/tests/ 121 122depend: 123 touch readaline.h 124 ${SETENV} CPPFLAGS="-DCONFGET_MAKEDEP ${CPPFLAGS}" \ 125 DEPENDFILE="${DEPENDFILE}" sh makedep.sh ${SRCS} 126 rm -f readaline.h 127 128test: all 129 prove t 130 131readaline.h: test-getline.c Makefile 132 rm -f readaline.h 133 if ${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -o test-getline test-getline.c ${LIBS}; then \ 134 echo '#define HAVE_GETLINE' > readaline.h; \ 135 else if ${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} -o test-fgetln test-fgetln.c ${LIBS}; then \ 136 echo '#define HAVE_FGETLN' > readaline.h; \ 137 else \ 138 echo 'Neither getline() nor fgetln() found!' 1>&2; \ 139 false; \ 140 fi; fi 141 142.PHONY: all clean depend install test 143 144ifeq ($(wildcard ${DEPENDFILE}),${DEPENDFILE}) 145include ${DEPENDFILE} 146endif 147