Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move headers from configure to compats.h #26

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
212 changes: 128 additions & 84 deletions Makefile.regen
Original file line number Diff line number Diff line change
@@ -1,94 +1,122 @@
.PHONY: distcheck

VERSION = 0.3.12
COMPATS = compat_err.c \
compat_b64_ntop.c \
compat_explicit_bzero.c \
compat_fts.c \
compat_getprogname.c \
compat_md5.c \
compat_memmem.c \
compat_memrchr.c \
compat_mkfifoat.c \
compat_mknodat.c \
compat_readpassphrase.c \
compat_reallocarray.c \
compat_recallocarray.c \
compat_scan_scaled.c \
compat_setresgid.c \
compat_setresuid.c \
compat_sha2.c \
compat_strlcat.c \
compat_strlcpy.c \
compat_strndup.c \
compat_strnlen.c \
compat_strtonum.c
TESTS = test-__progname.c \
test-arc4random.c \
test-b64_ntop.c \
test-capsicum.c \
test-crypt.c \
test-crypt_newhash.c \
test-endian_h.c \
test-err.c \
test-explicit_bzero.c \
test-fts.c \
test-getexecname.c \
test-getprogname.c \
test-INFTIM.c \
test-landlock.c \
test-lib_socket.c \
test-md5.c \
test-memmem.c \
test-memrchr.c \
test-memset_s.c \
test-mkfifoat.c \
test-mknodat.c \
test-osbyteorder_h.c \
test-PATH_MAX.c \
test-pledge.c \
test-program_invocation_short_name.c \
test-readpassphrase.c \
test-reallocarray.c \
test-recallocarray.c \
test-sandbox_init.c \
test-scan_scaled.c \
test-seccomp_filter.c \
test-setresgid.c \
test-setresuid.c \
test-sha2.c \
test-SOCK_NONBLOCK.c \
test-static.c \
test-strlcat.c \
test-strlcpy.c \
test-strndup.c \
test-strnlen.c \
test-strtonum.c \
test-sys_byteorder_h.c \
test-sys_endian_h.c \
test-sys_mkdev_h.c \
test-sys_queue.c \
test-sys_sysmacros_h.c \
test-sys_tree.c \
test-termios.c \
test-unveil.c \
test-WAIT_ANY.c
VERSION = 0.3.12
COMPATS = \
compat_err.c \
compat_b64_ntop.c \
compat_explicit_bzero.c \
compat_fts.c \
compat_getprogname.c \
compat_md5.c \
compat_memmem.c \
compat_memrchr.c \
compat_mkfifoat.c \
compat_mknodat.c \
compat_readpassphrase.c \
compat_reallocarray.c \
compat_recallocarray.c \
compat_scan_scaled.c \
compat_setresgid.c \
compat_setresuid.c \
compat_sha2.c \
compat_strlcat.c \
compat_strlcpy.c \
compat_strndup.c \
compat_strnlen.c \
compat_strtonum.c
COMPATS_H = \
compat_err.h \
compat_b64_ntop.h \
compat_endian.h \
compat_explicit_bzero.h \
compat_fts.h \
compat_getprogname.h \
compat_INFTIM.h \
compat_major_minor.h \
compat_md5.h \
compat_memmem.h \
compat_memrchr.h \
compat_mkfifoat.h \
compat_mknodat.h \
compat_osbyteorder.h \
compat_PATH_MAX.h \
compat_readpassphrase.h \
compat_reallocarray.h \
compat_recallocarray.h \
compat_scan_scaled.h \
compat_seccomp_filter.h \
compat_setresgid.h \
compat_setresuid.h \
compat_sha2.h \
compat_strlcat.h \
compat_strlcpy.h \
compat_strndup.h \
compat_strnlen.h \
compat_strtonum.h \
compat_sys_byteorder.h \
compat_sys_queue.h \
compat_sys_tree.h \
compat_WAIT_ANY.h
TESTS = \
test-__progname.c \
test-arc4random.c \
test-b64_ntop.c \
test-capsicum.c \
test-crypt.c \
test-crypt_newhash.c \
test-endian_h.c \
test-err.c \
test-explicit_bzero.c \
test-fts.c \
test-getexecname.c \
test-getprogname.c \
test-INFTIM.c \
test-landlock.c \
test-lib_socket.c \
test-md5.c \
test-memmem.c \
test-memrchr.c \
test-memset_s.c \
test-mkfifoat.c \
test-mknodat.c \
test-osbyteorder_h.c \
test-PATH_MAX.c \
test-pledge.c \
test-program_invocation_short_name.c \
test-readpassphrase.c \
test-reallocarray.c \
test-recallocarray.c \
test-sandbox_init.c \
test-scan_scaled.c \
test-seccomp_filter.c \
test-setresgid.c \
test-setresuid.c \
test-sha2.c \
test-SOCK_NONBLOCK.c \
test-static.c \
test-strlcat.c \
test-strlcpy.c \
test-strndup.c \
test-strnlen.c \
test-strtonum.c \
test-sys_byteorder_h.c \
test-sys_endian_h.c \
test-sys_mkdev_h.c \
test-sys_queue.c \
test-sys_sysmacros_h.c \
test-sys_tree.c \
test-termios.c \
test-unveil.c \
test-WAIT_ANY.c

