refactor the makefile / configure

steal more (good) stuff from mandoc-portable :)
This commit is contained in:
Omar Polo 2022-07-04 13:44:38 +00:00
parent 225686d7fd
commit 96e3c01314
4 changed files with 216 additions and 63 deletions

173
Makefile
View File

@ -1,13 +1,140 @@
# Copyright (c) 2022 Omar Polo <op@omarpolo.com>
# Copyright (c) 2011, 2013-2022 Ingo Schwarze <schwarze@openbsd.org>
# Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# tests to run as a port of the regression suite. Leave empty to run
# all.
TESTS=
.PHONY: all static clean cleanall test regress install
TESTSRCS = have/err.c \
have/explicit_bzero.c \
have/freezero.c \
have/getdtablecount.c \
have/getdtablesize.c \
have/getprogname.c \
have/imsg.c \
have/landlock.c \
have/libevent.c \
have/libevent2.c \
have/libtls.c \
have/noop.c \
have/noop.d \
have/openssl.c \
have/pr_set_name.c \
have/program_invocation_short_name.c \
have/queue_h.c \
have/reallocarray.c \
have/recallocarray.c \
have/setproctitle.c \
have/strlcat.c \
have/strlcpy.c \
have/strtonum.c \
have/tree_h.c \
have/vasprintf.c
COMPATS = compat/err.c \
compat/explicit_bzero.c \
compat/freezero.c \
compat/getdtablecount.c \
compat/getdtablesize.c \
compat/getprogname.c \
compat/imsg-buffer.c \
compat/imsg.c \
compat/imsg.h \
compat/queue.h \
compat/reallocarray.c \
compat/recallocarray.c \
compat/setproctitle.c \
compat/strlcat.c \
compat/strlcpy.c \
compat/strtonum.c \
compat/tree.h \
compat/vasprintf.c
GMID_SRCS = dirs.c \
ex.c \
fcgi.c \
gmid.c \
iri.c \
log.c \
mime.c \
proxy.c \
puny.c \
sandbox.c \
server.c \
utf8.c \
utils.c \
y.tab.c \
GMID_OBJS = ${GMID_SRCS:.c=.o} ${COBJS}
GG_SRCS = gg.c \
iri.c \
utf8.c
GG_OBJS = ${GG_SRCS:.c=.o} ${COBJS}
SRCS = gmid.h \
landlock_shim.h \
parse.y \
${GMID_SRCS} \
${GG_SRCS}
REGRESSFILES = regress/Makefile \
regress/env \
regress/err \
regress/example.mime.types \
regress/fcgi-test.c \
regress/fill-file.c \
regress/hello \
regress/invalid \
regress/iri_test.c \
regress/lib.sh \
regress/max-length-reply \
regress/puny-test.c \
regress/regress \
regress/serve-bigfile \
regress/sha \
regress/slow \
regress/tests.sh \
regress/valid.ext
EXTRAS = ChangeLog \
LICENSE \
Makefile \
Makefile.depend \
README.md \
configure \
configure.local.example \
gmid.1 \
gmid.conf.5
DISTFILES = ${EXTRAS} \
${COMPATS} \
${REGRESSFILES} \
${SRCS} \
${TESTSRCS}
DISTNAME = gmid-${VERSION}
all: Makefile.local gmid gg
.PHONY: all static clean cleanall test regress install
Makefile.local: configure
./configure
Makefile.local config.h: configure ${TESTSRCS}
@echo "$@ is out of date; please run ./configure"
@exit 1
include Makefile.local
@ -27,10 +154,11 @@ static: ${GMID_OBJS} ${GG_OBJS}
clean:
rm -f *.o compat/*.o y.tab.c y.tab.h y.output gmid gg
rm -f compile_flags.txt
cleanall: clean
${MAKE} -C regress clean
distclean: clean
rm -f Makefile.local config.h config.h.old config.log config.log.old
test: regress
regress: all
${MAKE} 'TESTS=${TESTS}' -C regress all
@ -45,10 +173,41 @@ install: gmid gg
${INSTALL_MAN} gmid.conf.5 ${DESTDIR}${MANDIR}/man5
${INSTALL_MAN} gg.1 ${DESTDIR}${MANDIR}/man1
compile_flags.txt:
printf "%s\n" ${CFLAGS} > compile_flags.txt
uninstall:
rm ${DESTDIR}${BINDIR}/gg
rm ${DESTDIR}${BINDIR}/gmid
rm ${DESTDIR}${MANDIR}/man1/gg.1
rm ${DESTDIR}${MANDIR}/man1/gmid.1
rm ${DESTDIR}${MANDIR}/man5/gmid.conf.5
# make sure we pass -o to ${CC}. OpenBSD default suffix rule doesn't
.SUFFIXES: .c .o
.c.o:
${CC} ${CFLAGS} -c $< -o $@
depend: config.h y.tab.c
mkdep -f Makefile.tmp1 ${CFLAGS} ${GMID_SRCS} ${GG_SRCS} ${COBJSx:.o=.c}
perl -e 'undef $$/; $$_ = <>; s|/usr/include/\S+||g; \
s|\\\n||g; s| +| |g; s| $$||mg; print;' \
Makefile.tmp1 > Makefile.tmp2
rm Makefile.tmp1
mv Makefile.tmp2 Makefile.depend
dist: ${DISTNAME}.sha256
${DISTNAME}.sha256: ${DISTNAME}.tar.gz
${DISTNAME}.tar.gz: ${DISTFILES}
mkdir -p .dist/${DISTNAME}/
${INSTALL} -m 0644 ${SRCS} ${EXTRAS} .dist/${DISTNAME}
cd .dist/${DISTNAME} && chmod 755 configure
mkdir -p .dist/${DISTNAME}/compat
${INSTALL} -m 0644 ${COMPATS} .dist/${DISTNAME}/compat
mkdir -p .dist/${DISTNAME}/have
${INSTALL} -m 0644 ${TESTSRCS} .dist/${DISTNAME}/have
mkdir -p .dist/${DISTNAME}/regress
${INSTALL} -m 0644 ${REGRESSFILES} .dist/${DISTNAME}/regress
cd .dist/${DISTNAME}/regress && chmod 755 env err hello invalid \
max-length-reply regress sha slow
cd .dist/ && tar zcf ../$@ ${DISTNAME}
rm -rf .dist/

17
Makefile.depend Normal file
View File

@ -0,0 +1,17 @@
dirs.o: dirs.c gmid.h config.h
ex.o: ex.c gmid.h config.h
fcgi.o: fcgi.c gmid.h config.h
gmid.o: gmid.c gmid.h config.h
iri.o: iri.c gmid.h config.h
log.o: log.c gmid.h config.h
mime.o: mime.c gmid.h config.h
proxy.o: proxy.c gmid.h config.h
puny.o: puny.c gmid.h config.h
sandbox.o: sandbox.c gmid.h config.h
server.o: server.c gmid.h config.h
utf8.o: utf8.c gmid.h config.h
utils.o: utils.c gmid.h config.h
y.tab.o: y.tab.c gmid.h config.h
gg.o: gg.c gmid.h config.h
iri.o: iri.c gmid.h config.h
utf8.o: utf8.c gmid.h config.h

87
configure vendored
View File

@ -53,6 +53,8 @@ LD_IMSG=
STATIC=
YACC=yacc
COBJS=
DISABLE_SANDBOX=0
NEED_GNU_SOURCE=0
@ -141,6 +143,20 @@ for keyvals in "$@"; do
esac
done
# --------
# Allow configure.local to override all variables, default settings,
# command-line arguments, and tested features, above.
if [ -r ./configure.local ]; then
echo "configure.local: reading..." 1>&2
echo "configure.local: reading..." 1>&3
cat ./configure.local 1>&3
. ./configure.local
else
echo "configure.local: no (fully automatic configuration)" 1>&2
echo "configure.local: no (fully automatic configuration)" 1>&3
fi
# --------
# tests functions
@ -220,12 +236,6 @@ else
echo 1>&3
fi
if runtest noop MMD -MMD; then
CFLAGS="${CFLAGS} -MMD"
echo "adding -MMD to CFLAGS" 1>&2
echo "adding -MMD to CFLAGS" 1>&3
fi
# --------
# tests for config.h
@ -352,60 +362,60 @@ if [ ${HAVE_ERR} -eq 0 ]; then
echo "extern void errx(int, const char*, ...);"
echo "extern void warn(const char*, ...);"
echo "extern void warnx(const char*, ...);"
COMPAT="${COMPAT} compat/err.o"
COBJS="${COBJS} compat/err.o"
else
echo "#include <err.h>"
fi
if [ ${HAVE_EXPLICIT_BZERO} -eq 0 ]; then
echo "extern void explicit_bzero(void*, size_t);"
COMPAT="${COMPAT} compat/explicit_bzero.o"
COBJS="${COBJS} compat/explicit_bzero.o"
fi
if [ ${HAVE_FREEZERO} -eq 0 ]; then
echo "extern void freezero(void*, size_t);"
COMPAT="${COMPAT} compat/freezero.o"
COBJS="${COBJS} compat/freezero.o"
fi
if [ ${HAVE_GETDTABLECOUNT} -eq 0 ]; then
echo "extern int getdtablecount(void);"
COMPAT="${COMPAT} compat/getdtablecount.o"
COBJS="${COBJS} compat/getdtablecount.o"
fi
if [ ${HAVE_GETDTABLESIZE} -eq 0 ]; then
echo "extern int getdtablesize(void);"
COMPAT="${COMPAT} compat/getdtablesize.o"
COBJS="${COBJS} compat/getdtablesize.o"
fi
if [ ${HAVE_GETPROGNAME} -eq 0 ]; then
echo "extern const char *getprogname(void);"
COMPAT="${COMPAT} compat/getprogname.o"
COBJS="${COBJS} compat/getprogname.o"
fi
if [ ${HAVE_IMSG} -eq 0 ]; then
COMPAT="${COMPAT} compat/imsg.o compat/imsg-buffer.o"
COBJS="${COBJS} compat/imsg.o compat/imsg-buffer.o"
fi
if [ ${HAVE_REALLOCARRAY} -eq 0 ]; then
echo "extern void *reallocarray(void*, size_t, size_t);"
COMPAT="${COMPAT} compat/reallocarray.o"
COBJS="${COBJS} compat/reallocarray.o"
fi
if [ ${HAVE_RECALLOCARRAY} -eq 0 ]; then
echo "extern void *recallocarray(void*, size_t, size_t, size_t);"
COMPAT="${COMPAT} compat/recallocarray.o"
COBJS="${COBJS} compat/recallocarray.o"
fi
if [ ${HAVE_SETPROCTITLE} -eq 0 ]; then
echo "extern void setproctitle(const char *fmt, ...);"
COMPAT="${COMPAT} compat/setproctitle.o"
COBJS="${COBJS} compat/setproctitle.o"
fi
if [ ${HAVE_STRLCAT} -eq 0 ]; then
echo "extern size_t strlcat(char*, const char*, size_t);"
COMPAT="${COMPAT} compat/strlcat.o"
COBJS="${COBJS} compat/strlcat.o"
fi
if [ ${HAVE_STRLCPY} -eq 0 ]; then
echo "extern size_t strlcpy(char*, const char*, size_t);"
COMPAT="${COMPAT} compat/strlcpy.o"
COBJS="${COBJS} compat/strlcpy.o"
fi
if [ ${HAVE_STRTONUM} -eq 0 ]; then
echo "extern long long strtonum(const char*, long long, long long, const char**);"
COMPAT="${COMPAT} compat/strtonum.o"
COBJS="${COBJS} compat/strtonum.o"
fi
if [ ${HAVE_VASPRINTF} -eq 0 ]; then
echo "extern int vasprintf(char**, const char*, va_list);"
COMPAT="${COMPAT} compat/vasprintf.o"
COBJS="${COBJS} compat/vasprintf.o"
fi
echo "file config.h: written" 1>&2
echo "file config.h: written" 1>&3
@ -413,25 +423,6 @@ echo "file config.h: written" 1>&3
# --------
# tests for Makefile.local
GMID_SRCS="dirs.c ex.c fcgi.c gmid.c iri.c log.c mime.c proxy.c puny.c"
GMID_SRCS="${GMID_SRCS} sandbox.c server.c utf8.c utils.c y.tab.c"
GMID_OBJS=
for src in ${GMID_SRCS}; do
GMID_OBJS="${GMID_OBJS} ${src%.c}.o"
done
GMID_OBJS="${GMID_OBJS} ${COMPAT}"
GG_SRCS="gg.c iri.c utf8.c"
GG_OBJS=
for src in ${GG_SRCS}; do
GG_OBJS="${GG_OBJS} ${src%.c}.o"
done
GG_OBJS="${GG_OBJS} ${COMPAT}"
ALL_SRCS="${GMID_SRCS} gg.c"
exec > Makefile.local
[ -z "${BINDIR}" ] && BINDIR="${PREFIX}/bin"
@ -458,28 +449,12 @@ INSTALL_LIB = ${INSTALL_LIB}
INSTALL_MAN = ${INSTALL_MAN}
INSTALL_DATA = ${INSTALL_DATA}
GMID_OBJS = ${GMID_OBJS}
GG_OBJS = ${GG_OBJS}
COBJS = ${COBJS}
VERSION = ${VERSION}
__HEREDOC__
printf "COMPAT ="
for comp in ${COMPAT}; do
printf " %s/%s" "$PWD" "$comp"
done
printf "\n\n"
# Include dependency info
for src in ${ALL_SRCS}; do
printf "%s\n" "-include ${src%.c}.d"
done
for comp in ${COMPAT}; do
printf "%s\n" "-include ${comp%.o}.d"
done
echo "file Makefile.local: written" 1>&2
echo "file Makefile.local: written" 1>&3

View File

@ -4,6 +4,8 @@ TESTS=
include ../Makefile.local
COMPAT= ${COBJS:%=../%}
.PHONY: all data clean regress
all: data puny-test iri_test fcgi-test