Skip to content

Commit e584f2c

Browse files
authored
Merge pull request #384 from Tarsnap/apisupport
Import and use apisupport
2 parents c3a97fc + 334db8e commit e584f2c

4 files changed

Lines changed: 114 additions & 3 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
/libtool
2828
/stamp-h1
2929
# In-tree build, only top-level
30+
/apisupport-config.h
3031
/cpusupport-config.h
3132
# In-tree build, all directories
3233
.dirstamp

Makefile.am

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ AM_CPPFLAGS= -I$(srcdir)/lib \
9393
-I$(srcdir)/libcperciva/crypto \
9494
-I$(srcdir)/libcperciva/util \
9595
-DCPUSUPPORT_CONFIG_FILE=\"cpusupport-config.h\" \
96+
-DAPISUPPORT_CONFIG_FILE=\"apisupport-config.h\" \
9697
-D_POSIX_C_SOURCE=200809L \
9798
-D_XOPEN_SOURCE=700 \
9899
${CFLAGS_POSIX}
@@ -105,10 +106,15 @@ scrypt_LDADD= libcperciva_aesni.la libcperciva_rdrand.la \
105106
${LDADD_POSIX}
106107
scrypt_man_MANS= scrypt.1
107108

109+
# apisupport needs to access post-configure info: lib-platform/platform.h,
110+
# config.h, and -DHAVE_CONFIG_H.
111+
apisupport-config.h:
112+
( 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
108113
cpusupport-config.h:
109114
( 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
110-
BUILT_SOURCES= cpusupport-config.h
111-
CLEANFILES= cpusupport-config.h cpusupport-config.h.tmp
115+
BUILT_SOURCES= apisupport-config.h cpusupport-config.h
116+
CLEANFILES= apisupport-config.h apisupport-config.h.tmp \
117+
cpusupport-config.h cpusupport-config.h.tmp
112118

113119
# Libraries from libcperciva code.
114120
noinst_LTLIBRARIES= libcperciva_aesni.la
@@ -151,7 +157,7 @@ libscrypt_sse2_la_CFLAGS=`. ./cpusupport-config.h; echo $${CFLAGS_X86_SSE2}`
151157
noinst_LTLIBRARIES+= libscrypt_memlimit.la
152158
libscrypt_memlimit_la_SOURCES= lib-platform/util/memlimit.c \
153159
lib-platform/util/memlimit.h
154-
libscrypt_memlimit_la_CFLAGS=-U_POSIX_C_SOURCE -U_XOPEN_SOURCE
160+
libscrypt_memlimit_la_CFLAGS=`. ./apisupport-config.h; echo $${CFLAGS_NONPOSIX_MEMLIMIT}`
155161

156162
# Install libscrypt-kdf?
157163
if LIBSCRYPT_KDF
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "platform.h"
2+
3+
#ifdef HAVE_SYS_PARAM_H
4+
#include <sys/param.h>
5+
#endif
6+
#ifdef HAVE_SYS_SYSCTL_H
7+
#include <sys/sysctl.h>
8+
#endif
9+
#ifdef HAVE_SYS_SYSINFO_H
10+
#include <sys/sysinfo.h>
11+
#endif
12+
13+
int
14+
main(void)
15+
{
16+
17+
/* Success! */
18+
return (0);
19+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Should be sourced by `command -p sh path/to/apisupport.sh "$PATH"` from
2+
# within a Makefile.
3+
if ! [ "${PATH}" = "$1" ]; then
4+
echo "WARNING: POSIX violation: ${SHELL}'s command -p resets \$PATH" 1>&2
5+
PATH=$1
6+
fi
7+
8+
# Standard output should be written to apisupport-config.h, which is both a
9+
# C header file defining APISUPPORT_PLATFORM_FEATURE macros and sourceable sh
10+
# code which sets CFLAGS_PLATFORM_FEATURE environment variables.
11+
SRCDIR=$(command -p dirname "$0")
12+
13+
CFLAGS_HARDCODED="-D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
14+
15+
# Do we want to record stderr to a file?
16+
if [ "${DEBUG:-0}" -eq "0" ]; then
17+
outcc="/dev/null"
18+
else
19+
outcc="apisupport-stderr.log"
20+
rm -f "${outcc}"
21+
fi
22+
23+
feature() {
24+
PLATFORM=$1
25+
FEATURE=$2
26+
EXTRALIB=$3
27+
shift 3;
28+
29+
# Bail if we didn't include this feature in this source tree.
30+
feature_filename="${SRCDIR}/apisupport-${PLATFORM}-${FEATURE}.c"
31+
if ! [ -f "${feature_filename}" ]; then
32+
return
33+
fi
34+
35+
# Check if we can compile this feature (and any required arguments).
36+
printf "Checking if compiler supports %s %s feature..." \
37+
"${PLATFORM}" "${FEATURE}" 1>&2
38+
for API_CFLAGS in "$@"; do
39+
if ${CC} ${CPPFLAGS} ${CFLAGS} ${CFLAGS_HARDCODED} \
40+
${API_CFLAGS} "${feature_filename}" ${LDADD_EXTRA} \
41+
${EXTRALIB} 2>>"${outcc}"; then
42+
rm -f a.out
43+
break;
44+
fi
45+
API_CFLAGS=NOTSUPPORTED;
46+
done
47+
case ${API_CFLAGS} in
48+
NOTSUPPORTED)
49+
echo " no" 1>&2
50+
;;
51+
"")
52+
echo " yes" 1>&2
53+
echo "#define APISUPPORT_${PLATFORM}_${FEATURE} 1"
54+
;;
55+
*)
56+
echo " yes, via ${API_CFLAGS}" 1>&2
57+
echo "#define APISUPPORT_${PLATFORM}_${FEATURE} 1"
58+
echo "#ifdef apisupport_dummy"
59+
echo "export CFLAGS_${PLATFORM}_${FEATURE}=\"${API_CFLAGS}\""
60+
echo "#endif"
61+
;;
62+
esac
63+
}
64+
65+
if [ "$2" = "--all" ]; then
66+
feature() {
67+
PLATFORM=$1
68+
FEATURE=$2
69+
echo "#define APISUPPORT_${PLATFORM}_${FEATURE} 1"
70+
}
71+
fi
72+
73+
# Detect how to compile non-POSIX code.
74+
feature NONPOSIX SETGROUPS "" "" \
75+
"-U_POSIX_C_SOURCE -U_XOPEN_SOURCE" \
76+
"-U_POSIX_C_SOURCE -U_XOPEN_SOURCE -Wno-reserved-id-macro"
77+
feature NONPOSIX MEMLIMIT "" "" \
78+
"-U_POSIX_C_SOURCE -U_XOPEN_SOURCE" \
79+
"-U_POSIX_C_SOURCE -U_XOPEN_SOURCE -Wno-reserved-id-macro"
80+
81+
# Detect how to compile libssl and libcrypto code.
82+
feature LIBSSL HOST_NAME "-lssl" "" \
83+
"-Wno-cast-qual"
84+
feature LIBCRYPTO LOW_LEVEL_AES "-lcrypto" "" \
85+
"-Wno-deprecated-declarations"

0 commit comments

Comments
 (0)