all: compats.c tests.c configure
all: compats.c compats.h tests.c configure

distcheck:
grep "^## $(VERSION)$$" versions.md >/dev/null

configure: configure.in Makefile.regen configure-sys_queue.h
configure: configure.in Makefile.regen
rm -f $@
( sed -n '/^@CONFIGURE_SYS_QUEUE_H@$$/!p;//q' configure.in ; \
sed -e 's!\\$$!\\\\!g' -e 's!\$$!\\$$!g' configure-sys_queue.h ; \
sed '1,/^@CONFIGURE_SYS_QUEUE_H@$$/d' configure.in ; ) > configure.1
( sed -n '/^@CONFIGURE_SYS_TREE_H@$$/!p;//q' configure.1 ; \
sed -e 's!\\$$!\\\\!g' -e 's!\$$!\\$$!g' configure-sys_tree.h ; \
sed '1,/^@CONFIGURE_SYS_TREE_H@$$/d' configure.1 ; ) > configure.2
sed "s!@VERSION@!$(VERSION)!g" configure.2 >$@
rm -f configure.1 configure.2
sed "s!@VERSION@!$(VERSION)!g" configure.in >$@
chmod 555 $@

compats.c: $(COMPATS) Makefile.regen
Expand All @@ -102,6 +130,22 @@ compats.c: $(COMPATS) Makefile.regen
echo "#endif /* !HAVE_$${up} */" ; \
done >>$@

compats.h: $(COMPATS_H) Makefile.regen
echo -n >$@
echo "#ifndef OCONFIGURE_COMPAT_H" >>$@
echo "#define OCONFIGURE_COMPAT_H" >>$@
echo >>$@
cat compat-preamble.h >>$@
for f in $(COMPATS_H) ; \
do \
ff="`echo $$f | sed -e 's!\.h$$!!' -e 's!^compat_!!'`" ; \
up="`echo $$ff | tr '[:lower:]' '[:upper:]'`" ; \
echo "#if !HAVE_$${up}" ; \
cat "$$f" ; \
echo "#endif /* !HAVE_$${up} */" ; \
done >>$@
echo "#endif /* OCONFIGURE_COMPAT_H */" >>$@

tests.c: $(TESTS) Makefile.regen
for f in $(TESTS) ; \
do \
Expand All @@ -113,4 +157,4 @@ tests.c: $(TESTS) Makefile.regen
done >$@

