#!/bin/sh - # # @(#)$Id: mkconfig,v 1.2 2018/09/28 05:49:13 jneitzel Exp $ # # Write out an appropriate "config.h" file. # This script is invoked automatically from the Makefile. # Thus, the user does not need to run it manually. # # Exit w/ a status of 0 on success. # Exit w/ a status of 1 on error. # -- # Jeffrey Allen Neitzel # CONFIG_H="config.h" rm -f $CONFIG_H trap 'status=$? ; rm -f $CONFIG_H ; exit $status' HUP INT QUIT TERM UNAME_S="`uname -s`" UNAME_SRM="`uname -srm`" PROGNAME="`basename $0`" if test $# -ne 0 ; then echo 'usage: $(SHELL) ./'"$PROGNAME" >&2 ; exit 1 ; fi if test X"$UNAME_S" = X -o X"$UNAME_SRM" = X ; then echo "$PROGNAME: Fatal uname(1) error" >&2 ; exit 1 fi # # Check whether or not we have the arc4random_uniform() function. # checkHaveArc4randomUniform() { rm -f arc4randomu.c arc4randomu cat <arc4randomu.c #include int main(void) { (void)arc4random_uniform(0200); return 0; } EOI cc -std=c99 -pedantic -Wall -Wextra -o arc4randomu arc4randomu.c >/dev/null 2>&1 test $? -eq 0 && ./arc4randomu test $? -eq 0 && echo '#define HAVE_ARC4RANDOM_UNIFORM 1' || echo '#define HAVE_ARC4RANDOM_UNIFORM 0' rm -f arc4randomu.c arc4randomu } cat <$CONFIG_H /* * rasgen - a random ASCII string generator */ /* * _XOPEN_SOURCE and/or _DEFAULT_SOURCE should be defined only if needed * to avoid compilation errors or warnings for the rasgen program on a * given system. The systems where these feature test macros are (known * to be) needed are defined in the mkconfig script. * * This includes only Linux and (?maybe?) SunOS (Solaris/OpenIndiana) * at the present time. * * Configured for: $UNAME_SRM */ #ifndef CONFIG_H #define CONFIG_H `checkHaveArc4randomUniform` EOI case "$UNAME_S" in *BSD|Darwin|DragonFly) echo "/* $UNAME_S: No need for _XOPEN_SOURCE or _DEFAULT_SOURCE */" \ >>$CONFIG_H ;; Linux) echo '#define _XOPEN_SOURCE 700' >>$CONFIG_H echo '#define _DEFAULT_SOURCE' >>$CONFIG_H ;; SunOS) ( echo '#define CONFIG_SUNOS' ; echo ) >>$CONFIG_H echo '#define _XOPEN_SOURCE 700' >>$CONFIG_H ;; *) # # This may or may not cause a compilation error. # Simply try it to see if it works or not. # echo "$PROGNAME: WARNING: Check \"$CONFIG_H\" if compilation fails." >&2 cat <>$CONFIG_H /* * WARNING: $UNAME_SRM: Unknown system * * Please report this result to the developer if possible. */ EOI ;; esac echo >>$CONFIG_H echo '#endif /* !CONFIG_H */' >>$CONFIG_H