This is a simple configuration script use for some BSD.lv project sources. It is not really ready for general use, but is used in several projects (ksql, sblg, lowdown, etc.). Its mission is to provide OpenBSD portability functions and feature testing for system-specific security facilities.
See versions.md for version information.
To use:
- copy configure, compats.c, and tests.c into your source tree
- have
include Makefile.configure
at the top of your Makefile - have
#include "config.h"
as the first inclusion in your sources - 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).
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.
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
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
Tests for
explicit_bzero(3), defining
HAVE_EXPLICIT_BZERO
variable with the result.
If not found, provides a compatibility function.
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.
Tests for the memmem(3)
function, defining HAVE_MEMMEM
with the result.
Provides a compatibility function if not found.
Tests for the memrchr(3)
function, defining HAVE_MEMRCHR
with the result.
Provides a compatibility function if not found.
Tests for the C11
memset_s function,
defining the HAVE_MEMSET_S
variable with the result.
Does not provide a compatibility function.
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
Tests for the PATH_MAX
variable, defining HAVE_PATH_MAX
with the
result.
If not found, defines the PATH_MAX
macro to be 4096.
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
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.
Tests for the reallocarray(3)
function, defining HAVE_REALLOCARRAY
with the result.
Provides a compatibility function if not found.
Tests for the recallocarray(3)
function, defining HAVE_RECALLOCARRAY
with the result.
Provides a compatibility function if not found.
Tests for
sandbox_init(3),
defining HAVE_SANDBOX_INIT
with the result.
Does not provide any compatibility.
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.
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.
Tests for the strlcat(3)
function, defining HAVE_STRLCAT
with the result.
Provides a compatibility function if not found.
Tests for the strlcpy(3)
function, defining HAVE_STRLCPY
with the result.
Provides a compatibility function if not found.
Tests for the strndup(3)
function, defining HAVE_STRNDUP
with the result.
Provides a compatibility function if not found.
Tests for the strnlen(3)
function, defining HAVE_STRNLEN
with the result.
Provides a compatibility function if not found.
Tests for the strtonum(3)
function, defining HAVE_STRTONUM
with the result.
Provides a compatibility function if not found.
Tests for OpenBSD's deprecated systrace(4) interface.
Defines HAVE_SYSTRACE
if found.
Does not provide any compatibility.
Tests for zlib(3) compilation and linking. Defines HAVE_ZLIB
if
found. Does not provide any compatibility.