clean:
rm -f configure compats.c tests.c
rm -f configure compats.c compats.h tests.c
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ To use (tl;dr edition):
1. copy
[configure](https://raw.githubusercontent.com/kristapsdz/oconfigure/master/configure),
[compats.c](https://raw.githubusercontent.com/kristapsdz/oconfigure/master/compats.c),
[compats.h](https://raw.githubusercontent.com/kristapsdz/oconfigure/master/compats.h),
and
[tests.c](https://raw.githubusercontent.com/kristapsdz/oconfigure/master/tests.c)
into your source tree
Expand Down
29 changes: 29 additions & 0 deletions compat-preamble.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifdef __cplusplus
# error "Do not use C++: this is a C application."
#endif
#if !defined(__GNUC__) || (__GNUC__ < 4)
# define __attribute__(x)
#endif
#if defined(__linux__) || defined(__MINT__) || defined(__wasi__)
# define _GNU_SOURCE /* memmem, memrchr, setresuid... */
# define _DEFAULT_SOURCE /* le32toh, crypt, ... */
#endif
#if defined(__NetBSD__)
# define _OPENBSD_SOURCE /* reallocarray, etc. */
#endif
#if defined(__sun)
# ifndef _XOPEN_SOURCE /* SunOS already defines */
# define _XOPEN_SOURCE /* XPGx */
# endif
# define _XOPEN_SOURCE_EXTENDED 1 /* XPG4v2 */
# ifndef __EXTENSIONS__ /* SunOS already defines */
# define __EXTENSIONS__ /* reallocarray, etc. */
# endif
#endif
#if !defined(__BEGIN_DECLS)
# define __BEGIN_DECLS
#endif
#if !defined(__END_DECLS)
# define __END_DECLS
#endif

1 change: 1 addition & 0 deletions compat_INFTIM.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define INFTIM (-1) /* poll.h */
1 change: 1 addition & 0 deletions compat_PATH_MAX.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define PATH_MAX 4096
2 changes: 2 additions & 0 deletions compat_WAIT_ANY.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define WAIT_ANY (-1) /* sys/wait.h */
#define WAIT_MYPGRP 0
7 changes: 7 additions & 0 deletions compat_b64_ntop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <sys/types.h> /* size_t, mode_t, dev_t */

/*
* Compatibility for b64_ntop(3).
*/
extern int b64_ntop(unsigned char const *, size_t, char *, size_t);
extern int b64_pton(char const *, unsigned char *, size_t);
16 changes: 16 additions & 0 deletions compat_endian.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Make it easier to include endian.h forms.
*/
#if HAVE_ENDIAN_H
# define COMPAT_ENDIAN_H <endian.h>
#elif HAVE_SYS_ENDIAN_H
# define COMPAT_ENDIAN_H <sys/endian.h>
#elif HAVE_OSBYTEORDER_H
# define COMPAT_ENDIAN_H <libkern/OSByteOrder.h>
#elif HAVE_SYS_BYTEORDER_H
# define COMPAT_ENDIAN_H <sys/byteorder.h>
#else
# warning No suitable endian.h could be found.
# warning Please e-mail the maintainers with your OS.
# define COMPAT_ENDIAN_H <endian.h>
#endif
17 changes: 17 additions & 0 deletions compat_err.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdarg.h>

/*
* Compatibility functions for err(3).
*/
extern void err(int, const char *, ...) __attribute__((noreturn));
extern void errc(int, int, const char *, ...) __attribute__((noreturn));
extern void errx(int, const char *, ...) __attribute__((noreturn));
extern void verr(int, const char *, va_list) __attribute__((noreturn));
extern void verrc(int, int, const char *, va_list) __attribute__((noreturn));
extern void verrx(int, const char *, va_list) __attribute__((noreturn));
extern void warn(const char *, ...);
extern void warnx(const char *, ...);
extern void warnc(int, const char *, ...);
extern void vwarn(const char *, va_list);
extern void vwarnc(int, const char *, va_list);
extern void vwarnx(const char *, va_list);
6 changes: 6 additions & 0 deletions compat_explicit_bzero.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <sys/types.h> /* size_t, mode_t, dev_t */

/*
* Compatibility for explicit_bzero(3).
*/
extern void explicit_bzero(void *, size_t);
Loading