diff --git a/.gitignore b/.gitignore index d1cb67fa..010439ab 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ /libtool /stamp-h1 # In-tree build, only top-level +/apisupport-config.h /cpusupport-config.h # In-tree build, all directories .dirstamp diff --git a/Makefile.am b/Makefile.am index e6b9fe1a..a3f265ed 100644 --- a/Makefile.am +++ b/Makefile.am @@ -93,6 +93,7 @@ AM_CPPFLAGS= -I$(srcdir)/lib \ -I$(srcdir)/libcperciva/crypto \ -I$(srcdir)/libcperciva/util \ -DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" \ + -DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" \ -D_POSIX_C_SOURCE=200809L \ -D_XOPEN_SOURCE=700 \ ${CFLAGS_POSIX} @@ -105,10 +106,15 @@ scrypt_LDADD= libcperciva_aesni.la libcperciva_rdrand.la \ ${LDADD_POSIX} scrypt_man_MANS= scrypt.1 +# apisupport needs to access post-configure info: lib-platform/platform.h, +# config.h, and -DHAVE_CONFIG_H. +apisupport-config.h: + ( export CC="${CC}"; export CFLAGS="-I${top_srcdir}/lib-platform -I${builddir} ${DEFS} ${CFLAGS}"; command -p sh $(srcdir)/libcperciva/apisupport/Build/apisupport.sh "$$PATH") > apisupport-config.h.tmp && command -p mv apisupport-config.h.tmp apisupport-config.h cpusupport-config.h: ( export CC="${CC}"; export CFLAGS="${CFLAGS}"; command -p sh $(srcdir)/libcperciva/cpusupport/Build/cpusupport.sh "$$PATH") > cpusupport-config.h.tmp && command -p mv cpusupport-config.h.tmp cpusupport-config.h -BUILT_SOURCES= cpusupport-config.h -CLEANFILES= cpusupport-config.h cpusupport-config.h.tmp +BUILT_SOURCES= apisupport-config.h cpusupport-config.h +CLEANFILES= apisupport-config.h apisupport-config.h.tmp \ + cpusupport-config.h cpusupport-config.h.tmp # Libraries from libcperciva code. noinst_LTLIBRARIES= libcperciva_aesni.la @@ -151,7 +157,7 @@ libscrypt_sse2_la_CFLAGS=`. ./cpusupport-config.h; echo $${CFLAGS_X86_SSE2}` noinst_LTLIBRARIES+= libscrypt_memlimit.la libscrypt_memlimit_la_SOURCES= lib-platform/util/memlimit.c \ lib-platform/util/memlimit.h -libscrypt_memlimit_la_CFLAGS=-U_POSIX_C_SOURCE -U_XOPEN_SOURCE +libscrypt_memlimit_la_CFLAGS=`. ./apisupport-config.h; echo $${CFLAGS_NONPOSIX_MEMLIMIT}` # Install libscrypt-kdf? if LIBSCRYPT_KDF diff --git a/libcperciva/apisupport/Build/apisupport-NONPOSIX-MEMLIMIT.c b/libcperciva/apisupport/Build/apisupport-NONPOSIX-MEMLIMIT.c new file mode 100644 index 00000000..d585ab21 --- /dev/null +++ b/libcperciva/apisupport/Build/apisupport-NONPOSIX-MEMLIMIT.c @@ -0,0 +1,19 @@ +#include "platform.h" + +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef HAVE_SYS_SYSCTL_H +#include +#endif +#ifdef HAVE_SYS_SYSINFO_H +#include +#endif + +int +main(void) +{ + + /* Success! */ + return (0); +} diff --git a/libcperciva/apisupport/Build/apisupport.sh b/libcperciva/apisupport/Build/apisupport.sh new file mode 100755 index 00000000..aedd5662 --- /dev/null +++ b/libcperciva/apisupport/Build/apisupport.sh @@ -0,0 +1,85 @@ +# Should be sourced by `command -p sh path/to/apisupport.sh "$PATH"` from +# within a Makefile. +if ! [ "${PATH}" = "$1" ]; then + echo "WARNING: POSIX violation: ${SHELL}'s command -p resets \$PATH" 1>&2 + PATH=$1 +fi + +# Standard output should be written to apisupport-config.h, which is both a +# C header file defining APISUPPORT_PLATFORM_FEATURE macros and sourceable sh +# code which sets CFLAGS_PLATFORM_FEATURE environment variables. +SRCDIR=$(command -p dirname "$0") + +CFLAGS_HARDCODED="-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700" + +# Do we want to record stderr to a file? +if [ "${DEBUG:-0}" -eq "0" ]; then + outcc="/dev/null" +else + outcc="apisupport-stderr.log" + rm -f "${outcc}" +fi + +feature() { + PLATFORM=$1 + FEATURE=$2 + EXTRALIB=$3 + shift 3; + + # Bail if we didn't include this feature in this source tree. + feature_filename="${SRCDIR}/apisupport-${PLATFORM}-${FEATURE}.c" + if ! [ -f "${feature_filename}" ]; then + return + fi + + # Check if we can compile this feature (and any required arguments). + printf "Checking if compiler supports %s %s feature..." \ + "${PLATFORM}" "${FEATURE}" 1>&2 + for API_CFLAGS in "$@"; do + if ${CC} ${CPPFLAGS} ${CFLAGS} ${CFLAGS_HARDCODED} \ + ${API_CFLAGS} "${feature_filename}" ${LDADD_EXTRA} \ + ${EXTRALIB} 2>>"${outcc}"; then + rm -f a.out + break; + fi + API_CFLAGS=NOTSUPPORTED; + done + case ${API_CFLAGS} in + NOTSUPPORTED) + echo " no" 1>&2 + ;; + "") + echo " yes" 1>&2 + echo "#define APISUPPORT_${PLATFORM}_${FEATURE} 1" + ;; + *) + echo " yes, via ${API_CFLAGS}" 1>&2 + echo "#define APISUPPORT_${PLATFORM}_${FEATURE} 1" + echo "#ifdef apisupport_dummy" + echo "export CFLAGS_${PLATFORM}_${FEATURE}=\"${API_CFLAGS}\"" + echo "#endif" + ;; + esac +} + +if [ "$2" = "--all" ]; then + feature() { + PLATFORM=$1 + FEATURE=$2 + echo "#define APISUPPORT_${PLATFORM}_${FEATURE} 1" + } +fi + +# Detect how to compile non-POSIX code. +feature NONPOSIX SETGROUPS "" "" \ + "-U_POSIX_C_SOURCE -U_XOPEN_SOURCE" \ + "-U_POSIX_C_SOURCE -U_XOPEN_SOURCE -Wno-reserved-id-macro" +feature NONPOSIX MEMLIMIT "" "" \ + "-U_POSIX_C_SOURCE -U_XOPEN_SOURCE" \ + "-U_POSIX_C_SOURCE -U_XOPEN_SOURCE -Wno-reserved-id-macro" + +# Detect how to compile libssl and libcrypto code. +feature LIBSSL HOST_NAME "-lssl" "" \ + "-Wno-cast-qual" +feature LIBCRYPTO LOW_LEVEL_AES "-lcrypto" "" \ + "-Wno-deprecated-declarations"