-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #384 from Tarsnap/apisupport
Import and use apisupport
- Loading branch information
Showing
4 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
libcperciva/apisupport/Build/apisupport-NONPOSIX-MEMLIMIT.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "platform.h" | ||
|
||
#ifdef HAVE_SYS_PARAM_H | ||
#include <sys/param.h> | ||
#endif | ||
#ifdef HAVE_SYS_SYSCTL_H | ||
#include <sys/sysctl.h> | ||
#endif | ||
#ifdef HAVE_SYS_SYSINFO_H | ||
#include <sys/sysinfo.h> | ||
#endif | ||
|
||
int | ||
main(void) | ||
{ | ||
|
||
/* Success! */ | ||
return (0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |