configuration script for BSD.lv projects
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE.md Add README and LICENSE file. Jun 30, 2017
Makefile Bump version. Jun 21, 2018
README.md Fix header documentation. Jun 21, 2018
compat_err.c Adding vwarn and vwarnx to err.h compatibility. Apr 3, 2018
compat_explicit_bzero.c Strip CVS tags out of compat files. Oct 14, 2017
compat_getprogname.c Add more tests/compat: getprogname (with several variants) and memrchr. Oct 12, 2017
compat_md5.c Strip CVS tags out of compat files. Oct 14, 2017
compat_memmem.c memmem(3) test and compat. Oct 14, 2017
compat_memrchr.c Strip CVS tags out of compat files. Oct 14, 2017
compat_reallocarray.c Strip CVS tags out of compat files. Oct 14, 2017
compat_recallocarray.c Strip CVS tags out of compat files. Oct 14, 2017
compat_strlcat.c Strip CVS tags out of compat files. Oct 14, 2017
compat_strlcpy.c Strip CVS tags out of compat files. Oct 14, 2017
compat_strndup.c Test for strndup. Requested by Jan Stary. Feb 23, 2018
compat_strnlen.c Add strnlen test. Feb 26, 2018
compat_strtonum.c Strip CVS tags out of compat files. Oct 14, 2017
compats.c Adding vwarn and vwarnx to err.h compatibility. Apr 3, 2018
configure Bump version. Jun 21, 2018
configure.in We don't actually need to run the tests: there are no facilities that… Jun 21, 2018
test-INFTIM.c Add INFTIM and arc4andom feature test. Oct 15, 2017
test-PATH_MAX.c No commit message Feb 26, 2017
test-SOCK_NONBLOCK.c Add test. Oct 15, 2017
test-__progname.c Add more tests/compat: getprogname (with several variants) and memrchr. Oct 12, 2017
test-arc4random.c Add INFTIM and arc4andom feature test. Oct 15, 2017
test-b64_ntop.c Fix warning about sign. Jun 21, 2018
test-capsicum.c Merge #1 --- thanks! Nov 1, 2017
test-err.c Remove embedded Ids. Oct 12, 2017
test-explicit_bzero.c Add recallocarray and md5. Oct 11, 2017
test-getprogname.c Add more tests/compat: getprogname (with several variants) and memrchr. Oct 12, 2017
test-md5.c Add recallocarray and md5. Oct 11, 2017
test-memmem.c Use _GNU_SOURCE for memmem. Oct 15, 2017
test-memrchr.c Add more tests/compat: getprogname (with several variants) and memrchr. Oct 12, 2017
test-memset_s.c Add recallocarray and md5. Oct 11, 2017
test-pledge.c No commit message Feb 26, 2017
test-program_invocation_short_name.c Fix program_invocation_short_name for linux. Oct 12, 2017
test-reallocarray.c No commit message Feb 26, 2017
test-recallocarray.c Add [incomplete] test for recallocarray. Oct 9, 2017
test-sandbox_init.c No commit message Feb 26, 2017
test-seccomp_filter.c Don't use a dash in seccomp filter. Oct 15, 2017
test-strlcat.c No commit message Feb 26, 2017
test-strlcpy.c No commit message Feb 26, 2017
test-strndup.c Test for strndup. Requested by Jan Stary. Feb 23, 2018
test-strnlen.c Add strnlen test. Feb 26, 2018
test-strtonum.c Remove embedded Ids. Oct 12, 2017
test-systrace.c Add systrace test. Oct 14, 2017
test-zlib.c Add zlib test. Oct 18, 2017
tests.c Migrate to built. Jun 21, 2018
versions.md Get version set up. Jun 21, 2018

README.md

This is a simple configuration script use for some BSD.lv project sources. Its mission is to provide OpenBSD portability functions and feature testing.

See versions.md for version information.

To use:

  1. copy configure, compats.c, and tests.c into your source tree
  2. have include Makefile.configure at the top of your Makefile
  3. have #include "config.h" as the first inclusion in your sources
  4. compile compile.o and link to it

Once prepared, a user just runs ./configure prior to running make. The configure script will check for common features as noted in the test files, e.g., pledge(2), and also provide compatibility for other functions, e.g., strlcpy(3).

The ./configure script may be executed in a cross-compiling environment with the compiler and linker set appropriately.

If you have Makefile flags you'd like to set, set them when you invoke configure as key-value pairs on the command-line, e.g.,

./configure PREFIX=/opt

The following flags are recognised and accepted: LDADD, LDFLAGS, CPPFLAGS, DESTDIR, PREFIX, MANDIR, LIBDIR, BINDIR, SHAREDIR, SBINDIR, and INCLUDEDIR. Un-recognised flags are discarded and warned about.

Using oconfigure requires some work within your sources to node compatibility areas, then some in your build environment:

#include "config.h" /* required inclusion */

#if HAVE_ERR /* sometimes err.h exists, sometimes not */
# include <err.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void) {
#if HAVE_PLEDGE /* do we have pledge? */
	if (-1 == pledge("stdio", NULL))
		err(EXIT_FAILURE, NULL);
#endif
	warnx("hello, world!"); /* compat provides this */
	return(EXIT_SUCCESS);
}

And then...

./configure
cc -o config.o -c config.c
cc -o main.o -c main.c
cc config.o main.o

Though you can just build this into your Makefile.

This framework was inspired by mandoc's configure script written by Ingo Schwarze, but has been expanded to accept configuration values on the command line.

What follows is a description of the features and facilities provided by the package when included into your sources.

The compatibility layer is generally provided by the excellent portable OpenSSH. All copyrights are noted within the included sources.

b64_ntop

This function, annoyingly, is sometimes declared but not defined. The following will guard against that in your sources. (You'll need to guard again around the function use itself, of course.)

#if HAVE_B64_NTOP
# include <netinet/in.h>
# include <resolv.h>
#endif

In future versions, I'll probably provide a compatibility version of the function.

Capsicum

Tests for FreeBSD's Capsicum subsystem, defining the HAVE_CAPSICUM variable with the result. Does not provide any compatibility. For example,

#if HAVE_CAPSICUM
# include <sys/resource.h>
# include <sys/capsicum.h>
#endif

err.h

Tests for the err(3) functions, defining HAVE_ERR variable with the result.

If not found, provides compatibility functions err, errx, warn, warnx, vwarn, vwarnx. The <err.h> header inclusion needs to be guarded for systems that include it by default; otherwise, the definitions are provided in the generated config.h.

#if HAVE_ERR
# include <err.h>
#endif

explicit_bzero(3)

Tests for explicit_bzero(3), defining HAVE_EXPLICIT_BZERO variable with the result.

If not found, provides a compatibility function.

INFTIM

Some systems (like OpenBSD) define INFTIM for use with poll(2). Others don't. This defines the HAVE_INFTIM variable with the results and, if not found, defines INFTIM to be the proper value.

memmem(3)

Tests for the memmem(3) function, defining HAVE_MEMMEM with the result. Provides a compatibility function if not found.

memrchr(3)

Tests for the memrchr(3) function, defining HAVE_MEMRCHR with the result. Provides a compatibility function if not found.

memset_s

Tests for the C11 memset_s function, defining the HAVE_MEMSET_S variable with the result. Does not provide a compatibility function.

md5.h

Tests for the standalone md5(3) functions, defining HAVE_MD5 with the result.

If not found, provides a full complement of standalone (i.e., not needing any crypto libraries) MD5 hashing functions. These are MD5Init, MD5Update, MD5Pad, MD5Transform, MD5End, and MD5Final. The preprocessor macros MD5_BLOCK_LENGTH, MD5_DIGEST_LENGTH, and MD5_DIGEST_STRING_LENGTH are also defined.

If using these functions, you'll want to guard an inclusion of the system-default:

#if HAVE_MD5
# include <md5.h>
#endif

PATH_MAX

Tests for the PATH_MAX variable, defining HAVE_PATH_MAX with the result. If not found, defines the PATH_MAX macro to be 4096.

pledge(2)

Test for OpenBSD's pledge(2) function, defining HAVE_PLEDGE with the result. Does not provide any compatibility. For example,

#if HAVE_PLEDGE
# include <unistd.h> /* pledge(2) */
#endif

getprogname(3)

Tests for the getprogname(3) function, defining HAVE_GETPROGNAME with the result. Provides a compatibility function if not found.

This internally tests for __progname and program_invocation_short_name if not found, so the HAVE___PROGNAME AND HAVE_PROGRAM_INVOCATION_SHORT_NAME macros will also be defined. Do not use these: use getprogname(3) instead.

reallocarray(3)

Tests for the reallocarray(3) function, defining HAVE_REALLOCARRAY with the result. Provides a compatibility function if not found.

recallocarray(3)

Tests for the recallocarray(3) function, defining HAVE_RECALLOCARRAY with the result. Provides a compatibility function if not found.

sandbox_init(3)

Tests for sandbox_init(3), defining HAVE_SANDBOX_INIT with the result. Does not provide any compatibility.

seccomp-filter(3)

Tests for Linux's prctl(2) function, which is the gateway for seccomp(2). Defines HAVE_SECCOMP_FILTER if found. Does not provide any compatibility.

Note: this test does not mean that the sandboxing is enabled. You'll need to perform a run-time check for prctl's return value in your sources.

SOCK_NONBLOCK

Tests for socketpair(2) supporting the SOCK_NONBLOCK mask as found on OpenBSD. Defines the HAVE_SOCK_NONBLOCK variable.

#if HAVE_SOCK_NONBLOCK
	socketpair(AF_UNIX, flags|SOCK_NONBLOCK, 0, fd);
#else
	socketpair(AF_UNIX, flags, 0, fd);
	fcntl(fd[0], F_SETFL, 
	      fcntl(fd[0], F_GETFL, 0)|O_NONBLOCK);
	fcntl(fd[1], F_SETFL, 
	      fcntl(fd[1], F_GETFL, 0)|O_NONBLOCK);
#endif

Does not provide any compatibility.

strlcat(3)

Tests for the strlcat(3) function, defining HAVE_STRLCAT with the result. Provides a compatibility function if not found.

strlcpy(3)

Tests for the strlcpy(3) function, defining HAVE_STRLCPY with the result. Provides a compatibility function if not found.

strndup(3)

Tests for the strndup(3) function, defining HAVE_STRNDUP with the result. Provides a compatibility function if not found.

strnlen(3)

Tests for the strnlen(3) function, defining HAVE_STRNLEN with the result. Provides a compatibility function if not found.

strtonum(3)

Tests for the strtonum(3) function, defining HAVE_STRTONUM with the result. Provides a compatibility function if not found.

systrace(4)

Tests for OpenBSD's deprecated systrace(4) interface. Defines HAVE_SYSTRACE if found. Does not provide any compatibility.

zlib(3)

Tests for zlib(3) compilation and linking. Defines HAVE_ZLIB if found. Does not provide any compatibility.