First Commit

This commit is contained in:
2025-02-06 22:24:29 +08:00
parent ed7df4c81e
commit 7539e6a53c
18116 changed files with 6181499 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
#!/usr/bin/env bash
#############################################################################
#
# This script switches back to the previous Crypto++ version before
# building the docs. Before running the script, copy it to the root
# directory. After running this script, you can 'make docs'
#
# Written and placed in public domain by Jeffrey Walton.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
# See https://www.cryptopp.com/wiki/Release_Versioning for more details
#
#############################################################################
sed 's/Library 8.9 API/Library 8.8 API/g' cryptlib.h > cryptlib.h.new
mv cryptlib.h.new cryptlib.h
sed 's/= 8.9/= 8.8/g' Doxyfile > Doxyfile.new
mv Doxyfile.new Doxyfile
sed 's/CRYPTOPP_MINOR 9/CRYPTOPP_MINOR 8/g' config_ver.h > config_ver.h.new
mv config_ver.h.new config_ver.h
# sed 'CRYPTOPP_REVISION CRYPTOPP_REVISION 1/g' config_ver.h > config_ver.h.new
# mv config_ver.h.new config_ver.h
sed 's/CRYPTOPP_VERSION 890/CRYPTOPP_VERSION 880/g' config_ver.h > config_ver.h.new
mv config_ver.h.new config_ver.h

View File

@@ -0,0 +1,938 @@
#!/usr/bin/env bash
# Written and placed in public domain by Jeffrey Walton
#
# This script attempts to update various config_xxx.h files based on the
# current toolchain. It fills a gap where some features are misdetected based
# on compiler version and associated macros, but the feature is (or is not)
# present. For example, modern Android toolchains should be AES-NI and AVX
# capable, but the project removes the feature support.
#
# Use the same compiler and environment to run configure and the makefile.
#
# To use the script, copy the script to the root of the Crypto++ directory.
# Set the environment, and then run the tool:
#
# export CXX="..."
# export CXXFLAGS="..."
# export LDFLAGS="..."
# ./configure.sh
#
# Android and iOS would use the following if you are using setenv-android.sh
# or setenv-ios.sh to set the environment. Otherwise the script expects
# CXX and CXXFLAGS to be set properly for Android or iOS.
#
# export CXXFLAGS="$IOS_CXXFLAGS --sysroot=$IOS_SYSROOT"
# or
# export CXXFLAGS="${ANDROID_CXXFLAGS} --sysroot=${ANDROID_SYSROOT}"
#
# Do not use this script for a multiarch environment unless the cpu features
# are the same for each arch. For example, -arch i386 -arch x86_64 could
# cause problems if x86 only included SSE4.2, while x64 included AVX.
#
# A wiki page is available for this script at
# https://www.cryptopp.com/wiki/Configure.sh
#
# This script was added at Crypto++ 8.3. Also see GH #850. This script will
# work with earlier versions of the library that use config_xxx.h files.
# The monolithic config.h was split into config_xxx.h in May 2019 at
# Crypto++ 8.3. Also see GH #835, PR #836.
# shellcheck disable=SC2086
# Verify the file exists and is writeable.
if [[ ! -f ./config_asm.h ]]; then
echo "WARNING:"
echo "WARNING: Unable to locate config_asm.h"
echo "WARNING:"
elif [[ ! -w ./config_asm.h ]]; then
echo "WARNING:"
echo "WARNING: Unable to write to config_asm.h"
echo "WARNING:"
fi
TMPDIR="${TMPDIR:-$HOME/tmp}"
TPROG="${TPROG:-TestPrograms/test_cxx.cpp}"
TOUT="${TOUT:-a.out}"
CC="${CC:-cc}"
CXX="${CXX:-c++}"
LD="${LD:-ld}"
CXXFLAGS="${CXXFLAGS:--DNDEBUG -g2 -O3}"
GREP="${GREP:-grep}"
if [[ -z "$(command -v ${CXX} 2>/dev/null)" ]]; then
echo "Compiler is not valid. Please install a compiler"
exit 1
fi
if [[ -z "$(command -v ${LD} 2>/dev/null)" ]]; then
echo "Linker is not valid. Please install a linker"
exit 1
fi
# Solaris fixup
if [[ -d /usr/gnu/bin ]]; then
GREP=/usr/gnu/bin/grep
fi
# Initialize these once
IS_X86=0
IS_X64=0
IS_IA32=0
IS_ARM32=0
IS_ARMV8=0
IS_PPC=0
IS_PPC64=0
# Determine compiler
GCC_COMPILER=$(${CXX} --version 2>/dev/null | ${GREP} -i -c -E '(^g\+\+|GNU)')
SUN_COMPILER=$(${CXX} -V 2>/dev/null | ${GREP} -i -c -E 'CC: (Sun|Oracle) Studio')
XLC_COMPILER=$(${CXX} -qversion 2>/dev/null | ${GREP} -i -c "IBM XL C/C++")
CLANG_COMPILER=$(${CXX} --version 2>/dev/null | ${GREP} -i -c -E 'clang|llvm')
if [[ "$SUN_COMPILER" -ne 0 ]]
then
# TODO: fix use of uname for SunCC
IS_X86=$(uname -m 2>&1 | ${GREP} -c -E 'i386|i486|i585|i686')
IS_X64=$(uname -m 2>&1 | ${GREP} -c -E 'i86pc|x86_64|amd64')
elif [[ "$XLC_COMPILER" -ne 0 ]]
then
IS_PPC=$(${CXX} ${CXXFLAGS} -qshowmacros -E ${TPROG} | ${GREP} -i -c -E '__PPC__|__POWERPC__')
IS_PPC64=$(${CXX} ${CXXFLAGS} -qshowmacros -E ${TPROG} | ${GREP} -i -c -E '__PPC64__|__POWERPC64__')
elif [[ "$CLANG_COMPILER" -ne 0 ]]
then
IS_X86=$(${CXX} ${CXXFLAGS} -dM -E ${TPROG} | ${GREP} -i -c -E 'i386|i486|i585|i686')
IS_X64=$(${CXX} ${CXXFLAGS} -dM -E ${TPROG} | ${GREP} -i -c -E 'i86pc|x86_64|amd64')
IS_ARM32=$(${CXX} ${CXXFLAGS} -dM -E ${TPROG} | ${GREP} -i -c -E 'arm|armhf|armv7|eabihf|armv8')
IS_ARMV8=$(${CXX} ${CXXFLAGS} -dM -E ${TPROG} | ${GREP} -i -c -E 'aarch32|aarch64|arm64')
IS_PPC=$(${CXX} ${CXXFLAGS} -dM -E ${TPROG} | ${GREP} -i -c -E 'ppc|powerpc')
IS_PPC64=$(${CXX} ${CXXFLAGS} -dM -E ${TPROG} | ${GREP} -c -E 'ppc64|powerpc64')
else
IS_X86=$(${CXX} ${CXXFLAGS} -dumpmachine 2>&1 | ${GREP} -i -c -E 'i386|i486|i585|i686')
IS_X64=$(${CXX} ${CXXFLAGS} -dumpmachine 2>&1 | ${GREP} -i -c -E 'x86_64|amd64')
IS_ARM32=$(${CXX} ${CXXFLAGS} -dumpmachine 2>&1 | ${GREP} -i -c -E 'arm|armhf|armv7|eabihf|armv8')
IS_ARMV8=$(${CXX} ${CXXFLAGS} -dumpmachine 2>&1 | ${GREP} -i -c -E 'aarch32|aarch64|arm64')
IS_PPC=$(${CXX} ${CXXFLAGS} -dumpmachine 2>&1 | ${GREP} -i -c -E 'ppc|powerpc')
IS_PPC64=$(${CXX} ${CXXFLAGS} -dumpmachine 2>&1 | ${GREP} -i -c -E 'ppc64|powerpc64')
fi
# One check for intel compatibles
if [[ "${IS_X86}" -ne 0 || "${IS_X64}" -ne 0 ]]; then IS_IA32=1; fi
# A 64-bit platform often matches the 32-bit variant due to appending '64'
if [[ "${IS_X64}" -ne 0 ]]; then IS_X86=0; fi
if [[ "${IS_ARMV8}" -ne 0 ]]; then IS_ARM32=0; fi
if [[ "${IS_PPC64}" -ne 0 ]]; then IS_PPC=0; fi
# Default values for setenv-*.sh scripts
IS_IOS="${IS_IOS:-0}"
IS_ANDROID="${IS_ANDROID:-0}"
TIMESTAMP=$(date "+%A, %B %d %Y, %I:%M %p")
# ===========================================================================
# =================================== Info ==================================
# ===========================================================================
if [[ "${IS_X86}" -ne 0 ]]; then echo "Configuring for x86"; fi
if [[ "${IS_X64}" -ne 0 ]]; then echo "Configuring for x86_64"; fi
if [[ "${IS_ARM32}" -ne 0 ]]; then echo "Configuring for ARM32"; fi
if [[ "${IS_ARMV8}" -ne 0 ]]; then echo "Configuring for Aarch64"; fi
if [[ "${IS_PPC}" -ne 0 ]]; then echo "Configuring for PowerPC"; fi
if [[ "${IS_PPC64}" -ne 0 ]]; then echo "Configuring for PowerPC64"; fi
echo "Compiler: $(command -v ${CXX})"
echo "Linker: $(command -v ${LD})"
# ===========================================================================
# =============================== config_asm.h ==============================
# ===========================================================================
rm -f config_asm.h.new
# ====================================================
# =================== common header ==================
# ====================================================
{
echo '// config_asm.h rewritten by configure.sh script'
echo '//' "${TIMESTAMP}"
echo '// Also see https://www.cryptopp.com/wiki/configure.sh'
echo ''
echo '#ifndef CRYPTOPP_CONFIG_ASM_H'
echo '#define CRYPTOPP_CONFIG_ASM_H'
echo ''
} >> config_asm.h.new
#############################################################################
# Pickup CRYPTOPP_DISABLE_ASM
disable_asm=$($GREP -c '\-DCRYPTOPP_DISABLE_ASM' <<< "${CPPFLAGS} ${CXXFLAGS}")
if [[ "$disable_asm" -ne 0 ]];
then
# Shell redirection
{
echo ''
echo '// Set in CPPFLAGS or CXXFLAGS'
echo '#define CRYPTOPP_DISABLE_ASM 1'
} >> config_asm.h.new
fi
#############################################################################
# Intel x86-based machines
if [[ "$disable_asm" -eq 0 && "$IS_IA32" -ne 0 ]];
then
if [[ "${SUN_COMPILER}" -ne 0 ]]; then
SSE2_FLAG=-xarch=sse2
SSE3_FLAG=-xarch=sse3
SSSE3_FLAG=-xarch=ssse3
SSE41_FLAG=-xarch=sse4_1
SSE42_FLAG=-xarch=sse4_2
CLMUL_FLAG=-xarch=aes
AESNI_FLAG=-xarch=aes
RDRAND_FLAG=-xarch=avx_i
RDSEED_FLAG=-xarch=avx2_i
AVX_FLAG=-xarch=avx
AVX2_FLAG=-xarch=avx2
SHANI_FLAG=-xarch=sha
else
SSE2_FLAG=-msse2
SSE3_FLAG=-msse3
SSSE3_FLAG=-mssse3
SSE41_FLAG=-msse4.1
SSE42_FLAG=-msse4.2
CLMUL_FLAG=-mpclmul
AESNI_FLAG=-maes
RDRAND_FLAG=-mrdrnd
RDSEED_FLAG=-mrdseed
AVX_FLAG=-mavx
AVX2_FLAG=-mavx2
SHANI_FLAG=-msha
fi
# Shell redirection
{
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${SSE2_FLAG} TestPrograms/test_x86_sse2.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -ne 0 ]]; then
echo '#define CRYPTOPP_DISABLE_ASM 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${SSE2_FLAG} TestPrograms/test_asm_sse2.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_X86_ASM_AVAILABLE 1'
if [[ "${IS_X64}" -ne 0 ]]; then
echo '#define CRYPTOPP_X64_ASM_AVAILABLE 1'
echo '#define CRYPTOPP_SSE2_ASM_AVAILABLE 1'
fi
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${SSE2_FLAG} TestPrograms/test_x86_sse2.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
have_sse2=1
echo '#define CRYPTOPP_SSE2_INTRIN_AVAILABLE 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${SSE3_FLAG} TestPrograms/test_x86_sse3.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
have_sse3=1
echo '#define CRYPTOPP_SSE3_AVAILABLE 1'
else
have_sse3=0
echo '#define CRYPTOPP_DISABLE_SSE3 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${SSSE3_FLAG} TestPrograms/test_x86_ssse3.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_sse3" -ne 0 ]]; then
have_ssse3=1
echo '#define CRYPTOPP_SSSE3_ASM_AVAILABLE 1'
echo '#define CRYPTOPP_SSSE3_AVAILABLE 1'
else
have_ssse3=0
echo '#define CRYPTOPP_DISABLE_SSSE3 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${SSE41_FLAG} TestPrograms/test_x86_sse41.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_ssse3" -ne 0 ]]; then
have_sse41=1
echo '#define CRYPTOPP_SSE41_AVAILABLE 1'
else
have_sse41=0
echo '#define CRYPTOPP_DISABLE_SSE4 1'
echo '#define CRYPTOPP_DISABLE_SSE41 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${SSE42_FLAG} TestPrograms/test_x86_sse42.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_sse41" -ne 0 ]]; then
have_sse42=1
echo '#define CRYPTOPP_SSE42_AVAILABLE 1'
else
have_sse42=0
echo '#define CRYPTOPP_DISABLE_SSE4 1'
echo '#define CRYPTOPP_DISABLE_SSE42 1'
fi
########################################################
# AES, CLMUL, RDRAND, RDSEED, SHA and AVX tied to SSE4.2
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${CLMUL_FLAG} TestPrograms/test_x86_clmul.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_sse42" -ne 0 ]]; then
echo '#define CRYPTOPP_CLMUL_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_CLMUL 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${AESNI_FLAG} TestPrograms/test_x86_aes.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_sse42" -ne 0 ]]; then
echo '#define CRYPTOPP_AESNI_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_AESNI 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${RDRAND_FLAG} TestPrograms/test_x86_rdrand.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_sse42" -ne 0 ]]; then
echo '#define CRYPTOPP_RDRAND_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_RDRAND 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${RDSEED_FLAG} TestPrograms/test_x86_rdseed.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_sse42" -ne 0 ]]; then
echo '#define CRYPTOPP_RDSEED_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_RDSEED 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${SHANI_FLAG} TestPrograms/test_x86_sha.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_sse42" -ne 0 ]]; then
echo '#define CRYPTOPP_SHANI_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_SHANI 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${AVX_FLAG} TestPrograms/test_x86_avx.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_sse42" -ne 0 ]]; then
have_avx=1
echo '#define CRYPTOPP_AVX_AVAILABLE 1'
else
have_avx=0
echo '#define CRYPTOPP_DISABLE_AVX 1'
fi
#####################
# AVX2 depends on AVX
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${AVX2_FLAG} TestPrograms/test_x86_avx2.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_avx" -ne 0 ]]; then
have_avx2=1
echo '#define CRYPTOPP_AVX2_AVAILABLE 1'
else
have_avx2=0
echo '#define CRYPTOPP_DISABLE_AVX2 1'
fi
# No flags, requires inline ASM
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_x86_via_rng.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_PADLOCK_RNG_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_PADLOCK_RNG 1'
fi
# No flags, requires inline ASM
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_x86_via_aes.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_PADLOCK_AES_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_PADLOCK_AES 1'
fi
# No flags, requires inline ASM
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_x86_via_sha.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_PADLOCK_SHA_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_PADLOCK_SHA 1'
fi
# Clang workaround
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_asm_mixed.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -ne 0 ]]; then
echo '#define CRYPTOPP_DISABLE_MIXED_ASM 1'
fi
if [[ "${SUN_COMPILER}" -ne 0 ]]; then
echo ''
echo '// Fixup for SunCC 12.1-12.4. Bad code generation in AES_Encrypt and friends.'
echo '#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5130)'
echo '# undef CRYPTOPP_AESNI_AVAILABLE'
echo '#endif'
echo ''
echo '// Fixup for SunCC 12.1-12.6. Compiler crash on GCM_Reduce_CLMUL.'
echo '// http://github.com/weidai11/cryptopp/issues/226'
echo '#if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x5150)'
echo '# undef CRYPTOPP_CLMUL_AVAILABLE'
echo '#endif'
fi
echo ''
echo '// Clang intrinsic casts, http://bugs.llvm.org/show_bug.cgi?id=20670'
echo '#define M128_CAST(x) ((__m128i *)(void *)(x))'
echo '#define CONST_M128_CAST(x) ((const __m128i *)(const void *)(x))'
echo '#define M256_CAST(x) ((__m256i *)(void *)(x))'
echo '#define CONST_M256_CAST(x) ((const __m256i *)(const void *)(x))'
} >> config_asm.h.new
fi
#############################################################################
# ARM 32-bit machines
if [[ "$disable_asm" -eq 0 && "$IS_ARM32" -ne 0 ]];
then
# IS_IOS is set when ./setenv-ios is run
if [[ "$IS_IOS" -ne 0 ]]; then
ARMV7_FLAG="-arch arm"
NEON_FLAG="-arch arm"
elif [[ "$CLANG_COMPILER" -ne 0 ]]; then
ARMV7_FLAG="-march=armv7"
NEON_FLAG="-march=armv7 -mfpu=neon"
else
ARMV7_FLAG="-march=armv7"
NEON_FLAG="-mfpu=neon"
fi
# Shell redirection
{
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${NEON_FLAG} TestPrograms/test_arm_neon_header.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_NEON_HEADER 1'
HDRFLAGS="-DCRYPTOPP_ARM_NEON_HEADER=1"
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} ${ARMV7_FLAG} TestPrograms/test_cxx.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_ARMV7_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_ARMV7 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} ${NEON_FLAG} TestPrograms/test_arm_neon.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_NEON_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_NEON 1'
fi
# Cryptogams is special. Attempt to compile the actual source files
# TestPrograms/test_cxx.cpp is needed for main().
CXX_RESULT=$(${CXX} ${CXXFLAGS} aes_armv4.S TestPrograms/test_cxx.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOGAMS_ARM_AES 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} sha1_armv4.S TestPrograms/test_cxx.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOGAMS_ARM_SHA1 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} sha256_armv4.S TestPrograms/test_cxx.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOGAMS_ARM_SHA256 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} sha512_armv4.S TestPrograms/test_cxx.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOGAMS_ARM_SHA512 1'
fi
} >> config_asm.h.new
fi
#############################################################################
# ARM 64-bit machines
if [[ "$disable_asm" -eq 0 && "$IS_ARMV8" -ne 0 ]];
then
# IS_IOS is set when ./setenv-ios is run
if [[ "$IS_IOS" -ne 0 ]]; then
ARMV8_FLAG="-arch arm64"
ARMV81_CRC_FLAG="-arch arm64"
ARMV81_CRYPTO_FLAG="-arch arm64"
ARMV84_CRYPTO_FLAG="-arch arm64"
else
ARMV8_FLAG="-march=armv8-a"
ARMV81_CRC_FLAG="-march=armv8-a+crc"
ARMV81_CRYPTO_FLAG="-march=armv8-a+crypto"
ARMV84_CRYPTO_FLAG="-march=armv8.4-a+crypto"
fi
# Shell redirection
{
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_arm_neon_header.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_NEON_HEADER 1'
HDRFLAGS="-DCRYPTOPP_ARM_NEON_HEADER=1"
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} TestPrograms/test_arm_acle_header.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_ACLE_HEADER 1'
HDRFLAGS="${HDRFLAGS} -DCRYPTOPP_ARM_ACLE_HEADER=1"
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} TestPrograms/test_arm_neon.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_NEON_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_NEON 1'
fi
# This should be an unneeded test. ASIMD on Aarch64 is NEON on A32 and T32
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} TestPrograms/test_arm_asimd.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_ASIMD_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_ASIMD 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} ${ARMV81_CRC_FLAG} TestPrograms/test_arm_crc.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_CRC32_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_CRC32 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} ${ARMV81_CRYPTO_FLAG} TestPrograms/test_arm_aes.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_AES_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_AES 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} ${ARMV81_CRYPTO_FLAG} TestPrograms/test_arm_pmull.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_PMULL_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_PMULL 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} ${ARMV81_CRYPTO_FLAG} TestPrograms/test_arm_sha1.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_SHA_AVAILABLE 1'
echo '#define CRYPTOPP_ARM_SHA1_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_SHA 1'
echo '#define CRYPTOPP_DISABLE_ARM_SHA1 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} ${ARMV81_CRYPTO_FLAG} TestPrograms/test_arm_sha256.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_SHA2_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_SHA2 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} ${ARMV84_CRYPTO_FLAG} TestPrograms/test_arm_sha3.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_SHA3_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_SHA3 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} ${ARMV84_CRYPTO_FLAG} TestPrograms/test_arm_sha512.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_SHA512_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_SHA512 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} ${ARMV84_CRYPTO_FLAG} TestPrograms/test_arm_sm3.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_SM3_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_SM3 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${HDRFLAGS} ${ARMV84_CRYPTO_FLAG} TestPrograms/test_arm_sm4.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_ARM_SM4_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_ARM_SM4 1'
fi
} >> config_asm.h.new
fi
#############################################################################
# PowerPC machines
if [[ "$disable_asm" -eq 0 && ("$IS_PPC" -ne 0 || "$IS_PPC64" -ne 0) ]];
then
# IBM XL C/C++ has the -qaltivec flag really screwed up. We can't seem
# to get it enabled without an -qarch= option. And -qarch= produces an
# error on later versions of the compiler. The only thing that seems
# to work consistently is -qarch=auto.
if [[ "${XLC_COMPILER}" -ne 0 ]]; then
POWER9_FLAG="-qarch=pwr9 -qaltivec"
POWER8_FLAG="-qarch=pwr8 -qaltivec"
POWER7_VSX_FLAG="-qarch=pwr7 -qvsx -qaltivec"
POWER7_PWR_FLAG="-qarch=pwr7 -qaltivec"
ALTIVEC_FLAG="-qarch=auto -qaltivec"
else
POWER9_FLAG="-mcpu=power9"
POWER8_FLAG="-mcpu=power8"
POWER7_VSX_FLAG="-mcpu=power7 -mvsx"
POWER7_PWR_FLAG="-mcpu=power7"
ALTIVEC_FLAG="-maltivec"
fi
# Shell redirection
{
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${ALTIVEC_FLAG} TestPrograms/test_ppc_altivec.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
have_altivec=1
echo '#define CRYPTOPP_ALTIVEC_AVAILABLE 1'
else
have_altivec=0
echo '#define CRYPTOPP_DISABLE_ALTIVEC 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${POWER7_PWR_FLAG} TestPrograms/test_ppc_power7.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_altivec" -ne 0 ]]; then
have_power7=1
echo '#define CRYPTOPP_POWER7_AVAILABLE 1'
else
have_power7=0
echo '#define CRYPTOPP_DISABLE_POWER7 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${POWER8_FLAG} TestPrograms/test_ppc_power8.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_power7" -ne 0 ]]; then
have_power8=1
echo '#define CRYPTOPP_POWER8_AVAILABLE 1'
else
have_power8=0
echo '#define CRYPTOPP_DISABLE_POWER8 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${POWER9_FLAG} TestPrograms/test_ppc_power9.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_power8" -ne 0 ]]; then
have_power9=1
echo '#define CRYPTOPP_POWER9_AVAILABLE 1'
else
have_power9=0
echo '#define CRYPTOPP_DISABLE_POWER9 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${POWER8_FLAG} TestPrograms/test_ppc_aes.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_power8" -ne 0 ]]; then
echo '#define CRYPTOPP_POWER8_AES_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_POWER8_AES 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${POWER8_FLAG} TestPrograms/test_ppc_vmull.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_power8" -ne 0 ]]; then
echo '#define CRYPTOPP_POWER8_VMULL_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_POWER8_VMULL 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} ${POWER8_FLAG} TestPrograms/test_ppc_sha.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 && "$have_power8" -ne 0 ]]; then
echo '#define CRYPTOPP_POWER8_SHA_AVAILABLE 1'
else
echo '#define CRYPTOPP_DISABLE_POWER8_SHA 1'
fi
} >> config_asm.h.new
fi
# ====================================================
# =================== common footer ==================
# ====================================================
{
echo ''
echo '#endif // CRYPTOPP_CONFIG_ASM_H'
echo ''
} >> config_asm.h.new
if [[ -e config_asm.h ]]; then
cp config_asm.h config_asm.h.old
mv config_asm.h.new config_asm.h
fi
echo 'Done writing config_asm.h'
# ===========================================================================
# =============================== config_cxx.h ==============================
# ===========================================================================
rm -f config_cxx.h.new
# ====================================================
# =================== common header ==================
# ====================================================
{
echo '// config_cxx.h rewritten by configure.sh script'
echo '//' "${TIMESTAMP}"
echo '// Also see https://www.cryptopp.com/wiki/configure.sh'
echo ''
echo '#ifndef CRYPTOPP_CONFIG_CXX_H'
echo '#define CRYPTOPP_CONFIG_CXX_H'
} >> config_cxx.h.new
# Shell redirection
{
echo ''
echo '// ***************** C++98 and C++03 ********************'
echo ''
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx98_exception.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '// Ancient Crypto++ define, dating back to C++98.'
echo '#define CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE 1'
echo '#define CRYPTOPP_CXX98_UNCAUGHT_EXCEPTION 1'
else
echo '// Ancient Crypto++ define, dating back to C++98.'
echo '// #define CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE 1'
echo '// #define CRYPTOPP_CXX98_UNCAUGHT_EXCEPTION 1'
fi
echo ''
echo '// ***************** C++11 and above ********************'
echo ''
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11 1'
else
echo '// test_cxx11.cpp returned non-zero result'
echo '// #define CRYPTOPP_CXX11 1'
fi
echo ''
echo '#if defined(CRYPTOPP_CXX11)'
echo ''
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_atomic.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_ATOMIC 1'
else
echo '// #define CRYPTOPP_CXX11_ATOMIC 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_auto.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_AUTO 1'
else
echo '// #define CRYPTOPP_CXX11_AUTO 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_sync.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_SYNCHRONIZATION 1'
else
echo '// #define CRYPTOPP_CXX11_SYNCHRONIZATION 1'
fi
# CRYPTOPP_CXX11_DYNAMIC_INIT is old name
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_staticinit.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_STATIC_INIT 1'
echo '#define CRYPTOPP_CXX11_DYNAMIC_INIT 1'
else
echo '// #define CRYPTOPP_CXX11_STATIC_INIT 1'
echo '// #define CRYPTOPP_CXX11_DYNAMIC_INIT 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_deletefn.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_DELETED_FUNCTIONS 1'
else
echo '// #define CRYPTOPP_CXX11_DELETED_FUNCTIONS 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_alignas.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_ALIGNAS 1'
else
echo '// #define CRYPTOPP_CXX11_ALIGNAS 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_alignof.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_ALIGNOF 1'
else
echo '// #define CRYPTOPP_CXX11_ALIGNOF 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_initializer.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_INITIALIZER_LIST 1'
else
echo '// #define CRYPTOPP_CXX11_INITIALIZER_LIST 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_lambda.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_LAMBDA 1'
else
echo '// #define CRYPTOPP_CXX11_LAMBDA 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_noexcept.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_NOEXCEPT 1'
else
echo '// #define CRYPTOPP_CXX11_NOEXCEPT 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_vartemplates.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_VARIADIC_TEMPLATES 1'
else
echo '// #define CRYPTOPP_CXX11_VARIADIC_TEMPLATES 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_constexpr.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_CONSTEXPR 1'
else
echo '// #define CRYPTOPP_CXX11_CONSTEXPR 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_enumtype.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_STRONG_ENUM 1'
else
echo '// #define CRYPTOPP_CXX11_STRONG_ENUM 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_nullptr.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_NULLPTR 1'
else
echo '// #define CRYPTOPP_CXX11_NULLPTR 1'
fi
# 2-argument static assert
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx11_assert.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX11_ASSERT 1'
else
echo '// #define CRYPTOPP_CXX11_ASSERT 1'
fi
echo ''
echo '#endif // CRYPTOPP_CXX11'
echo ''
echo '// ***************** C++14 and above ********************'
echo ''
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx14.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX14 1'
else
echo '// test_cxx14.cpp returned non-zero result'
echo '// #define CRYPTOPP_CXX14 1'
fi
echo ''
echo '#if defined(CRYPTOPP_CXX14)'
echo ''
echo '// No dead bodies here. Move on...'
echo ''
echo '#endif // CRYPTOPP_CXX14'
echo ''
echo '// ***************** C++17 and above ********************'
echo ''
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx17.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX17 1'
else
echo '// test_cxx17.cpp returned non-zero result'
echo '// #define CRYPTOPP_CXX17 1'
fi
echo ''
echo '#if defined(CRYPTOPP_CXX17)'
echo ''
# 1-argument static assert
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx17_assert.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX17_ASSERT 1'
else
echo '// #define CRYPTOPP_CXX17_ASSERT 1'
fi
CXX_RESULT=$(${CXX} ${CXXFLAGS} TestPrograms/test_cxx17_exceptions.cpp -o ${TOUT} 2>&1 | wc -w)
if [[ "${CXX_RESULT}" -eq 0 ]]; then
echo '#define CRYPTOPP_CXX17_UNCAUGHT_EXCEPTIONS 1'
else
echo '// #define CRYPTOPP_CXX17_UNCAUGHT_EXCEPTIONS 1'
fi
echo ''
echo '#endif // CRYPTOPP_CXX17'
echo ''
echo '// ***************** C++ fixups ********************'
echo ''
echo '#if defined(CRYPTOPP_CXX11_NOEXCEPT)'
echo '# define CRYPTOPP_THROW noexcept(false)'
echo '# define CRYPTOPP_NO_THROW noexcept(true)'
echo '#else'
echo '# define CRYPTOPP_THROW'
echo '# define CRYPTOPP_NO_THROW'
echo '#endif // CRYPTOPP_CXX11_NOEXCEPT'
echo ''
echo '// C++11 nullptr_t type safety and analysis'
echo '#if defined(CRYPTOPP_CXX11_NULLPTR) && !defined(NULLPTR)'
echo '# define NULLPTR nullptr'
echo '#elif !defined(NULLPTR)'
echo '# define NULLPTR NULL'
echo '#endif // CRYPTOPP_CXX11_NULLPTR'
} >> config_cxx.h.new
# ====================================================
# =================== common footer ==================
# ====================================================
{
echo ''
echo '#endif // CRYPTOPP_CONFIG_CXX_H'
echo ''
} >> config_cxx.h.new
if [[ -e config_cxx.h ]]; then
cp config_cxx.h config_cxx.h.old
mv config_cxx.h.new config_cxx.h
fi
echo 'Done writing config_cxx.h'
rm -f "${TOUT}"
exit 0

View File

@@ -0,0 +1,30 @@
# coverity-linux.txt - Scan build submission instructions for Unix and Linux.
# Written and placed in public domain by Jeffrey Walton and Uri Blumenthal.
# Copyright assigned to Crypto++ project.
#
# The following are copy/paste instructions for invoking cov-build, building the library and submitting the artifacts for a scan.
#
# For more information see http://cryptopp.com/wiki/Coverity_Scan.
##################################################################
reset
make distclean &>/dev/null
# Usually we test with these flags
# CXXFLAGS="-DNDEBUG -g3 -O2"
cov-build --dir cov-int make -j 2
tar czvf cryptopp.tgz cov-int
CRYPTOPP_COVERITY_TOKEN=XXXXXXXXXXXXXXXX
COVERITY_SCAN_NAME="Rijndael-AliasedTable-SSE2-Linux-i686"
curl \
--form token="$CRYPTOPP_COVERITY_TOKEN" \
--form email=webmaster@cryptopp.com \
--form file=@cryptopp.tgz \
--form version="$COVERITY_SCAN_NAME" \
--form description="$COVERITY_SCAN_NAME" \
https://scan.coverity.com/builds?project=Cryptopp

View File

@@ -0,0 +1,36 @@
# coverity-linux.txt - Scan build submission instructions for Unix and Linux.
# Written and placed in public domain by Jeffrey Walton and Uri Blumenthal.
# Copyright assigned to Crypto++ project.
#
# The following are copy/paste instructions for invoking cov-build, building the library and submitting the artifacts for a scan.
#
# For more information see http://cryptopp.com/wiki/Coverity_Scan.
##################################################################
reset
make distclean &>/dev/null
# Usually we test with these flags
CXXFLAGS="-DNDEBUG -g3 -O2" cov-build --dir cov-int make -j 2
# Sometimes we need these flags (add COVERITY_UNSUPPORTED)
# COVERITY_UNSUPPORTED=1 CXXFLAGS="-DNDEBUG -g3 -O2" cov-build --dir cov-int make -j 2
# Sometimes we need these flags (alternate compile, C++11)
# CXX=/opt/local/bin/clang++-mp-3.7 COVERITY_UNSUPPORTED=1 CXXFLAGS="-DNDEBUG -g3 -O2 -std=c++11" cov-build --dir cov-int make -j 2
tar czvf cryptopp.tgz cov-int
CRYPTOPP_COVERITY_TOKEN=XXXXXXXXXXXXXXXX
COVERITY_SCAN_NAME="Cryptopp-MacOSX-x86_64"
curl
--form token="$CRYPTOPP_COVERITY_TOKEN" \
--form email=webmaster@cryptopp.com \
--form file=@cryptopp.tgz \
--form version="$COVERITY_SCAN_NAME" \
--form description="$COVERITY_SCAN_NAME" \
https://scan.coverity.com/builds?project=Cryptopp

View File

@@ -0,0 +1,30 @@
REM coverity-windows.txt - Scan build submission instructions for Windows using cryptest.nmake.
REM Written and placed in public domain by Jeffrey Walton and Uri Blumenthal.
REM Copyright assigned to Crypto++ project.
REM
REM The following are copy/paste instructions for invoking cov-build, building the library and
REM submitting the artifacts for a scan. Also see http://cryptopp.com/wiki/Coverity_Scan.
REM ################################################################
cls
del /f cryptopp.zip
rmdir /q /s cov-int
nmake /f cryptest.nmake clean
REM Uncomment CXXFLAGS in makefile. Pay attention to X86, X64 or ARM
cov-build.exe --dir cov-int nmake /f cryptest.nmake
7z.exe a -r -tzip -mx=9 cryptopp.zip cov-int
set CRYPTOPP_COVERITY_TOKEN=XXXXXXXXXXXXXXXX
set COVERITY_SCAN_NAME=Rijndael-AliasedTable-SSE2-Windows-X64
curl.exe ^
--form token="%CRYPTOPP_COVERITY_TOKEN%" ^
--form email=webmaster@cryptopp.com ^
--form file=@cryptopp.zip ^
--form version="%COVERITY_SCAN_NAME%" ^
--form description="%COVERITY_SCAN_NAME%" ^
https://scan.coverity.com/builds?project=Cryptopp

View File

@@ -0,0 +1,18 @@
REM cryptdll-windows.cmd - written and placed in public domain by Jeffrey Walton
REM Copyright assigned to the Crypto++ project.
REM
REM For details see https://cryptopp.com/wiki/MSBuild_(Command_Line)
REM
REM Build the Win32/Debug cryptest.exe
msbuild /t:Build /p:Configuration=Debug;Platform=Win32 cryptlib.vcxproj
msbuild /t:Build /p:Configuration=Debug;Platform=Win32 cryptest.vcxproj
REM Build the Win32/Release cryptopp.dll
msbuild /t:Build /p:Configuration=Release;Platform=Win32 cryptdll.vcxproj
REM Build the FIPS test driver
msbuild /t:Build /p:Configuration=Release;Platform=Win32 dlltest.vcxproj
REM Run the FIPS test driver
.\Win32\DLL_Output\Release\dlltest.exe

View File

@@ -0,0 +1,125 @@
#!/usr/bin/env bash
#############################################################################
#
# This script tests the cryptopp-android-mk gear using ndk-build. The
# source files include Application.mk and Android.mk.
#
# Written and placed in public domain by Jeffrey Walton and Uri Blumenthal.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
# See http://www.cryptopp.com/wiki/Android.mk_(Command_Line) for more details
#
#############################################################################
# Error checking
if [ ! -d "${ANDROID_NDK_ROOT}" ]; then
echo "ERROR: ANDROID_NDK_ROOT is not a valid path for ${USER}. Please set it."
echo "ANDROID_NDK_ROOT is '${ANDROID_NDK_ROOT}'"
exit 1
fi
# Error checking
if [ ! -d "${ANDROID_SDK_ROOT}" ]; then
echo "ERROR: ANDROID_SDK_ROOT is not a valid path for ${USER}. Please set it."
echo "ANDROID_SDK_ROOT is '${ANDROID_SDK_ROOT}'"
exit 1
fi
# Error checking
if [ -z "$(command -v ndk-build 2>/dev/null)" ]; then
echo "ERROR: ndk-build is not on-path for ${USER}. Please set it."
echo "PATH is '${PATH}'"
exit 1
fi
# Temp directory
if [[ -z "${TMPDIR}" ]]; then
TMPDIR="$HOME/tmp"
mkdir -p "${TMPDIR}"
if [ -n "${SUDO_USER}" ]; then
chown -R "${SUDO_USER}" "${TMPDIR}"
fi
fi
# Sane default
if [[ -z "${MAKE_JOBS}" ]]; then
MAKE_JOBS=4
fi
# Fixup for sed and "illegal byte sequence"
IS_DARWIN=$(uname -s 2>/dev/null | grep -i -c darwin)
if [[ "${IS_DARWIN}" -ne 0 ]] && [[ -z "${LC_ALL}" ]]; then
export LC_ALL=C
fi
# Cleanup old artifacts
rm -rf "${TMPDIR}/build.failed" 2>/dev/null
rm -rf "${TMPDIR}/build.log" 2>/dev/null
#############################################################################
# Prepare the environment
unset CXX CPPFLAGS CXXFLAGS LDFLAGS
unset ANDROID_CPPFLAGS ANDROID_CXXFLAGS ANDROID_LDFLAGS ANDROID_SYSROOT
if [[ -e TestScripts/setenv-android.sh ]]; then
cp TestScripts/setenv-android.sh .
chmod u+x setenv-android.sh
fi
#############################################################################
files=(Android.mk Application.mk test_shared.hxx test_shared.cxx)
for file in "${files[@]}"; do
echo "Downloading $file"
if ! curl -L -s -o "${file}" "https://raw.githubusercontent.com/noloader/cryptopp-android-mk/master/${file}"; then
echo "${file} download failed"
exit 1
fi
# Permissions
chmod u=rw,go=r "${file}"
# Throttle
sleep 1
done
#############################################################################
# Paydirt
NDK_PROJECT_PATH="$PWD"
NDK_APPLICATION_MK="$PWD/Application.mk"
PLATFORMS=(armeabi-v7a arm64-v8a x86 x86_64)
# Clean all past artifacts
ndk-build APP_ABI=all NDK_PROJECT_PATH="${NDK_PROJECT_PATH}" NDK_APPLICATION_MK="${NDK_APPLICATION_MK}" distclean &>/dev/null
for platform in "${PLATFORMS[@]}"
do
echo ""
echo "===================================================================="
echo "Building for ${platform}..."
if ndk-build -j "${MAKE_JOBS}" APP_ABI="${platform}" NDK_PROJECT_PATH="${NDK_PROJECT_PATH}" NDK_APPLICATION_MK="${NDK_APPLICATION_MK}" V=1;
then
echo "${platform} ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
done
echo
echo "===================================================================="
cat "${TMPDIR}/build.log"
# let the script fail if any of the builds failed
if [ -f "${TMPDIR}/build.failed" ]; then
exit 1
fi
exit 0

View File

@@ -0,0 +1,242 @@
#!/usr/bin/env bash
#############################################################################
#
# This script tests Android cross-compiles using setenv-android.sh script.
#
# Written and placed in public domain by Jeffrey Walton and Uri Blumenthal.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
# See http://www.cryptopp.com/wiki/Android_(Command_Line) for more details
#
#############################################################################
# Error checking
if [ -z "$(command -v ./setenv-android.sh 2>/dev/null)" ]; then
echo "Failed to locate setenv-android.sh."
exit 1
fi
# Error checking
if [ ! -d "${ANDROID_NDK_ROOT}" ]; then
echo "ERROR: ANDROID_NDK_ROOT is not a valid path for ${USER}. Please set it."
echo "ANDROID_NDK_ROOT is '${ANDROID_NDK_ROOT}'"
exit 1
fi
# Error checking
if [ ! -d "${ANDROID_SDK_ROOT}" ]; then
echo "ERROR: ANDROID_SDK_ROOT is not a valid path for ${USER}. Please set it."
echo "ANDROID_SDK_ROOT is '${ANDROID_SDK_ROOT}'"
exit 1
fi
# Error checking
if [ -z "$(command -v ndk-build 2>/dev/null)" ]; then
echo "ERROR: ndk-build is not on-path for ${USER}. Please set it."
echo "PATH is '${PATH}'"
exit 1
fi
# Temp directory
if [[ -z "${TMPDIR}" ]]; then
TMPDIR="$HOME/tmp"
mkdir -p "${TMPDIR}"
if [ -n "${SUDO_USER}" ]; then
chown -R "${SUDO_USER}" "${TMPDIR}"
fi
fi
# Sane default
if [[ -z "${MAKE_JOBS}" ]]; then
MAKE_JOBS=4
fi
# Cleanup old artifacts
rm -rf "${TMPDIR}/build.failed" 2>/dev/null
rm -rf "${TMPDIR}/build.log" 2>/dev/null
#############################################################################
# Prepare the environment
unset CXX CPPFLAGS CXXFLAGS LDFLAGS
unset ANDROID_CPPFLAGS ANDROID_CXXFLAGS ANDROID_LDFLAGS ANDROID_SYSROOT
if [[ -e TestScripts/setenv-android.sh ]]; then
cp TestScripts/setenv-android.sh .
chmod u+x setenv-android.sh
fi
#############################################################################
PLATFORMS=(armv7a aarch64 x86 x86_64)
for platform in "${PLATFORMS[@]}"
do
# setenv-android.sh reads these two variables for configuration info.
# Android 5.0 is 21. Android 6.0 is 23.
export ANDROID_API="23"
export ANDROID_CPU="${platform}"
make -f GNUmakefile-cross distclean > /dev/null 2>&1
echo
echo "===================================================================="
echo "Testing for Android support of ${platform}"
# Test if we can set the environment for the platform
if ! ./setenv-android.sh > /dev/null 2>&1;
then
echo
echo "There were problems testing ${platform}"
echo "${platform} ==> SKIPPED" >> "${TMPDIR}/build.log"
continue
fi
echo
echo "===================================================================="
echo "Building for ${platform}..."
# run in subshell to not keep any envars
(
source ./setenv-android.sh
if make -k -j "${MAKE_JOBS}" -f GNUmakefile-cross static dynamic cryptest.exe;
then
echo "${platform} ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test code generation
if [[ "${platform}" == "armv7a" ]]
then
# Test NEON code generation
# In the past we looked for the vector loads, stores and shifts using vld and friends.
# It looks like objdump changed its output format on Android after Clang, so we need
# to check for statements like eor v0.16b, v2.16b, v0.16b nowadays.
count=$(${OBJDUMP} --disassemble chacha_simd.o 2>&1 | grep -c -E 'vld|vst|vshl|vshr|veor|v0\.|v1\.|v2\.|v3\.|v4\.|v5\.|v6\.|v7\.')
if [[ "${count}" -gt 64 ]]
then
echo "${platform} : NEON ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : NEON ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
elif [[ "${platform}" == "aarch64" ]]
then
# Test ASIMD code generation
# In the past we looked for the vector loads, stores and shifts using vld and friends.
# It looks like objdump changed its output format on Android after Clang, so we need
# to check for statements like eor v0.16b, v2.16b, v0.16b nowadays.
count=$(${OBJDUMP} --disassemble chacha_simd.o 2>&1 | grep -c -E 'vld|vst|vshl|vshr|veor|v0\.|v1\.|v2\.|v3\.|v4\.|v5\.|v6\.|v7\.')
if [[ "${count}" -gt 64 ]]
then
echo "${platform} : ASIMD ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : ASIMD ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test AES code generation
count=$(${OBJDUMP} --disassemble rijndael_simd.o 2>&1 | grep -c -E 'aese|aesd|aesmc|aesimc')
if [[ "${count}" -gt 32 ]]
then
echo "${platform} : AES ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : AES ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test PMULL code generation
count=$(${OBJDUMP} --disassemble gcm_simd.o 2>&1 | grep -c -E 'pmull|pmull2')
if [[ "${count}" -gt 16 ]]
then
echo "${platform} : PMULL ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : PMULL ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test SHA1 code generation
count=$(${OBJDUMP} --disassemble sha_simd.o 2>&1 | grep -c -E 'sha1c|sha1m|sha1p|sha1h|sha1su0|sha1su1')
if [[ "${count}" -gt 32 ]]
then
echo "${platform} : SHA1 ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : SHA1 ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test SHA2 code generation
count=$(${OBJDUMP} --disassemble sha_simd.o | grep -c -E 'sha256h|sha256su0|sha256su1')
if [[ "${count}" -gt 32 ]]
then
echo "${platform} : SHA2 ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : SHA2 ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
elif [[ "${platform}" == "x86" || "${platform}" == "x86_64" ]]
then
# Test AES code generation
count=$(${OBJDUMP} --disassemble rijndael_simd.o 2>&1 | grep -c -E 'aesenc|aesdec|aesenclast|aesdeclast|aesimc')
if [[ "${count}" -gt 32 ]]
then
echo "${platform} : AES ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : AES ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test CLMUL code generation
count=$(${OBJDUMP} --disassemble gcm_simd.o 2>&1 | grep -c -E 'pclmulqdq|pclmullqlq|pclmullqhq|vpclmulqdq')
if [[ "${count}" -gt 16 ]]
then
echo "${platform} : CLMUL ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : CLMUL ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test SHA1 code generation
count=$(${OBJDUMP} --disassemble sha_simd.o 2>&1 | grep -c -E 'sha1rnds4|sha1nexte|sha1msg1|sha1msg2')
if [[ "${count}" -gt 32 ]]
then
echo "${platform} : SHA1 ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : SHA1 ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test SHA2 code generation
count=$(${OBJDUMP} --disassemble sha_simd.o | grep -c -E 'sha256rnds2|sha256msg1|sha256msg2')
if [[ "${count}" -gt 32 ]]
then
echo "${platform} : SHA2 ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : SHA2 ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
fi
)
done
echo
echo "====================================================="
cat "${TMPDIR}/build.log"
# let the script fail if any of the builds failed
if [ -f "${TMPDIR}/build.failed" ]; then
exit 1
fi
exit 0

View File

@@ -0,0 +1,147 @@
#!/usr/bin/env bash
#############################################################################
#
# This script tests the Autotools gear.
#
# Written and placed in public domain by Jeffrey Walton.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
# See https://www.cryptopp.com/wiki/Autotools for more details
#
#############################################################################
if ! command -v wget >/dev/null 2>&1; then
if ! command -v curl >/dev/null 2>&1; then
echo "wget and curl not found. Things will fail"
exit 1
fi
fi
#############################################################################
# Default tools
GREP=grep
SED=sed
AWK=awk
MAKE=make
# Fixup, Solaris and friends
if [ -d /usr/xpg4/bin ]; then
SED=/usr/xpg4/bin/sed
AWK=/usr/xpg4/bin/awk
GREP=/usr/xpg4/bin/grep
elif [ -d /usr/bin/posix ]; then
SED=/usr/bin/posix/sed
AWK=/usr/bin/posix/awk
GREP=/usr/bin/posix/grep
fi
if command -v wget >/dev/null 2>&1; then
FETCH_CMD="wget -q -O"
elif command -v curl >/dev/null 2>&1; then
FETCH_CMD="curl -L -s -o"
else
FETCH_CMD="curl-and-wget-not-found"
fi
# Fixup for sed and "illegal byte sequence"
IS_DARWIN=`uname -s 2>&1 | "$GREP" -i -c darwin`
if [ "$IS_DARWIN" -ne 0 ]; then
LC_ALL=C; export LC_ALL
fi
# Fixup for Solaris and BSDs
if [ command -v gmake >/dev/null 2>&1 ]; then
MAKE=gmake
fi
#############################################################################
files=(bootstrap.sh configure.ac Makefile.am libcryptopp.pc.in)
for file in "${files[@]}"; do
echo "Downloading $file"
if ! ${FETCH_CMD} "$file" "https://raw.githubusercontent.com/noloader/cryptopp-autotools/master/$file"; then
echo "$file download failed"
exit 1
fi
if file "$file" | $GREP -q 'executable'; then
chmod +x "$file"
fi
# Throttle
sleep 1
done
if [ "$IS_DARWIN" -ne 0 ] && [ command -v xattr >/dev/null 2>&1 ]; then
echo "Removing bootstrap.sh quarantine"
xattr -d "com.apple.quarantine" bootstrap.sh >/dev/null 2>&1
fi
#############################################################################
echo "Running bootstrap"
echo ""
if ! ./bootstrap.sh; then
echo "bootstrap failed."
exit 1
fi
#############################################################################
echo "Running configure"
echo ""
if ! ./configure; then
echo "configure failed."
exit 1
fi
#############################################################################
echo ""
echo "Building test artifacts"
echo ""
${MAKE} clean >/dev/null 2>&1
if ! ${MAKE} -j2 -f Makefile; then
echo "make failed."
exit 1
fi
#############################################################################
echo ""
echo "Testing library"
echo ""
if ! ./cryptest v; then
echo "cryptest v failed."
exit 1
fi
if ! ./cryptest tv all; then
echo "cryptest tv all failed."
exit 1
fi
#############################################################################
echo ""
echo "Building tarball"
echo ""
if ! make dist; then
echo "make dist failed."
exit 1
fi
# Return success
exit 0

View File

@@ -0,0 +1,149 @@
#!/usr/bin/env bash
if ! command -v gcov > /dev/null; then
echo "Please install gcov"
exit 1
fi
if ! command -v lcov > /dev/null; then
echo "Please install lcov"
exit 1
fi
# Default make jobs
MAKE_JOBS=${MAKE_JOBS:-4}
# Default temp directory
if [ -z "${TMPDIR}" ];
then
if [ -d "${HOME}/tmp" ]; then
TMPDIR="${HOME}/tmp"
else
TMPDIR="/tmp"
fi
fi
DEBUG_CXXFLAGS="-DDEBUG -DCRYPTOPP_COVERAGE=1 -g3 -O1 -coverage"
NOASM_CXXFLAGS="-DNDEBUG -DCRYPTOPP_DISABLE_ASM -DCRYPTOPP_COVERAGE=1 -g3 -O1 -coverage"
RELEASE_CXXFLAGS="-DNDEBUG -DCRYPTOPP_COVERAGE=1 -g3 -O1 -coverage"
# Clean old artifacts
rm -rf TestCoverage/ >/dev/null
make distclean >/dev/null
echo "**************************************************"
echo "***** Baseline build *****"
echo "**************************************************"
# The man page says to run a baseline, but the cryptest_base recipe
# breaks things. Zeroing the counters seems to be the best we can do.
if lcov --base-directory . --directory . --zerocounters;
then
echo
echo "Baseline zero counters ok"
echo
else
echo
echo "Baseline zero counters failed"
echo
fi
#make clean > /dev/null
#if ! make -j "${MAKE_JOBS}";
#then
# echo "Baseline build failed"
# exit 1
#fi
# Run test programs
#./cryptest.exe v
#./cryptest.exe tv all
# Create a baseline
#lcov --base-directory . --directory . -i -c -o cryptest_base.info
echo "**************************************************"
echo "***** Debug build *****"
echo "**************************************************"
make clean > /dev/null
if ! CXXFLAGS="${DEBUG_CXXFLAGS}" make -j "${MAKE_JOBS}";
then
echo "Debug build failed"
exit 1
fi
# Run test programs
./cryptest.exe v
./cryptest.exe tv all
# Gather data
lcov --base-directory . --directory . -c -o cryptest_debug.info
echo "**************************************************"
echo "***** No ASM build *****"
echo "**************************************************"
make clean > /dev/null
if ! CXXFLAGS="${NOASM_CXXFLAGS}" make -j "${MAKE_JOBS}";
then
echo "No ASM build failed"
exit 1
fi
# Run test programs
./cryptest.exe v
./cryptest.exe tv all
# Gather data
lcov --base-directory . --directory . -c -o cryptest_noasm.info
echo "**************************************************"
echo "***** Release build *****"
echo "**************************************************"
make clean > /dev/null
if ! CXXFLAGS="${RELEASE_CXXFLAGS}" make -j "${MAKE_JOBS}";
then
echo "Release build failed"
exit 1
fi
# Run test programs
./cryptest.exe v
./cryptest.exe tv all
./cryptest.exe b 0.5
# Gather data
lcov --base-directory . --directory . -c -o cryptest_release.info
echo "**************************************************"
echo "***** HTML processing *****"
echo "**************************************************"
if [ ! -e cryptest_debug.info ]; then
echo "WARN: cryptest_debug.info does not exist"
fi
if [ ! -e cryptest_noasm.info ]; then
echo "WARN: cryptest_noasm.info does not exist"
fi
if [ ! -e cryptest_release.info ]; then
echo "WARN: cryptest_release.info does not exist"
fi
# The man page says to run a baseline, but the cryptest_base recipe
# breaks things. Zeroing the counters seems to be the best we can do.
# --add-tracefile cryptest_base.info
lcov --add-tracefile cryptest_debug.info \
--add-tracefile cryptest_noasm.info \
--add-tracefile cryptest_release.info \
--output-file cryptest_all.info
lcov --remove cryptest_all.info \
'/usr/*' '*/adhoc*.*' '*/dlltest*.*' '*/fipstest*.*' '*/fips140*.*' '*/test*.*' \
--output-file cryptest.info
genhtml -o TestCoverage/ -t "Crypto++ test coverage" --num-spaces 4 cryptest.info
exit 0

View File

@@ -0,0 +1,12 @@
// cryptest-coverity.cpp - Coverity modeling file.
// Written and placed in public domain by Jeffrey Walton and Uri Blumenthal.
//
// For more information see http://cryptopp.com/wiki/Coverity_Scan.
//
// Also see https://scan.coverity.com/tune#what-is-model
///////////////////////////////////////////////////////////////////
void special_abort(const char* msg) {
__coverity_panic__();
}

View File

@@ -0,0 +1,186 @@
#!/usr/bin/env bash
#############################################################################
#
# This script tests the cryptopp-ios gear.
#
# Written and placed in public domain by Jeffrey Walton and Uri Blumenthal.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
# See http://www.cryptopp.com/wiki/iOS_(Command_Line) for more details
#############################################################################
if [ -z "$(command -v ./setenv-ios.sh)" ]; then
echo "Failed to locate setenv-ios.sh"
exit 1
fi
# Temp directory
if [[ -z "${TMPDIR}" ]]; then
TMPDIR="$HOME/tmp"
mkdir "${TMPDIR}"
fi
# Sane default
if [[ -z "${MAKE_JOBS}" ]]; then
MAKE_JOBS=4
fi
# Cleanup old artifacts
rm -rf "${TMPDIR}/build.failed" 2>/dev/null
rm -rf "${TMPDIR}/build.log" 2>/dev/null
#############################################################################
# Prepare the environment
unset CXX CPPFLAGS CXXFLAGS LDFLAGS
unset IOS_CPPFLAGS IOS_CXXFLAGS IOS_LDFLAGS IOS_SYSROOT
if [[ -e TestScripts/setenv-ios.sh ]]; then
cp TestScripts/setenv-ios.sh .
chmod u+x setenv-ios.sh
fi
#############################################################################
# Hack a Bash data structure...
PLATFORMS=()
PLATFORMS+=("iPhoneOS:armv7")
PLATFORMS+=("iPhoneOS:arm64")
PLATFORMS+=("AppleTVOS:armv7")
PLATFORMS+=("AppleTVOS:arm64")
PLATFORMS+=("WatchOS:armv7")
PLATFORMS+=("WatchOS:arm64")
PLATFORMS+=("WatchOS:arm64_32")
PLATFORMS+=("iPhoneSimulator:i386")
PLATFORMS+=("iPhoneSimulator:x86_64")
PLATFORMS+=("AppleTVSimulator:i386")
PLATFORMS+=("AppleTVSimulator:x86_64")
PLATFORMS+=("WatchSimulator:i386")
PLATFORMS+=("WatchSimulator:x86_64")
for platform in "${PLATFORMS[@]}"
do
sdk=$(echo "${platform[@]}" | awk -F':' '{print $1}')
cpu=$(echo "${platform[@]}" | awk -F':' '{print $2}')
# setenv-ios.sh reads these two variables for configuration info.
export IOS_SDK="$sdk"
export IOS_CPU="$cpu"
make -f GNUmakefile-cross distclean > /dev/null 2>&1
echo
echo "====================================================="
echo "Testing for iOS support of ${platform}"
# Test if we can set the environment for the platform
if ! ./setenv-ios.sh > /dev/null 2>&1;
then
echo
echo "${platform} not supported by Xcode"
echo "${platform} ==> SKIPPED" >> "${TMPDIR}/build.log"
continue
fi
echo
echo "====================================================="
echo "Building for ${platform}..."
# run in subshell to not keep any envars
(
source ./setenv-ios.sh
if make -k -j "${MAKE_JOBS}" -f GNUmakefile-cross static dynamic cryptest.exe;
then
echo "${platform} ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test code generation
if [[ "${cpu}" == "armv7" ]]
then
# Test NEON code generation
count=$(otool -tV chacha_simd.o 2>&1 | grep -c -E 'vld|vst|vshl|vshr|veor')
if [[ "${count}" -gt 64 ]]
then
echo "${platform} : NEON ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : NEON ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
elif [[ "${cpu}" == "arm64" ]]
then
# Test ASIMD code generation
count=$(otool -tV chacha_simd.o 2>&1 | grep -c -E 'ldr[[:space:]]*q|str[[:space:]]*q|shl.4|shr.4|eor.16')
if [[ "${count}" -gt 64 ]]
then
echo "${platform} : ASIMD ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : ASIMD ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test AES code generation
count=$(otool -tV rijndael_simd.o 2>&1 | grep -c -E 'aese|aesd|aesmc|aesimc')
if [[ "${count}" -gt 32 ]]
then
echo "${platform} : AES ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : AES ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test PMULL code generation
count=$(otool -tV gcm_simd.o 2>&1 | grep -c -E 'pmull|pmull2')
if [[ "${count}" -gt 16 ]]
then
echo "${platform} : PMULL ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : PMULL ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test SHA1 code generation
count=$(otool -tV sha_simd.o 2>&1 | grep -c -E 'sha1c|sha1m|sha1p|sha1h|sha1su0|sha1su1')
if [[ "${count}" -gt 32 ]]
then
echo "${platform} : SHA1 ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : SHA1 ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
# Test SHA2 code generation
count=$(otool -tV sha_simd.o | grep -c -E 'sha256h|sha256su0|sha256su1')
if [[ "${count}" -gt 32 ]]
then
echo "${platform} : SHA2 ==> SUCCESS" >> "${TMPDIR}/build.log"
else
echo "${platform} : SHA2 ==> FAILURE" >> "${TMPDIR}/build.log"
touch "${TMPDIR}/build.failed"
fi
fi
)
done
echo
echo "====================================================="
cat "${TMPDIR}/build.log"
# let the script fail if any of the builds failed
if [ -f "${TMPDIR}/build.failed" ]; then
exit 1
fi
exit 0

View File

@@ -0,0 +1,111 @@
#!/usr/bin/env bash
#############################################################################
#
# This script tests the cryptopp-pem gear.
#
# Written and placed in public domain by Jeffrey Walton.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
#############################################################################
GREP=grep
SED=sed
AWK=awk
MAKE=make
# Fixup, Solaris and friends
if [[ (-d /usr/xpg4/bin) ]]; then
SED=/usr/xpg4/bin/sed
AWK=/usr/xpg4/bin/awk
GREP=/usr/xpg4/bin/grep
elif [[ (-d /usr/bin/posix) ]]; then
SED=/usr/bin/posix/sed
AWK=/usr/bin/posix/awk
GREP=/usr/bin/posix/grep
fi
# Fixup for sed and "illegal byte sequence"
IS_DARWIN=$(uname -s | "$GREP" -i -c darwin)
if [[ "$IS_DARWIN" -ne 0 ]]; then
export LC_ALL=C
fi
# Fixup for Solaris and BSDs
if command -v gmake 2>/dev/null; then
MAKE=gmake
else
MAKE=make
fi
#############################################################################
if ! command -v "${MAKE}" 2>/dev/null; then
echo "Cannot find $MAKE. Things may fail."
fi
if ! command -v curl 2>/dev/null; then
echo "Cannot find cURL. Things may fail."
fi
if ! command -v openssl 2>/dev/null; then
echo "Cannot find openssl. Things may fail."
fi
#############################################################################
files=(pem_create.sh pem_verify.sh pem_test.cxx pem_eol.cxx
pem.h pem_common.cpp pem_common.h pem_read.cpp pem_write.cpp
x509cert.h x509cert.cpp)
for file in "${files[@]}"; do
echo "Downloading $file"
if ! curl -L -s -o "$file" "https://raw.githubusercontent.com/noloader/cryptopp-pem/master/$file"; then
echo "$file download failed"
exit 1
fi
# Throttle
sleep 1
done
# Add execute to scripts
chmod +x *.sh
if [[ "$IS_DARWIN" -ne 0 ]] && [[ -n $(command -v xattr) ]]; then
echo "Removing pem_create.sh pem_verify.sh quarantine"
xattr -d "com.apple.quarantine" pem_create.sh pem_verify.sh &>/dev/null
fi
#############################################################################
echo ""
echo "Building test artifacts"
echo ""
"$MAKE" clean &>/dev/null
if ! "$MAKE" -j 2; then
echo "make failed."
exit 1
fi
if ! ./cryptest.exe v; then
echo "cryptest v failed."
exit 1
fi
if ! ./pem_create.sh; then
echo "pem_create.sh failed."
exit 1
fi
if ! ./pem_verify.sh; then
echo "pem_verify.sh failed."
exit 1
fi
# Return success
exit 0

View File

@@ -0,0 +1,224 @@
#!/usr/bin/env bash
#############################################################################
#
# This is a test script that can be used on some Linux/Unix/Apple machines to
# automate testing of the shared object to ensure linking and symbols don't go
# missing from release to release.
#
# Written and placed in public domain by Jeffrey Walton and Uri Blumenthal.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
#############################################################################
#############################################################################
# Tags to test
OLD_VERSION_TAG=CRYPTOPP_8_3_0
NEW_VERSION_TAG=master
#############################################################################
# If local repo is dirty, then prompt first
DIRTY=$(git diff --shortstat 2> /dev/null | tail -1)
if [[ ! -z "$DIRTY" ]]; then
echo
echo "The local repo is dirty. Continuing will reset the repo and lose changes."
read -p "Type 'Y' to proceed or 'N' to exit. Proceed? " -n 1 -r
echo # (optional) move to a new line
if [[ !($REPLY =~ ^[Yy]$) ]]; then
exit 0
fi
else
echo
echo "The local repo is clean. Proceeding..."
fi
#############################################################################
echo
echo "****************************************************************"
echo "Testing '$NEW_VERSION_TAG' against '$OLD_VERSION_TAG'"
echo "****************************************************************"
#############################################################################
# Setup tools and platforms
GREP=grep
EGREP=egrep
SED=sed
AWK=awk
CXXFILT=c++filt
THIS_SYSTEM=$(uname -s 2>&1)
IS_DARWIN=$("${GREP}" -i -c darwin <<< "${THIS_SYSTEM}")
IS_LINUX=$("${GREP}" -i -c linux <<< "${THIS_SYSTEM}")
IS_CYGWIN=$("${GREP}" -i -c cygwin <<< "${THIS_SYSTEM}")
IS_MINGW=$("${GREP}" -i -c mingw <<< "${THIS_SYSTEM}")
IS_OPENBSD=$("${GREP}" -i -c openbsd <<< "${THIS_SYSTEM}")
IS_FREEBSD=$("${GREP}" -i -c freebsd <<< "${THIS_SYSTEM}")
IS_NETBSD=$("${GREP}" -i -c netbsd <<< "${THIS_SYSTEM}")
IS_SOLARIS=$("${GREP}" -i -c sunos <<< "${THIS_SYSTEM}")
THIS_MACHINE=$(uname -m 2>&1)
IS_X86=$("${EGREP}" -i -c 'i386|i486|i586|i686' <<< "${THIS_MACHINE}")
IS_X64=$("${EGREP}" -i -c "amd64|x86_64" <<< "${THIS_MACHINE}")
IS_PPC32=$("${EGREP}" -i -c "PowerPC|PPC" <<< "${THIS_MACHINE}")
IS_PPC64=$("${EGREP}" -i -c "PowerPC64|PPC64" <<< "${THIS_MACHINE}")
IS_ARM32=$("${EGREP}" -i -c "arm|aarch32" <<< "${THIS_MACHINE}")
IS_ARMV8=$("${EGREP}" -i -c "arm64|aarch64" <<< "${THIS_MACHINE}")
IS_S390=$("${EGREP}" -i -c "s390" <<< "${THIS_MACHINE}")
if [[ "${IS_X64}" -eq 1 ]]; then IS_X86=0; fi
if [[ "${IS_ARMV8}" -eq 1 ]]; then IS_ARM32=0; fi
if [[ "${IS_PPC64}" -eq 1 ]]; then IS_PPC32=0; fi
# Fixup
if [[ "$IS_FREEBSD" -ne "0" || "$IS_OPENBSD" -ne "0" || "$IS_NETBSD" -ne "0" ]]; then
MAKE=gmake
elif [[ "$IS_SOLARIS" -ne "0" ]]; then
MAKE=$(command -v gmake 2>/dev/null | "${GREP}" -v "no gmake" | head -1)
if [[ -z "$MAKE" && -e "/usr/sfw/bin/gmake" ]]; then
MAKE=/usr/sfw/bin/gmake
fi
else
MAKE=make
fi
if [[ "$IS_DARWIN" -ne "0" ]]; then
LINK_LIBRARY=libcryptopp.dylib
else
LINK_LIBRARY=libcryptopp.so
fi
if [[ -z "${CXX}" ]]; then CXX=c++; fi
SUN_COMPILER=$("${CXX}" -V 2>&1 | "${EGREP}" -i -c "CC: (Sun|Studio)")
GCC_COMPILER=$("${CXX}" --version 2>&1 | "${EGREP}" -i -c "^(gcc|g\+\+)")
INTEL_COMPILER=$("${CXX}" --version 2>&1 | "${GREP}" -i -c "icc")
MACPORTS_COMPILER=$("${CXX}" --version 2>&1 | "${GREP}" -i -c "MacPorts")
CLANG_COMPILER=$("${CXX}" --version 2>&1 | "${GREP}" -i -c "clang")
#############################################################################
# CPU is logical count, memory is in MiB. Low resource boards have
# fewer than 4 cores and 1GB or less memory. We use this to
# determine if we can build in parallel without an OOM kill.
CPU_COUNT=1
MEM_SIZE=512
if [[ -e "/proc/cpuinfo" && -e "/proc/meminfo" ]]; then
CPU_COUNT=$(cat /proc/cpuinfo | "${GREP}" -c '^processor')
MEM_SIZE=$(cat /proc/meminfo | "${GREP}" "MemTotal" | "${AWK}" '{print $2}')
MEM_SIZE=$(($MEM_SIZE/1024))
elif [[ "$IS_DARWIN" -ne "0" ]]; then
CPU_COUNT=$(sysctl -a 2>&1 | "${GREP}" 'hw.availcpu' | "${AWK}" '{print $3; exit}')
MEM_SIZE=$(sysctl -a 2>&1 | "${GREP}" 'hw.memsize' | "${AWK}" '{print $3; exit;}')
MEM_SIZE=$(($MEM_SIZE/1024/1024))
elif [[ "$IS_SOLARIS" -ne "0" ]]; then
CPU_COUNT=$(psrinfo 2>/dev/null | wc -l | "${AWK}" '{print $1}')
MEM_SIZE=$(prtconf 2>/dev/null | "${GREP}" Memory | "${AWK}" '{print $3}')
fi
# Some ARM devboards cannot use 'make -j N', even with multiple cores and RAM
# An 8-core Cubietruck Plus with 2GB RAM experiences OOM kills with '-j 2'.
HAVE_SWAP=1
if [[ "$IS_LINUX" -ne "0" ]]; then
if [[ -e "/proc/meminfo" ]]; then
SWAP_SIZE=$(cat /proc/meminfo | "${GREP}" "SwapTotal" | "${AWK}" '{print $2}')
if [[ "$SWAP_SIZE" -eq "0" ]]; then
HAVE_SWAP=0
fi
else
HAVE_SWAP=0
fi
fi
if [[ "$CPU_COUNT" -ge "2" && "$MEM_SIZE" -ge "1280" && "$HAVE_SWAP" -ne "0" ]]; then
MAKEARGS=(-j "$CPU_COUNT")
fi
#############################################################################
#############################################################################
"${MAKE}" distclean &>/dev/null && cleanup &>/dev/null
git checkout master -f &>/dev/null
git checkout "$OLD_VERSION_TAG" -f &>/dev/null
if [[ "$?" -ne "0" ]]; then
echo "Failed to checkout $OLD_VERSION_TAG"
exit 1
fi
echo
echo "****************************************************************"
echo "Building dynamic library for $OLD_VERSION_TAG"
echo "****************************************************************"
echo
LINK_LIBRARY="$LINK_LIBRARY" "$MAKE" "${MAKEARGS[@]}" -f GNUmakefile cryptest.exe dynamic
if [[ ! -f "$LINK_LIBRARY" ]]; then
echo "Failed to make $OLD_VERSION_TAG library"
exit 1
fi
echo
echo "****************************************************************"
echo "Running $OLD_VERSION_TAG cryptest.exe using $OLD_VERSION_TAG library"
echo "****************************************************************"
echo
if [[ "$IS_DARWIN" -ne "0" ]]; then
DYLD_LIBRARY_PATH="$PWD:$DYLD_LIBRARY_PATH" ./cryptest.exe v 2>&1 | "$CXXFILT"
DYLD_LIBRARY_PATH="$PWD:$DYLD_LIBRARY_PATH" ./cryptest.exe tv all 2>&1 | "$CXXFILT"
else
LD_LIBRARY_PATH="$PWD:$LD_LIBRARY_PATH" ./cryptest.exe v 2>&1 | "$CXXFILT"
LD_LIBRARY_PATH="$PWD:$LD_LIBRARY_PATH" ./cryptest.exe tv all 2>&1 | "$CXXFILT"
fi
# Stash away old cryptest.exe
cp cryptest.exe cryptest.exe.saved
echo
echo "****************************************************************"
echo "Building dynamic library for $NEW_VERSION_TAG"
echo "****************************************************************"
echo
"${MAKE}" distclean &>/dev/null && cleanup &>/dev/null
git checkout master -f &>/dev/null
git checkout "$NEW_VERSION_TAG" -f &>/dev/null
LINK_LIBRARY="$LINK_LIBRARY" "$MAKE" "${MAKEARGS[@]}" -f GNUmakefile cryptest.exe dynamic
if [[ ! -f "$LINK_LIBRARY" ]]; then
echo "Failed to make $NEW_VERSION_TAG library"
exit 1
fi
# Fetch old cryptest.exe
cp cryptest.exe.saved cryptest.exe
echo
echo "****************************************************************"
echo "Running $OLD_VERSION_TAG cryptest.exe using $NEW_VERSION_TAG library"
echo "****************************************************************"
echo
if [[ "$IS_DARWIN" -ne "0" ]]; then
DYLD_LIBRARY_PATH="$PWD:$DYLD_LIBRARY_PATH" ./cryptest.exe v 2>&1 | "$CXXFILT"
DYLD_LIBRARY_PATH="$PWD:$DYLD_LIBRARY_PATH" ./cryptest.exe tv all 2>&1 | "$CXXFILT"
else
LD_LIBRARY_PATH="$PWD:$LD_LIBRARY_PATH" ./cryptest.exe v 2>&1 | "$CXXFILT"
LD_LIBRARY_PATH="$PWD:$LD_LIBRARY_PATH" ./cryptest.exe tv all 2>&1 | "$CXXFILT"
fi
"${MAKE}" distclean &>/dev/null && cleanup &>/dev/null
git checkout master -f &>/dev/null
exit 0

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
#############################################################################
#
# This script invokes clang-tidy on source files.
#
# Written and placed in public domain by Jeffrey Walton.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
#############################################################################
for file in $(find . -maxdepth 1 -type f -name '*.cpp'); do
echo "Tidying $file"
clang-tidy $file -checks=-clang-analyzer-optin.cplusplus.VirtualCall -- -std=c++03
done

8120
externals/cryptopp/TestScripts/cryptest.sh vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,47 @@
#include <iostream>
// Compile with:
// g++ cryptopp-compiler.cpp -o cryptopp-compiler.exe
// Or:
// cl.exe /EHs cryptopp-compiler.cpp /Fe:cryptopp-compiler.exe
int main(int argc, char* argv[])
{
#if defined (_MSC_VER)
std::cout << "_MSC_VER is defined" << std::endl;
#else
std::cout << "_MSC_VER is not defined" << std::endl;
#endif
#if defined (__GNUC__)
std::cout << "__GNUC__ is defined" << std::endl;
#else
std::cout << "__GNUC__ is not defined" << std::endl;
#endif
#if defined (__clang__)
std::cout << "__clang__ is defined" << std::endl;
#else
std::cout << "__clang__ is not defined" << std::endl;
#endif
#if defined (__INTEL_COMPILER)
std::cout << "__INTEL_COMPILER is defined" << std::endl;
#else
std::cout << "__INTEL_COMPILER is not defined" << std::endl;
#endif
#if defined (__xlC__)
std::cout << "__xlC__ is defined" << std::endl;
#else
std::cout << "__xlC__ is not defined" << std::endl;
#endif
#if defined (__SUNPRO_CC)
std::cout << "__SUNPRO_CC is defined" << std::endl;
#else
std::cout << "__SUNPRO_CC is not defined" << std::endl;
#endif
return 0;
}

View File

@@ -0,0 +1,79 @@
#!/usr/bin/env bash
#############################################################################
#
# This scripts queries and modifies CPU scaling frequencies to produce more
# accurate benchmark results. To move from a low power state to a higher
# one, run 'governor.sh performance'. To move back to a low power state
# run 'governor.sh powersave' or 'governor.sh ondemand' or reboot.
#
# Written and placed in public domain by Jeffrey Walton. The script based on
# code by Andy Polyakov, http://www.openssl.org/~appro/cryptogams/.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
# See https://www.cryptopp.com/wiki/Benchmarks for more details
#
#############################################################################
# Fixup ancient Bash
# https://unix.stackexchange.com/q/468579/56041
if [[ -z "${BASH_SOURCE[0]}" ]]; then
BASH_SOURCE="$0"
fi
if [[ "$EUID" -ne 0 ]]; then
echo "This script must be run as root"
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi
if [ "x$1" = "x" ]; then
echo "usage: $0 on[demand]|pe[rformance]|po[wersave]|us[erspace]?"
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi
# "on demand" may result in a "invalid write argument" or similar
case $1 in
on*|de*) governor="ondemand";;
po*|pw*) governor="powersave";;
pe*) governor="performance";;
co*) governor="conservative";;
us*) governor="userspace";;
\?) ;;
*) echo "$1: unrecognized governor";;
esac
if [ -z "$governor" ]; then
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi
cpus=$(ls /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor 2>/dev/null)
if [ -z "$cpus" ]; then
echo "Failed to read CPU system device tree"
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
fi
echo "Current CPU governor scaling settings:"
count=0
for cpu in $cpus; do
echo " CPU $count: $(cat "$cpu")"
((count++))
done
if [ "x$governor" != "x" ]; then
for cpu in $cpus; do
echo "$governor" > "$cpu"
done
fi
echo "New CPU governor scaling settings:"
count=0
for cpu in $cpus; do
echo " CPU $count: $(cat "$cpu")"
((count++))
done
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 0 || return 0

View File

@@ -0,0 +1,207 @@
#!/usr/bin/env bash
#############################################################################
# Tests Android cross-compiles
#
# This script installs a SDK and NDK to test Android cross-compiles.
#
# Written and placed in public domain by Jeffrey Walton
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
# See http://www.cryptopp.com/wiki/Android_(Command_Line) for more details
#############################################################################
# NDK-r19: https://dl.google.com/android/repository/android-ndk-r19c-linux-x86_64.zip
# SDK for r19: https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip
# SDK for Mac: https://dl.google.com/android/repository/sdk-tools-mac-4333796.zip
# NDK-r20: https://dl.google.com/android/repository/android-ndk-r20b-linux-x86_64.zip
# SDK for r20: https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip
# SDK for Mac: https://dl.google.com/android/repository/commandlinetools-mac-6200805_latest.zip
# NDK-r21: https://dl.google.com/android/repository/android-ndk-r21-linux-x86_64.zip
# SDK for r21: https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip
# SDK for Mac: https://dl.google.com/android/repository/commandlinetools-mac-6200805_latest.zip
# NDK-r22: https://dl.google.com/android/repository/android-ndk-r22-linux-x86_64.zip
# SDK for r22: https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip
# SDK for Mac: https://dl.google.com/android/repository/commandlinetools-mac-6858069_latest.zip
# Platform tools
# Linux: https://dl.google.com/android/repository/platform-tools-latest-linux.zip
# Mac: https://dl.google.com/android/repository/platform-tools-latest-darwin.zip
# Windows: https://dl.google.com/android/repository/platform-tools-latest-windows.zip
function cleanup {
# Cleanup downloads
rm -f android-sdk.zip android-ndk.zip platform-tools.zip
}
trap cleanup EXIT
if [ -z "${ANDROID_SDK_ROOT}" ]; then
echo "ERROR: ANDROID_SDK_ROOT is not set for ${USER}. Please set it."
exit 1
fi
if [ -z "${ANDROID_NDK_ROOT}" ]; then
echo "ERROR: ANDROID_NDK_ROOT is not set for ${USER}. Please set it."
exit 1
fi
# Temp directory
if [[ -z "${TMPDIR}" ]]; then
TMPDIR="$HOME/tmp"
mkdir -p "${TMPDIR}"
if [ -n "${SUDO_USER}" ]; then
chown -R "${SUDO_USER}" "${TMPDIR}"
fi
fi
# Install Android deps
if [[ -z "$(command -v java 2>/dev/null)" && -n "$(command -v apt-get 2>/dev/null)" ]]; then
apt-get -qq update 2>/dev/null || true
apt-get -qq install --no-install-recommends unzip curl wget 2>/dev/null || true
if [[ -n "$(apt-cache search openjdk-13-jdk 2>/dev/null | head -n 1)" ]]; then
apt-get -qq install --no-install-recommends openjdk-13-jdk 2>/dev/null || true
elif [[ -n "$(apt-cache search openjdk-8-jdk 2>/dev/null | head -n 1)" ]]; then
apt-get -qq install --no-install-recommends openjdk-8-jdk 2>/dev/null || true
fi
elif [[ -z "$(command -v java 2>/dev/null)" && -n "$(command -v dnf 2>/dev/null)" ]]; then
dnf update 2>/dev/null || true
dnf install unzip curl wget 2>/dev/null || true
if [[ -n "$(dnf search java-latest-openjdk-devel 2>/dev/null | head -n 1)" ]]; then
dnf install java-latest-openjdk-devel 2>/dev/null || true
elif [[ -n "$(dnf search java-11-openjdk-devel 2>/dev/null | head -n 1)" ]]; then
dnf install java-11-openjdk-devel 2>/dev/null || true
fi
elif [[ -z "$(command -v java 2>/dev/null)" && -n "$(command -v yum 2>/dev/null)" ]]; then
yum update 2>/dev/null || true
yum install unzip curl wget 2>/dev/null || true
if [[ -n "$(yum search java-latest-openjdk-devel 2>/dev/null | head -n 1)" ]]; then
yum install java-latest-openjdk-devel 2>/dev/null || true
elif [[ -n "$(yum search java-11-openjdk-devel 2>/dev/null | head -n 1)" ]]; then
yum install java-11-openjdk-devel 2>/dev/null || true
fi
fi
# User feedback
#echo "ANDROID_NDK_ROOT is '${ANDROID_NDK_ROOT}'"
#echo "ANDROID_SDK_ROOT is '${ANDROID_SDK_ROOT}'"
IS_DARWIN=$(uname -s 2>/dev/null | grep -i -c darwin)
IS_LINUX=$(uname -s 2>/dev/null | grep -i -c linux)
# Change NDK_NAME as required
NDK_NAME=android-ndk-r20b
NDK_TOP=$(dirname "${ANDROID_NDK_ROOT}")
# Keep this in sync with the move at the end.
if [ "$IS_LINUX" -eq 1 ]; then
NDK_URL=https://dl.google.com/android/repository/${NDK_NAME}-linux-x86_64.zip
SDK_URL=https://dl.google.com/android/repository/commandlinetools-linux-6200805_latest.zip
TOOLS_URL=https://dl.google.com/android/repository/platform-tools-latest-linux.zip
elif [ "$IS_DARWIN" -eq 1 ]; then
NDK_URL=https://dl.google.com/android/repository/${NDK_NAME}-darwin-x86_64.zip
SDK_URL=https://dl.google.com/android/repository/commandlinetools-mac-6200805_latest.zip
TOOLS_URL=https://dl.google.com/android/repository/platform-tools-latest-darwin.zip
else
echo "Unknown platform: \"$(uname -s 2>/dev/null)\". Please fix this script."
fi
echo "Downloading SDK"
if ! curl -L -s -o android-sdk.zip "${SDK_URL}";
then
echo "Failed to download SDK"
exit 1
fi
echo "Downloading NDK"
if ! curl -L -s -o android-ndk.zip "${NDK_URL}";
then
echo "Failed to download NDK"
exit 1
fi
echo "Downloading Platform Tools"
if ! curl -L -s -o platform-tools.zip "${TOOLS_URL}";
then
echo "Failed to download Platform Tools"
exit 1
fi
# Android SDK does not include a top level directory
echo "Unpacking SDK to ${ANDROID_SDK_ROOT}"
if ! unzip -u -qq android-sdk.zip -d "${ANDROID_SDK_ROOT}";
then
echo "Failed to unpack SDK"
exit 1
fi
# Android NDK includes top level NDK_NAME directory
echo "Unpacking NDK to ${NDK_TOP}/${NDK_NAME}"
if ! unzip -u -qq android-ndk.zip -d "${NDK_TOP}";
then
echo "Failed to unpack NDK"
exit 1
fi
echo "Unpacking Platform Tools to ${ANDROID_SDK_ROOT}"
if ! unzip -u -qq platform-tools.zip -d "${ANDROID_SDK_ROOT}";
then
echo "Failed to unpack Platform Tools"
exit 1
fi
# Unlink as needed
if [[ -e "${ANDROID_NDK_ROOT}" ]]; then
ls_output=$(ls -l "${ANDROID_NDK_ROOT}" 2>/dev/null | head -n 1)
# Only remove soft links
if [[ ${ls_output:0:1} == "l" ]]; then
unlink "${ANDROID_NDK_ROOT}"
fi
fi
# Create softlink
(
echo "Symlinking ${NDK_NAME} to android-ndk"
cd ${NDK_TOP} || exit 1
if ! ln -s "${NDK_NAME}" android-ndk; then
echo "Failed to link ${NDK_NAME} to android-ndk"
fi
)
# We don't set ANDROID_HOME to ANDROID_SDK_ROOT.
# https://stackoverflow.com/a/47028911/608639
touch "${ANDROID_SDK_ROOT}/repositories.cfg"
# And https://stackoverflow.com/q/43433542
mkdir -p "${HOME}/.android"
touch "${HOME}/.android/repositories.cfg"
if [[ -n "${SUDO_USER}" ]]; then
chown -R "${SUDO_USER}" "${HOME}/.android"
fi
count=$(ls -1 "${ANDROID_SDK_ROOT}" 2>/dev/null | wc -l)
if [[ "${count}" -lt 2 ]]; then
echo "ANDROID_SDK_ROOT appears empty. The contents are listed."
echo "$(ls "${ANDROID_SDK_ROOT}")"
exit 1
fi
count=$(ls -1 "${ANDROID_NDK_ROOT}" 2>/dev/null | wc -l)
if [[ "${count}" -lt 2 ]]; then
echo "ANDROID_NDK_ROOT appears empty. The contents are listed."
echo "$(ls "${ANDROID_NDK_ROOT}")"
exit 1
fi
echo "Finished installing SDK and NDK"
exit 0

View File

@@ -0,0 +1,173 @@
#!/usr/bin/env bash
#############################################################################
#
# The following builds the benchmarks under 5.6.2, 5.6.4 and Master. The
# results can then be compared to ensure an speed penalty is not inadvertently
# taken. Crypto++ 5.6.2 is significant because its the last version Wei worked
# on before turning the library over to the community.
#
# Written and placed in public domain by Jeffrey Walton.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
# See https://www.cryptopp.com/wiki/Benchmarks for more details
#
#############################################################################
# Set to suite your taste. Speed is in GiHz
if [[ -z "$CPU_FREQ" ]]; then
if [[ ! -z "CRYPTOPP_CPU_SPEED" ]]; then
CPU_FREQ="$CRYPTOPP_CPU_SPEED"
else
CPU_FREQ=2.8
fi
fi
echo "***************************************************"
echo "Using CPU frequency of $CPU_FREQ GiHz."
echo "Please modify this script if its not correct"
echo
#############################################################################
current=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
git fetch --all &>/dev/null &>/dev/null
if [[ "$?" -ne "0" ]]; then
echo "$PWD does not appear to be a Git repository"
exit 1
fi
#############################################################################
# Try to find a fast option
OPT=
if [[ -z "$OPT" ]]; then
rm -f "$TMP/adhoc.exe" &>/dev/null
"$CXX" -DCRYPTOPP_ADHOC_MAIN -O3 adhoc.cpp -o "$TMP/adhoc.exe" &>/dev/null
if [[ ("$?" -eq "0") ]]; then
OPT=-O3
fi
fi
if [[ -z "$OPT" ]]; then
rm -f "$TMP/adhoc.exe" &>/dev/null
"$CXX" -DCRYPTOPP_ADHOC_MAIN -xO3 adhoc.cpp -o "$TMP/adhoc.exe" &>/dev/null
if [[ ("$?" -eq "0") ]]; then
OPT=-xO3
fi
fi
if [[ -z "$OPT" ]]; then
rm -f "$TMP/adhoc.exe" &>/dev/null
"$CXX" -DCRYPTOPP_ADHOC_MAIN -O2 adhoc.cpp -o "$TMP/adhoc.exe" &>/dev/null
if [[ ("$?" -eq "0") ]]; then
OPT=-O2
fi
fi
if [[ -z "$OPT" ]]; then
rm -f "$TMP/adhoc.exe" &>/dev/null
"$CXX" -DCRYPTOPP_ADHOC_MAIN -xO2 adhoc.cpp -o "$TMP/adhoc.exe" &>/dev/null
if [[ ("$?" -eq "0") ]]; then
OPT=-xO2
fi
fi
if [[ -z "$OPT" ]]; then
rm -f "$TMP/adhoc.exe" &>/dev/null
"$CXX" -DCRYPTOPP_ADHOC_MAIN -O adhoc.cpp -o "$TMP/adhoc.exe" &>/dev/null
if [[ ("$?" -eq "0") ]]; then
OPT=-O
fi
fi
#############################################################################
echo "***************************************************"
echo "**************** Crypto++ 5.6.2 *******************"
echo "***************************************************"
echo
git checkout -f CRYPTOPP_5_6_2 &>/dev/null
if [[ "$?" -ne "0" ]]; then
echo "git checkout CRYPTOPP_5_6_2 failed"
else
rm -f *.o benchmarks.html benchmarks-562.html &>/dev/null
CXXFLAGS="-DNDEBUG $OPT" make
if [[ "$?" -eq "0" ]]; then
echo "Running benchmarks for Crypto++ 5.6.2"
./cryptest.exe b 3 "$CPU_FREQ" > benchmarks-562.html
if [[ "$?" -ne "0" ]]; then
rm -rf benchmarks-562.html &>/dev/null
echo "Failed to create benchmarks for Crypto++ 5.6.2"
fi
else
echo "Failed to make benchmarks for Crypto++ 5.6.2"
fi
fi
#############################################################################
echo "***************************************************"
echo "**************** Crypto++ 5.6.4 *******************"
echo "***************************************************"
echo
git checkout -f CRYPTOPP_5_6_4 &>/dev/null
if [[ "$?" -ne "0" ]]; then
echo "git checkout CRYPTOPP_5_6_4 failed"
else
rm -f *.o benchmarks.html benchmarks-564.html &>/dev/null
CXXFLAGS="-DNDEBUG $OPT" make
if [[ "$?" -eq "0" ]]; then
echo "Running benchmarks for Crypto++ 5.6.4"
./cryptest.exe b 3 "$CPU_FREQ" > benchmarks-564.html
if [[ "$?" -ne "0" ]]; then
rm -rf benchmarks-564.html &>/dev/null
echo "Failed to create benchmarks for Crypto++ 5.6.4"
fi
else
echo "Failed to make benchmarks for Crypto++ 5.6.4"
fi
fi
#############################################################################
echo "***************************************************"
echo "*************** Crypto++ Master *******************"
echo "***************************************************"
echo
git checkout -f master &>/dev/null
if [[ "$?" -ne "0" ]]; then
echo "git checkout master failed"
else
rm -f *.o benchmarks.html benchmarks-master.html &>/dev/null
CXXFLAGS="-DNDEBUG $OPT" make
if [[ "$?" -eq "0" ]]; then
echo "Running benchmarks for Crypto++ Master"
./cryptest.exe b 3 "$CPU_FREQ" > benchmarks-master.html
if [[ "$?" -ne "0" ]]; then
rm -rf benchmarks-master.html &>/dev/null
echo "Failed to create benchmarks for Crypto++ Master"
fi
else
echo "Failed to make benchmarks for Crypto++ Master"
fi
fi
#############################################################################
if [[ ! -z "$current" ]]; then
git checkout -f "$current"
fi
exit 0

View File

@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# Use this script to reset a fork to Wei Dai's master
# https://stackoverflow.com/questions/9646167/clean-up-a-fork-and-restart-it-from-the-upstream
#
# Written and placed in public domain by Jeffrey Walton
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
git remote add upstream https://github.com/weidai11/cryptopp 2>/dev/null
git fetch upstream
git checkout master
git reset --hard upstream/master
git push origin master --force

View File

@@ -0,0 +1,574 @@
#!/usr/bin/env bash
#############################################################################
#
# This script sets the cross-compile environment for Android.
#
# Based upon OpenSSL's setenv-android.sh by TH, JW, and SM.
# Heavily modified by JWW for Crypto++.
# Modified by Skycoder42 Android NDK-r19 and above.
# Modified some more by JW and UB.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
# Also see:
# https://android.googlesource.com/platform/ndk.git/+/HEAD/docs/UnifiedHeaders.md
# https://android.googlesource.com/platform/ndk/+/master/docs/PlatformApis.md
# https://developer.android.com/ndk/guides/abis.html and
# https://developer.android.com/ndk/guides/cpp-support.
#
# See http://www.cryptopp.com/wiki/Android_(Command_Line) for more details
#############################################################################
#########################################
##### Some validation #####
#########################################
# cryptest-android.sh may run this script without sourcing.
if [ "$0" = "${BASH_SOURCE[0]}" ]; then
echo "setenv-android.sh is usually sourced, but not this time."
fi
# This supports both 'source setenv-android.sh 21 arm64' and
# 'source setenv-android.sh ANDROID_API=21 ANDROID_CPU=arm64'
if [[ -n "$1" ]]
then
arg1=$(echo "$1" | cut -f 1 -d '=')
arg2=$(echo "$1" | cut -f 2 -d '=')
if [[ -n "${arg2}" ]]; then
ANDROID_API="${arg2}"
else
ANDROID_API="${arg1}"
fi
printf "Using positional arg, ANDROID_API=%s\n" "${ANDROID_API}"
fi
# This supports both 'source setenv-android.sh 21 arm64' and
# 'source setenv-android.sh ANDROID_API=21 ANDROID_CPU=arm64'
if [[ -n "$2" ]]
then
arg1=$(echo "$2" | cut -f 1 -d '=')
arg2=$(echo "$2" | cut -f 2 -d '=')
if [[ -n "${arg2}" ]]; then
ANDROID_CPU="${arg2}"
else
ANDROID_CPU="${arg1}"
fi
printf "Using positional arg, ANDROID_CPU=%s\n" "${ANDROID_CPU}"
fi
if [ -z "${ANDROID_API}" ]; then
echo "ANDROID_API is not set. Please set it"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [ -z "${ANDROID_CPU}" ]; then
echo "ANDROID_CPU is not set. Please set it"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
DEF_CPPFLAGS="-DNDEBUG"
DEF_CFLAGS="-Wall -g2 -O3 -fPIC"
DEF_CXXFLAGS="-Wall -g2 -O3 -fPIC"
DEF_ASFLAGS=
DEF_LDFLAGS=""
#########################################
##### Clear old options #####
#########################################
unset IS_IOS
unset IS_MACOS
unset IS_ANDROID
unset IS_ARM_EMBEDDED
unset ANDROID_CPPFLAGS
unset ANDROID_CFLAGS
unset ANDROID_CXXFLAGS
unset ANDROID_ASFLAGS
unset ANDROID_LDFLAGS
unset ANDROID_SYSROOT
#########################################
##### Small Fixups, if needed #####
#########################################
ANDROID_CPU=$(tr '[:upper:]' '[:lower:]' <<< "${ANDROID_CPU}")
if [[ "${ANDROID_CPU}" == "amd64" || "${ANDROID_CPU}" == "x86_64" ]] ; then
ANDROID_CPU=x86_64
fi
if [[ "${ANDROID_CPU}" == "i386" || "${ANDROID_CPU}" == "i686" ]] ; then
ANDROID_CPU=i686
fi
if [[ "${ANDROID_CPU}" == "armv7"* || "${ANDROID_CPU}" == "armeabi"* ]] ; then
ANDROID_CPU=armeabi-v7a
fi
if [[ "${ANDROID_CPU}" == "aarch64" || "${ANDROID_CPU}" == "arm64"* || "${ANDROID_CPU}" == "armv8"* ]] ; then
ANDROID_CPU=arm64-v8a
fi
# Debug
# echo "Configuring for ${ANDROID_API} (${ANDROID_CPU})"
########################################
##### Environment #####
########################################
# ANDROID_NDK_ROOT should always be set by the user (even when not running this script)
# http://groups.google.com/group/android-ndk/browse_thread/thread/a998e139aca71d77.
# If the user did not specify the NDK location, try and pick it up. Something like
# ANDROID_NDK_ROOT=/opt/android-ndk-r19c or ANDROID_NDK_ROOT=/usr/local/android-ndk-r20.
if [ -n "${ANDROID_NDK_ROOT}" ]; then
echo "ANDROID_NDK_ROOT is ${ANDROID_NDK_ROOT}"
else
echo "ANDROID_NDK_ROOT is empty. Searching for the NDK"
ANDROID_NDK_ROOT=$(find /opt -maxdepth 1 -type d -name "android-ndk*" 2>/dev/null | tail -n -1)
if [ -z "${ANDROID_NDK_ROOT}" ]; then
ANDROID_NDK_ROOT=$(find /usr/local -maxdepth 1 -type d -name "android-ndk*" 2>/dev/null | tail -n -1)
fi
if [ -z "${ANDROID_NDK_ROOT}" ]; then
ANDROID_NDK_ROOT=$(find "$HOME" -maxdepth 1 -type d -name "android-ndk*" 2>/dev/null | tail -n -1)
fi
if [ -d "$HOME/Library/Android/sdk/ndk-bundle" ]; then
ANDROID_NDK_ROOT="$HOME/Library/Android/sdk/ndk-bundle"
fi
fi
# Error checking
if [ ! -d "${ANDROID_NDK_ROOT}" ]; then
echo "ERROR: ANDROID_NDK_ROOT is not a valid path for ${USER}. Please set it."
echo "ANDROID_NDK_ROOT is '${ANDROID_NDK_ROOT}'"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -d "${ANDROID_SDK_ROOT}" ]; then
echo "ERROR: ANDROID_SDK_ROOT is not a valid path for ${USER}. Please set it."
echo "ANDROID_SDK_ROOT is '${ANDROID_SDK_ROOT}'"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# User feedback
#echo "ANDROID_NDK_ROOT is '${ANDROID_NDK_ROOT}'"
#echo "ANDROID_SDK_ROOT is '${ANDROID_SDK_ROOT}'"
#####################################################################
# Need to set HOST_TAG to darwin-x86_64, linux-x86_64,
# windows, or windows-x86_64
if [[ "$(uname -s | grep -i -c darwin)" -ne 0 ]]; then
HOST_TAG=darwin-x86_64
elif [[ "$(uname -s | grep -i -c linux)" -ne 0 ]]; then
HOST_TAG=linux-x86_64
else
echo "ERROR: Unknown host"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
ANDROID_TOOLCHAIN="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${HOST_TAG}/bin"
ANDROID_SYSROOT="${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/${HOST_TAG}/sysroot"
# Error checking
if [ ! -d "${ANDROID_TOOLCHAIN}" ]; then
echo "ERROR: ANDROID_TOOLCHAIN is not a valid path. Please set it."
echo "ANDROID_TOOLCHAIN is '${ANDROID_TOOLCHAIN}'"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -d "${ANDROID_SYSROOT}" ]; then
echo "ERROR: ANDROID_SYSROOT is not a valid path. Please set it."
echo "ANDROID_SYSROOT is '${ANDROID_SYSROOT}'"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
#####################################################################
# https://developer.android.com/ndk/guides/abis.html and
# https://developer.android.com/ndk/guides/cpp-support.
# Since NDK r16 the only STL available is libc++, so we
# add -std=c++11 -stdlib=libc++ to CXXFLAGS. This is
# consistent with Android.mk and 'APP_STL := c++_shared'.
case "${ANDROID_CPU}" in
armv7*|armeabi*)
CC="armv7a-linux-androideabi${ANDROID_API}-clang"
CXX="armv7a-linux-androideabi${ANDROID_API}-clang++"
LD="arm-linux-androideabi-ld"
AS="arm-linux-androideabi-as"
AR="arm-linux-androideabi-ar"
NM="arm-linux-androideabi-nm"
RANLIB="arm-linux-androideabi-ranlib"
STRIP="arm-linux-androideabi-strip"
OBJDUMP="arm-linux-androideabi-objdump"
# https://github.com/weidai11/cryptopp/pull/1119
if [ -n "${ANDROID_LD}" ]; then
if [ "$LD" != "ld.lld" ]; then
LD="arm-linux-androideabi-${ANDROID_LD}"
fi
elif [ "${ANDROID_API}" -ge 22 ]; then
# New default linker
# https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r22/docs/BuildSystemMaintainers.md#Linkers
LD="ld.lld"
elif [ "${ANDROID_API}" -ge 19 ]; then
# New default linker. BFD used on all excpet aarch64; Gold used on aarch64
# https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r19/docs/BuildSystemMaintainers.md#Linkers
LD="arm-linux-androideabi-ld.bfd"
fi
# As of NDK r22, there are new names for some tools.
# https://developer.android.com/ndk/guides/other_build_systems
if [ "${ANDROID_API}" -ge 22 ]; then
AR="llvm-ar"
AS="llvm-as"
NM="llvm-nm"
OBJDUMP="llvm-objdump"
RANLIB="llvm-ranlib"
STRIP="llvm-strip"
fi
# You may need this on older NDKs
# ANDROID_CPPFLAGS="-D__ANDROID__=${ANDROID_API}"
# Android NDK r19 and r20 no longer use -mfloat-abi=softfp. Add it as required.
ANDROID_CFLAGS="-target armv7-none-linux-androideabi${ANDROID_API}"
ANDROID_CFLAGS="${ANDROID_CFLAGS} -march=armv7-a -mthumb"
ANDROID_CFLAGS="${ANDROID_CFLAGS} -fstack-protector-strong -funwind-tables -fexceptions -frtti"
ANDROID_CFLAGS="${ANDROID_CFLAGS} -fno-addrsig -fno-experimental-isel"
ANDROID_CXXFLAGS="-target armv7-none-linux-androideabi${ANDROID_API}"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -march=armv7-a -mthumb"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -std=c++11 -stdlib=libc++"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fstack-protector-strong -funwind-tables -fexceptions -frtti"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fno-addrsig -fno-experimental-isel"
;;
armv8*|aarch64|arm64*)
CC="aarch64-linux-android${ANDROID_API}-clang"
CXX="aarch64-linux-android${ANDROID_API}-clang++"
LD="aarch64-linux-android-ld"
AS="aarch64-linux-android-as"
AR="aarch64-linux-android-ar"
NM="aarch64-linux-android-nm"
RANLIB="aarch64-linux-android-ranlib"
STRIP="aarch64-linux-android-strip"
OBJDUMP="aarch64-linux-android-objdump"
# https://github.com/weidai11/cryptopp/pull/1119
if [ -n "${ANDROID_LD}" ]; then
if [ "$LD" != "ld.lld" ]; then
LD="aarch64-linux-android-${ANDROID_LD}"
fi
elif [ "${ANDROID_API}" -ge 22 ]; then
# New default linker
# https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r22/docs/BuildSystemMaintainers.md#Linkers
LD="ld.lld"
elif [ "${ANDROID_API}" -ge 19 ]; then
# New default linker. BFD used on all excpet aarch64; Gold used on aarch64
# https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r19/docs/BuildSystemMaintainers.md#Linkers
LD="aarch64-linux-android-ld.gold"
fi
# As of NDK r22, there are new names for some tools.
# https://developer.android.com/ndk/guides/other_build_systems
if [ "${ANDROID_API}" -ge 22 ]; then
AR="llvm-ar"
AS="llvm-as"
NM="llvm-nm"
OBJDUMP="llvm-objdump"
RANLIB="llvm-ranlib"
STRIP="llvm-strip"
fi
# You may need this on older NDKs
# ANDROID_CPPFLAGS="-D__ANDROID__=${ANDROID_API}"
ANDROID_CFLAGS="-target aarch64-none-linux-android${ANDROID_API}"
ANDROID_CFLAGS="${ANDROID_CFLAGS} -fstack-protector-strong -funwind-tables -fexceptions -frtti"
ANDROID_CFLAGS="${ANDROID_CFLAGS} -fno-addrsig -fno-experimental-isel"
ANDROID_CXXFLAGS="-target aarch64-none-linux-android${ANDROID_API}"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -std=c++11 -stdlib=libc++"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fstack-protector-strong -funwind-tables -fexceptions -frtti"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fno-addrsig -fno-experimental-isel"
;;
i686|x86)
CC="i686-linux-android${ANDROID_API}-clang"
CXX="i686-linux-android${ANDROID_API}-clang++"
LD="i686-linux-android-ld"
AS="i686-linux-android-as"
AR="i686-linux-android-ar"
NM="i686-linux-android-nm"
RANLIB="i686-linux-android-ranlib"
STRIP="i686-linux-android-strip"
OBJDUMP="i686-linux-android-objdump"
# https://github.com/weidai11/cryptopp/pull/1119
if [ -n "${ANDROID_LD}" ]; then
if [ "$LD" != "ld.lld" ]; then
LD="i686-linux-android-${ANDROID_LD}"
fi
elif [ "${ANDROID_API}" -ge 22 ]; then
# New default linker
# https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r22/docs/BuildSystemMaintainers.md#Linkers
LD="ld.lld"
elif [ "${ANDROID_API}" -ge 19 ]; then
# New default linker. BFD used on all excpet aarch64; Gold used on aarch64
# https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r19/docs/BuildSystemMaintainers.md#Linkers
LD="i686-linux-android-ld.bfd"
fi
# As of NDK r22, there are new names for some tools.
# https://developer.android.com/ndk/guides/other_build_systems
if [ "${ANDROID_API}" -ge 22 ]; then
AR="llvm-ar"
AS="llvm-as"
NM="llvm-nm"
OBJDUMP="llvm-objdump"
RANLIB="llvm-ranlib"
STRIP="llvm-strip"
fi
# You may need this on older NDKs
# ANDROID_CPPFLAGS="-D__ANDROID__=${ANDROID_API}"
# Newer NDK's choke on -mtune=intel, so omit it
ANDROID_CFLAGS="-target i686-none-linux-android${ANDROID_API}"
ANDROID_CFLAGS="${ANDROID_CFLAGS} -mssse3 -mfpmath=sse"
ANDROID_CFLAGS="${ANDROID_CFLAGS} -fstack-protector-strong -funwind-tables -fexceptions -frtti"
ANDROID_CFLAGS="${ANDROID_CFLAGS} -fno-addrsig -fno-experimental-isel"
ANDROID_CXXFLAGS="-target i686-none-linux-android${ANDROID_API}"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -mssse3 -mfpmath=sse"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -std=c++11 -stdlib=libc++"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fstack-protector-strong -funwind-tables -fexceptions -frtti"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fno-addrsig -fno-experimental-isel"
;;
x86_64|x64)
CC="x86_64-linux-android${ANDROID_API}-clang"
CXX="x86_64-linux-android${ANDROID_API}-clang++"
LD="x86_64-linux-android-ld"
AS="x86_64-linux-android-as"
AR="x86_64-linux-android-ar"
NM="x86_64-linux-android-nm"
RANLIB="x86_64-linux-android-ranlib"
STRIP="x86_64-linux-android-strip"
OBJDUMP="x86_64-linux-android-objdump"
# https://github.com/weidai11/cryptopp/pull/1119
if [ -n "${ANDROID_LD}" ]; then
if [ "$LD" != "ld.lld" ]; then
LD="x86_64-linux-android-${ANDROID_LD}"
fi
elif [ "${ANDROID_API}" -ge 22 ]; then
# New default linker
# https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r22/docs/BuildSystemMaintainers.md#Linkers
LD="ld.lld"
elif [ "${ANDROID_API}" -ge 19 ]; then
# New default linker. BFD used on all excpet aarch64; Gold used on aarch64
# https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r19/docs/BuildSystemMaintainers.md#Linkers
LD="x86_64-linux-android-ld.bfd"
fi
# As of NDK r22, there are new names for some tools.
# https://developer.android.com/ndk/guides/other_build_systems
if [ "${ANDROID_API}" -ge 22 ]; then
AR="llvm-ar"
AS="llvm-as"
NM="llvm-nm"
OBJDUMP="llvm-objdump"
RANLIB="llvm-ranlib"
STRIP="llvm-strip"
fi
# You may need this on older NDKs
# ANDROID_CPPFLAGS="-D__ANDROID__=${ANDROID_API}"
# Newer NDK's choke on -mtune=intel, so omit it
ANDROID_CFLAGS="-target x86_64-none-linux-android${ANDROID_API}"
ANDROID_CFLAGS="${ANDROID_CFLAGS} -march=x86-64 -msse4.2 -mpopcnt"
ANDROID_CFLAGS="${ANDROID_CFLAGS} -fstack-protector-strong -funwind-tables -fexceptions -frtti"
ANDROID_CFLAGS="${ANDROID_CFLAGS} -fno-addrsig -fno-experimental-isel"
ANDROID_CXXFLAGS="-target x86_64-none-linux-android${ANDROID_API}"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -march=x86-64 -msse4.2 -mpopcnt"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -std=c++11 -stdlib=libc++"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fstack-protector-strong -funwind-tables -fexceptions -frtti"
ANDROID_CXXFLAGS="${ANDROID_CXXFLAGS} -fno-addrsig -fno-experimental-isel"
;;
*)
echo "ERROR: Unknown architecture ${ANDROID_CPU}"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
;;
esac
echo "Configuring for Android API ${ANDROID_API} on ${ANDROID_CPU}"
#####################################################################
# Common to all builds
ANDROID_CPPFLAGS="${DEF_CPPFLAGS} ${ANDROID_CPPFLAGS} -DANDROID"
ANDROID_ASFLAGS="${DEF_ASFLAGS} -Wa,--noexecstack"
ANDROID_CFLAGS="${DEF_CFLAGS} ${ANDROID_CFLAGS}"
ANDROID_CXXFLAGS="${DEF_CXXFLAGS} ${ANDROID_CXXFLAGS} -Wa,--noexecstack"
ANDROID_LDFLAGS="${DEF_LDFLAGS}"
# Aarch64 ld does not understand --warn-execstack
ANDROID_LDFLAGS="${ANDROID_LDFLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now"
ANDROID_LDFLAGS="${ANDROID_LDFLAGS} -Wl,--warn-shared-textrel -Wl,--warn-common"
ANDROID_LDFLAGS="${ANDROID_LDFLAGS} -Wl,--warn-unresolved-symbols"
ANDROID_LDFLAGS="${ANDROID_LDFLAGS} -Wl,--gc-sections -Wl,--fatal-warnings"
#####################################################################
# Error checking
if [ ! -e "${ANDROID_TOOLCHAIN}/$CC" ]; then
echo "ERROR: Failed to find Android clang. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${ANDROID_TOOLCHAIN}/$CXX" ]; then
echo "ERROR: Failed to find Android clang++. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${ANDROID_TOOLCHAIN}/$RANLIB" ]; then
echo "ERROR: Failed to find Android ranlib. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${ANDROID_TOOLCHAIN}/$AR" ]; then
echo "ERROR: Failed to find Android ar. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${ANDROID_TOOLCHAIN}/$AS" ]; then
echo "ERROR: Failed to find Android as. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking. lld location is <NDK>/toolchains/llvm/prebuilt/<host-tag>/bin/ld.lld
# https://android.googlesource.com/platform/ndk/+/refs/heads/ndk-release-r21/docs/BuildSystemMaintainers.md#Linkers
if [ "$LD" != "ld.lld" ] && [ ! -e "${ANDROID_TOOLCHAIN}/$LD" ]; then
echo "ERROR: Failed to find Android ld. Please edit this script. When using NDK 22 or higher make sure to set ANDROID_LD! (bfd, gold)"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
#####################################################################
# Add tools to head of path, if not present already
LENGTH=${#ANDROID_TOOLCHAIN}
SUBSTR=${PATH:0:$LENGTH}
if [ "$SUBSTR" != "${ANDROID_TOOLCHAIN}" ]; then
export PATH="${ANDROID_TOOLCHAIN}:$PATH"
fi
#####################################################################
# Now that we are using cpu-features from Android rather than
# CPU probing, we need to copy cpu-features.h and cpu-features.c
# from the NDK into our source directory and then build it.
if [[ ! -e "${ANDROID_NDK_ROOT}/sources/android/cpufeatures/cpu-features.h" ]]; then
echo "ERROR: Unable to locate cpu-features.h"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [[ ! -e "${ANDROID_NDK_ROOT}/sources/android/cpufeatures/cpu-features.c" ]]; then
echo "ERROR: Unable to locate cpu-features.c"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
cp "${ANDROID_NDK_ROOT}/sources/android/cpufeatures/cpu-features.h" .
cp "${ANDROID_NDK_ROOT}/sources/android/cpufeatures/cpu-features.c" .
# Cleanup the sources for the C++ compiler
# https://github.com/weidai11/cryptopp/issues/926
sed -e 's/= memmem/= (const char*)memmem/g' \
-e 's/= memchr/= (const char*)memchr/g' \
-e 's/= malloc/= (char*)malloc/g' \
cpu-features.c > cpu-features.c.fixed
mv cpu-features.c.fixed cpu-features.c
# Fix permissions. For some reason cpu-features.h is +x.
chmod u=rw,go=r cpu-features.h cpu-features.c
#####################################################################
VERBOSE=${VERBOSE:-1}
if [ "$VERBOSE" -gt 0 ]; then
echo "ANDROID_TOOLCHAIN: ${ANDROID_TOOLCHAIN}"
echo "ANDROID_API: ${ANDROID_API}"
echo "ANDROID_CPU: ${ANDROID_CPU}"
if [ -n "${ANDROID_CPPFLAGS}" ]; then
echo "ANDROID_CPPFLAGS: ${ANDROID_CPPFLAGS}"
fi
echo "ANDROID_CFLAGS: ${ANDROID_CFLAGS}"
echo "ANDROID_CXXFLAGS: ${ANDROID_CXXFLAGS}"
if [ -n "${ANDROID_ASFLAGS}" ]; then
echo "ANDROID_ASFLAGS: ${ANDROID_ASFLAGS}"
fi
if [ -n "${ANDROID_LDFLAGS}" ]; then
echo "ANDROID_LDFLAGS: ${ANDROID_LDFLAGS}"
fi
echo "ANDROID_SYSROOT: ${ANDROID_SYSROOT}"
if [ -e "cpu-features.h" ] && [ -e "cpu-features.c" ]; then
echo "CPU FEATURES: cpu-features.h and cpu-features.c are present"
fi
fi
#####################################################################
# GNUmakefile-cross and Autotools expect these to be set.
# Note: prior to Crypto++ 8.6, CPPFLAGS, CXXFLAGS and LDFLAGS were not
# exported. At Crypto++ 8.6 CPPFLAGS, CXXFLAGS and LDFLAGS were exported.
export IS_ANDROID=1
export CPP CC CXX LD AS AR NM OBJDUMP RANLIB STRIP
# Do NOT use ANDROID_SYSROOT_INC or ANDROID_SYSROOT_LD
# https://github.com/android/ndk/issues/894#issuecomment-470837964
CPPFLAGS="${ANDROID_CPPFLAGS} -isysroot ${ANDROID_SYSROOT}"
CFLAGS="${ANDROID_CFLAGS}"
CXXFLAGS="${ANDROID_CXXFLAGS}"
ASFLAGS="${ANDROID_ASFLAGS}"
LDFLAGS="${ANDROID_LDFLAGS} --sysroot ${ANDROID_SYSROOT}"
# Trim whitespace as needed
CPPFLAGS=$(echo "${CPPFLAGS}" | awk '{$1=$1;print}')
CFLAGS=$(echo "${CFLAGS}" | awk '{$1=$1;print}')
CXXFLAGS=$(echo "${CXXFLAGS}" | awk '{$1=$1;print}')
ASFLAGS=$(echo "${ASFLAGS}" | awk '{$1=$1;print}')
LDFLAGS=$(echo "${LDFLAGS}" | awk '{$1=$1;print}')
export CPPFLAGS CFLAGS CXXFLAGS ASFLAGS LDFLAGS
#####################################################################
echo
echo "*******************************************************************************"
echo "It looks the the environment is set correctly. Your next step is build"
echo "the library with 'make -f GNUmakefile-cross'."
echo "*******************************************************************************"
echo
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0

View File

@@ -0,0 +1,184 @@
#!/usr/bin/env bash
#############################################################################
#
# This script sets the cross-compile environment for ARM embedded.
#
# Based upon OpenSSL's setenv-android.sh by TH, JW, and SM.
# Heavily modified by JWW for Crypto++.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
# See http://www.cryptopp.com/wiki/ARM_Embedded_(Command_Line) for details.
#############################################################################
# cryptest-embedded.sh may run this script without sourcing.
if [ "$0" = "${BASH_SOURCE[0]}" ]; then
echo "setenv-embedded.sh is usually sourced, but not this time."
fi
DEF_CPPFLAGS="-DNDEBUG"
DEF_CFLAGS="-Wall -g2 -O3 -fPIC"
DEF_CXXFLAGS="-Wall -g2 -O3 -fPIC"
DEF_LDFLAGS=""
#########################################
##### Clear old options #####
#########################################
unset IS_IOS
unset IS_MACOS
unset IS_ANDROID
unset IS_ARM_EMBEDDED
unset ARM_EMBEDDED_CPPFLAGS
unset ARM_EMBEDDED_CFLAGS
unset ARM_EMBEDDED_HEADERS
unset ARM_EMBEDDED_CXX_HEADERS
unset ARM_EMBEDDED_CXXFLAGS
unset ARM_EMBEDDED_LDFLAGS
unset ARM_EMBEDDED_SYSROOT
########################################
##### Environment #####
########################################
if [ -z "${ARM_EMBEDDED_TOOLCHAIN-}" ]; then
ARM_EMBEDDED_TOOLCHAIN="/usr/bin"
fi
if [ ! -d "${ARM_EMBEDDED_TOOLCHAIN}" ]; then
echo "ARM_EMBEDDED_TOOLCHAIN is not valid"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Fedora
# TOOL_PREFIX="arm-linux-gnu"
# Ubuntu
TOOL_PREFIX="arm-linux-gnueabi"
CPP="${ARM_EMBEDDED_TOOLCHAIN}/${TOOL_PREFIX}-cpp"
CC="${ARM_EMBEDDED_TOOLCHAIN}/${TOOL_PREFIX}-gcc"
CXX="${ARM_EMBEDDED_TOOLCHAIN}/${TOOL_PREFIX}-g++"
LD="${ARM_EMBEDDED_TOOLCHAIN}/${TOOL_PREFIX}-ld"
AR="${ARM_EMBEDDED_TOOLCHAIN}/${TOOL_PREFIX}-ar"
AS="${ARM_EMBEDDED_TOOLCHAIN}/${TOOL_PREFIX}-as"
RANLIB="${ARM_EMBEDDED_TOOLCHAIN}/${TOOL_PREFIX}-ranlib"
OBJDUMP="${ARM_EMBEDDED_TOOLCHAIN}/${TOOL_PREFIX}-objdump"
# Test a few of the tools
if [ ! -e "$CPP" ]; then
echo "ERROR: CPP is not valid"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [ ! -e "$CC" ]; then
echo "ERROR: CC is not valid"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [ ! -e "$CXX" ]; then
echo "ERROR: CXX is not valid"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [ ! -e "$AR" ]; then
echo "ERROR: AR is not valid"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [ ! -e "$AS" ]; then
echo "ERROR: AS is not valid"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [ ! -e "$RANLIB" ]; then
echo "ERROR: RANLIB is not valid"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [ ! -e "$LD" ]; then
echo "ERROR: LD is not valid"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [ -z "${ARM_EMBEDDED_SYSROOT}" ]; then
ARM_EMBEDDED_SYSROOT="/usr/arm-linux-gnueabi"
fi
if [ ! -d "${ARM_EMBEDDED_SYSROOT}" ]; then
echo "ERROR: ARM_EMBEDDED_SYSROOT is not valid"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Fix C++ header paths for Ubuntu
# ARM_EMBEDDED_TOOLCHAIN_VERSION="4.7.3"
ARM_EMBEDDED_TOOLCHAIN_VERSION="5.4.0"
ARM_EMBEDDED_CXX_HEADERS="${ARM_EMBEDDED_SYSROOT}/include/c++/${ARM_EMBEDDED_TOOLCHAIN_VERSION}"
if [ ! -d "${ARM_EMBEDDED_CXX_HEADERS}" ]; then
echo "ERROR: ARM_EMBEDDED_CXX_HEADERS is not valid"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [ ! -d "${ARM_EMBEDDED_CXX_HEADERS}/arm-linux-gnueabi" ]; then
echo "ERROR: ARM_EMBEDDED_CXX_HEADERS is not valid"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Add additional flags below, like -mcpu=cortex-m3.
if [ -z "${ARM_EMBEDDED_HEADERS}" ]; then
ARM_EMBEDDED_HEADERS="-I\"${ARM_EMBEDDED_CXX_HEADERS}\" -I\"${ARM_EMBEDDED_CXX_HEADERS}/arm-linux-gnueabi\""
fi
#####################################################################
VERBOSE=${VERBOSE:-1}
if [ "$VERBOSE" -gt 0 ]; then
echo "ARM_EMBEDDED_TOOLCHAIN: ${ARM_EMBEDDED_TOOLCHAIN}"
if [[ -n "${ARM_EMBEDDED_CPPFLAGS}" ]]; then
echo "ARM_EMBEDDED_CPPFLAGS: ${ARM_EMBEDDED_CPPFLAGS}"
fi
echo "ARM_EMBEDDED_CFLAGS: ${ARM_EMBEDDED_CFLAGS}"
echo "ARM_EMBEDDED_CXXFLAGS: ${ARM_EMBEDDED_CXXFLAGS}"
if [[ -n "${ARM_EMBEDDED_LDFLAGS}" ]]; then
echo "ARM_EMBEDDED_LDFLAGS: ${ARM_EMBEDDED_LDFLAGS}"
fi
echo "ARM_EMBEDDED_SYSROOT: ${ARM_EMBEDDED_SYSROOT}"
fi
#####################################################################
# GNUmakefile-cross and Autotools expect these to be set.
# Note: prior to Crypto++ 8.6, CPPFLAGS, CXXFLAGS and LDFLAGS were not
# exported. At Crypto++ 8.6 CPPFLAGS, CXXFLAGS and LDFLAGS were exported.
export IS_ARM_EMBEDDED=1
export CPP CC CXX LD AS AR RANLIB STRIP OBJDUMP
CPPFLAGS="${DEF_CPPFLAGS} ${ARM_EMBEDDED_CPPFLAGS} ${ARM_EMBEDDED_HEADERS} -isysroot ${ARM_EMBEDDED_SYSROOT}"
CFLAGS="${DEF_CFLAGS} ${ARM_EMBEDDED_CFLAGS}"
CXXFLAGS="${DEF_CXXFLAGS} ${ARM_EMBEDDED_CXXFLAGS}"
LDFLAGS="${DEF_LDFLAGS} ${ARM_EMBEDDED_LDFLAGS} --sysroot ${ARM_EMBEDDED_SYSROOT}"
# Trim whitespace as needed
CPPFLAGS=$(echo "${CPPFLAGS}" | awk '{$1=$1;print}')
CFLAGS=$(echo "${CFLAGS}" | awk '{$1=$1;print}')
CXXFLAGS=$(echo "${CXXFLAGS}" | awk '{$1=$1;print}')
LDFLAGS=$(echo "${LDFLAGS}" | awk '{$1=$1;print}')
export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
#####################################################################
echo
echo "*******************************************************************************"
echo "It looks the the environment is set correctly. Your next step is build"
echo "the library with 'make -f GNUmakefile-cross'."
echo "*******************************************************************************"
echo
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0

View File

@@ -0,0 +1,399 @@
#!/usr/bin/env bash
#############################################################################
#
# This script sets the cross-compile environment for Xcode/iOS.
#
# Based upon OpenSSL's setenv-android.sh by TH, JW, and SM.
# Heavily modified by JWW for Crypto++.
# Modified some more by JW and UB.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
# cpp is set to Apple's cpp. Actually, cpp is merely on-path so Apple's cpp
# is used. But Apple's cpp is sufficiently different from GNU's cpp and causes
# Autotools a lot of trouble because Autotools tests are predicated on GNU cpp.
# If your Autotools project results in "configure:6560: error: C preprocessor
# cpp fails sanity check", then file a bug report with Autotools.
#
# See http://www.cryptopp.com/wiki/iOS_(Command_Line) for more details
#############################################################################
#########################################
##### Some validation #####
#########################################
# In the past we could mostly infer arch or cpu from the SDK (and mostly
# vice-versa). Nowadays we need the user to set it for us because Apple
# platforms have both 32-bit or 64-bit variations.
# cryptest-ios.sh may run this script without sourcing.
if [ "$0" = "${BASH_SOURCE[0]}" ]; then
echo "setenv-ios.sh is usually sourced, but not this time."
fi
# This supports 'source setenv-ios.sh iPhone arm64' and
# 'source setenv-ios.sh IOS_SDK=iPhone IOS_CPU=arm64'
if [[ -n "$1" ]]
then
arg1=$(echo "$1" | cut -f 1 -d '=')
arg2=$(echo "$1" | cut -f 2 -d '=')
if [[ -n "${arg2}" ]]; then
IOS_SDK="${arg2}"
else
IOS_SDK="${arg1}"
fi
printf "Using positional arg, IOS_SDK=%s\n" "${IOS_SDK}"
fi
# This supports 'source setenv-ios.sh iPhone arm64' and
# 'source setenv-ios.sh IOS_SDK=iPhone IOS_CPU=arm64'
if [[ -n "$2" ]]
then
arg1=$(echo "$2" | cut -f 1 -d '=')
arg2=$(echo "$2" | cut -f 2 -d '=')
if [[ -n "${arg2}" ]]; then
IOS_CPU="${arg2}"
else
IOS_CPU="${arg1}"
fi
printf "Using positional arg, IOS_CPU=%s\n" "${IOS_CPU}"
fi
if [ -z "${IOS_SDK}" ]; then
echo "IOS_SDK is not set. Please set it"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [ -z "${IOS_CPU}" ]; then
echo "IOS_CPU is not set. Please set it"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
DEF_CPPFLAGS="-DNDEBUG"
DEF_CFLAGS="-Wall -g2 -O3 -fPIC"
DEF_CXXFLAGS="-Wall -g2 -O3 -fPIC"
DEF_LDFLAGS=""
#########################################
##### Clear old options #####
#########################################
unset IS_IOS
unset IS_MACOS
unset IS_ANDROID
unset IS_ARM_EMBEDDED
unset IOS_CPPFLAGS
unset IOS_CFLAGS
unset IOS_CXXFLAGS
unset IOS_LDFLAGS
unset IOS_SYSROOT
#########################################
##### Small Fixups, if needed #####
#########################################
IOS_CPU=$(tr '[:upper:]' '[:lower:]' <<< "${IOS_CPU}")
ALT_SDK=$(tr '[:upper:]' '[:lower:]' <<< "${IOS_SDK}")
if [[ "${IOS_SDK}" == "iPhone" ]]; then
IOS_SDK=iPhoneOS
elif [[ "$ALT_SDK" == "iphone" || "$ALT_SDK" == "iphoneos" ]]; then
IOS_SDK=iPhoneOS
fi
if [[ "${IOS_SDK}" == "iPhoneSimulator" || "${IOS_SDK}" == "iPhoneOSSimulator" ]]; then
IOS_SDK=iPhoneSimulator
elif [[ "$ALT_SDK" == "iphonesimulator" || "$ALT_SDK" == "iphoneossimulator" ]]; then
IOS_SDK=iPhoneSimulator
fi
if [[ "${IOS_SDK}" == "TV" || "${IOS_SDK}" == "AppleTV" ]]; then
IOS_SDK=AppleTVOS
elif [[ "$ALT_SDK" == "tv" || "$ALT_SDK" == "appletv" || "$ALT_SDK" == "appletvos" ]]; then
IOS_SDK=AppleTVOS
fi
if [[ "${IOS_SDK}" == "Watch" || "${IOS_SDK}" == "AppleWatch" ]]; then
IOS_SDK=WatchOS
elif [[ "$ALT_SDK" == "watch" || "$ALT_SDK" == "applewatch" || "$ALT_SDK" == "applewatchos" ]]; then
IOS_SDK=WatchOS
fi
if [[ "${IOS_CPU}" == "amd64" || "${IOS_CPU}" == "x86_64" ]] ; then
IOS_CPU=x86_64
fi
if [[ "${IOS_CPU}" == "i386" || "${IOS_CPU}" == "i586" || "${IOS_CPU}" == "i686" ]] ; then
IOS_CPU=i386
fi
if [[ "${IOS_CPU}" == "aarch64" || "${IOS_CPU}" == "arm64"* || "${IOS_CPU}" == "armv8"* ]] ; then
IOS_CPU=arm64
fi
echo "Configuring for ${IOS_SDK} (${IOS_CPU})"
########################################
##### Environment #####
########################################
# The flags below were tested with Xcode 8 on Travis. If
# you use downlevel versions of Xcode, then you can push
# xxx-version-min=n lower. For example, Xcode 7 can use
# -miphoneos-version-min=5. However, Xcode 7 lacks
# AppleTVOS and WatchOS support.
# Also see https://github.com/rust-lang/rust/issues/48862
# and https://developer.apple.com/documentation/bundleresources/information_property_list/minimumosversion
# iPhones can be either 32-bit or 64-bit
if [[ "${IOS_SDK}" == "iPhoneOS" && "${IOS_CPU}" == "armv7"* ]]; then
MIN_VER=-miphoneos-version-min=6
elif [[ "${IOS_SDK}" == "iPhoneOS" && "${IOS_CPU}" == "arm64" ]]; then
MIN_VER=-miphoneos-version-min=6
# Fixups for convenience
elif [[ "${IOS_SDK}" == "iPhoneOS" && "${IOS_CPU}" == "i386" ]]; then
IOS_SDK=iPhoneSimulator
# MIN_VER=-miphoneos-version-min=6
MIN_VER=-miphonesimulator-version-min=6
elif [[ "${IOS_SDK}" == "iPhoneOS" && "${IOS_CPU}" == "x86_64" ]]; then
IOS_SDK=iPhoneSimulator
# MIN_VER=-miphoneos-version-min=6
MIN_VER=-miphonesimulator-version-min=6
# Simulator builds
elif [[ "${IOS_SDK}" == "iPhoneSimulator" && "${IOS_CPU}" == "i386" ]]; then
MIN_VER=-miphonesimulator-version-min=6
elif [[ "${IOS_SDK}" == "iPhoneSimulator" && "${IOS_CPU}" == "x86_64" ]]; then
MIN_VER=-miphonesimulator-version-min=6
elif [[ "${IOS_SDK}" == "iPhoneSimulator" && "${IOS_CPU}" == "arm64" ]]; then
MIN_VER=-miphonesimulator-version-min=6
# Apple TV can be 32-bit Intel (1st gen), 32-bit ARM (2nd, 3rd gen) or 64-bit ARM (4th gen)
elif [[ "${IOS_SDK}" == "AppleTVOS" && "${IOS_CPU}" == "i386" ]]; then
MIN_VER=-mappletvos-version-min=6
elif [[ "${IOS_SDK}" == "AppleTVOS" && "${IOS_CPU}" == "armv7"* ]]; then
MIN_VER=-mappletvos-version-min=6
elif [[ "${IOS_SDK}" == "AppleTVOS" && "${IOS_CPU}" == "arm64" ]]; then
MIN_VER=-mappletvos-version-min=6
# Simulator builds
elif [[ "${IOS_SDK}" == "AppleTVSimulator" && "${IOS_CPU}" == "i386" ]]; then
MIN_VER=-mappletvsimulator-version-min=6
elif [[ "${IOS_SDK}" == "AppleTVSimulator" && "${IOS_CPU}" == "x86_64" ]]; then
MIN_VER=-mappletvsimulator-version-min=6
# Watch can be either 32-bit or 64-bit ARM. TODO: figure out which
# -mwatchos-version-min=n is needed for arm64. 9 is not enough.
elif [[ "${IOS_SDK}" == "WatchOS" && "${IOS_CPU}" == "armv7"* ]]; then
MIN_VER=-mwatchos-version-min=6
elif [[ "${IOS_SDK}" == "WatchOS" && "${IOS_CPU}" == "arm64" ]]; then
MIN_VER=-mwatchos-version-min=6
# Simulator builds. TODO: figure out which -watchos-version-min=n
# is needed for arm64. 6 compiles and links, but is it correct?
elif [[ "${IOS_SDK}" == "WatchSimulator" && "${IOS_CPU}" == "i386" ]]; then
MIN_VER=-mwatchsimulator-version-min=6
elif [[ "${IOS_SDK}" == "WatchSimulator" && "${IOS_CPU}" == "x86_64" ]]; then
MIN_VER=-mwatchsimulator-version-min=6
# And the final catch-all
else
echo "IOS_SDK and IOS_CPU are not valid. Please fix them"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
#####################################################################
# Xcode 6 and below cannot handle -miphonesimulator-version-min
# Fix it so the simulator will compile as expected. This trick
# may work on other platforms, but it was not tested.
if [ -n "$(command -v xcodebuild 2>/dev/null)" ]; then
# Output of xcodebuild is similar to "Xcode 6.2". The first cut gets
# the dotted decimal value. The second cut gets the major version.
XCODE_VERSION=$(xcodebuild -version 2>/dev/null | head -n 1 | cut -f 2 -d ' ' | cut -f 1 -d '.')
if [ -z "${XCODE_VERSION}" ]; then XCODE_VERSION=100; fi
if [ "${XCODE_VERSION}" -le 6 ]; then
MIN_VER="${MIN_VER//iphonesimulator/iphoneos}"
fi
fi
#####################################################################
# Allow a user override? I think we should be doing this. The use case is:
# move /Applications/Xcode somewhere else for a side-by-side installation.
if [ -z "${XCODE_DEVELOPER-}" ]; then
XCODE_DEVELOPER=$(xcode-select -print-path 2>/dev/null)
fi
if [ ! -d "${XCODE_DEVELOPER}" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER directory."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# XCODE_DEVELOPER_SDK is the SDK location.
XCODE_DEVELOPER_SDK="${XCODE_DEVELOPER}/Platforms/$IOS_SDK.platform/Developer/SDKs"
if [ ! -d "${XCODE_DEVELOPER_SDK}" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER_SDK directory."
echo " Is the SDK supported by Xcode and installed?"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# XCODE_TOOLCHAIN is the location of the actual compiler tools.
if [ -d "${XCODE_DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/" ]; then
XCODE_TOOLCHAIN="${XCODE_DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
elif [ -d "${XCODE_DEVELOPER_SDK}/Developer/usr/bin/" ]; then
XCODE_TOOLCHAIN="${XCODE_DEVELOPER_SDK}/Developer/usr/bin/"
fi
if [ ! -d "${XCODE_TOOLCHAIN}" ]; then
echo "ERROR: unable to find Xcode cross-compiler tools."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# XCODE_SDK is the SDK name/version being used - adjust the list as appropriate.
# For example, remove 4.3, 6.2, and 6.1 if they are not installed. We go back to
# the 1.0 SDKs because Apple WatchOS uses low numbers, like 2.0 and 2.1.
XCODE_SDK=""
for i in $(seq 30 -1 5) # SDK major
do
for j in $(seq 20 -1 0) # SDK minor
do
SDK_VER="$i.$j"
if [ -d "${XCODE_DEVELOPER_SDK}/${IOS_SDK}${SDK_VER}.sdk" ]; then
XCODE_SDK="${IOS_SDK}${SDK_VER}.sdk"
break 2
fi
done
done
# Error checking
if [ -z "${XCODE_SDK}" ]; then
echo "ERROR: unable to find a SDK."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
IOS_CFLAGS="-arch ${IOS_CPU} ${MIN_VER} -fno-common"
IOS_CXXFLAGS="-arch ${IOS_CPU} ${MIN_VER} -stdlib=libc++ -fno-common"
IOS_SYSROOT="${XCODE_DEVELOPER_SDK}/${XCODE_SDK}"
if [ ! -d "${IOS_SYSROOT}" ]; then
echo "ERROR: unable to find Xcode sysroot."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# The simulators need to disable ASM. They don't receive arch flags.
# https://github.com/weidai11/cryptopp/issues/635
if [[ "${IOS_SDK}" == *"Simulator" ]]; then
IOS_CPPFLAGS="$IOS_CPPFLAGS -DCRYPTOPP_DISABLE_ASM"
fi
#####################################################################
CPP="cpp"; CC="clang"; CXX="clang++"; LD="ld"
AS="as"; AR="libtool"; RANLIB="ranlib"
STRIP="strip"; OBJDUMP="objdump"
# Error checking
if [ ! -e "${XCODE_TOOLCHAIN}/$CC" ]; then
echo "ERROR: Failed to find iOS clang. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${XCODE_TOOLCHAIN}/$CXX" ]; then
echo "ERROR: Failed to find iOS clang++. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${XCODE_TOOLCHAIN}/$RANLIB" ]; then
echo "ERROR: Failed to find iOS ranlib. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${XCODE_TOOLCHAIN}/$AR" ]; then
echo "ERROR: Failed to find iOS ar. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${XCODE_TOOLCHAIN}/$AS" ]; then
echo "ERROR: Failed to find iOS as. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${XCODE_TOOLCHAIN}/$LD" ]; then
echo "ERROR: Failed to find iOS ld. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
#####################################################################
# Add tools to head of path, if not present already
LENGTH=${#XCODE_TOOLCHAIN}
SUBSTR=${PATH:0:$LENGTH}
if [ "${SUBSTR}" != "${XCODE_TOOLCHAIN}" ]; then
export PATH="${XCODE_TOOLCHAIN}:${PATH}"
fi
#####################################################################
VERBOSE=${VERBOSE:-1}
if [ "$VERBOSE" -gt 0 ]; then
echo "XCODE_TOOLCHAIN: ${XCODE_TOOLCHAIN}"
echo "IOS_SDK: ${IOS_SDK}"
echo "IOS_CPU: ${IOS_CPU}"
if [ -n "${IOS_CPPFLAGS}" ]; then
echo "IOS_CPPFLAGS: ${IOS_CPPFLAGS}"
fi
echo "IOS_CFLAGS: ${IOS_CFLAGS}"
echo "IOS_CXXFLAGS: ${IOS_CXXFLAGS}"
if [ -n "${IOS_LDFLAGS}" ]; then
echo "IOS_LDFLAGS: ${IOS_LDFLAGS}"
fi
echo "IOS_SYSROOT: ${IOS_SYSROOT}"
fi
#####################################################################
# GNUmakefile-cross and Autotools expect these to be set.
# Note: prior to Crypto++ 8.6, CPPFLAGS, CXXFLAGS and LDFLAGS were not
# exported. At Crypto++ 8.6 CPPFLAGS, CXXFLAGS and LDFLAGS were exported.
export IS_IOS=1
export CPP CC CXX LD AS AR RANLIB STRIP OBJDUMP
CPPFLAGS="${DEF_CPPFLAGS} ${IOS_CPPFLAGS} -isysroot ${IOS_SYSROOT}"
CFLAGS="${DEF_CFLAGS} ${IOS_CFLAGS}"
CXXFLAGS="${DEF_CXXFLAGS} ${IOS_CXXFLAGS}"
LDFLAGS="${DEF_LDFLAGS} ${IOS_LDFLAGS} --sysroot ${IOS_SYSROOT}"
# Trim whitespace as needed
CPPFLAGS=$(echo "${CPPFLAGS}" | awk '{$1=$1;print}')
CFLAGS=$(echo "${CFLAGS}" | awk '{$1=$1;print}')
CXXFLAGS=$(echo "${CXXFLAGS}" | awk '{$1=$1;print}')
LDFLAGS=$(echo "${LDFLAGS}" | awk '{$1=$1;print}')
export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
#####################################################################
echo
echo "*******************************************************************************"
echo "It looks the the environment is set correctly. Your next step is build"
echo "the library with 'make -f GNUmakefile-cross'."
echo "*******************************************************************************"
echo
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0

View File

@@ -0,0 +1,422 @@
#!/usr/bin/env bash
#############################################################################
#
# This script sets the cross-compile environment for Xcode/MacOS.
#
# Based upon OpenSSL's setenv-android.sh by TH, JW, and SM.
# Heavily modified by JWW for Crypto++.
# Modified some more by JW and UB.
#
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
# licensed under the Boost Software License 1.0, while the individual files
# in the compilation are all public domain.
#
# cpp is set to Apple's cpp. Actually, cpp is merely on-path so Apple's cpp
# is used. But Apple's cpp is sufficiently different from GNU's cpp and causes
# Autotools a lot of trouble because Autotools tests are predicated on GNU cpp.
# If your Autotools project results in "configure:6560: error: C preprocessor
# cpp fails sanity check", then file a bug report with Autotools.
#
# See http://www.cryptopp.com/wiki/MacOS_(Command_Line) for more details
#############################################################################
#########################################
##### Some validation #####
#########################################
# In the past we could mostly infer arch or cpu from the SDK (and mostly
# vice-versa). Nowadays we need the user to set it for us because Apple
# platforms have both 32-bit or 64-bit variations.
# cryptest-macos.sh may run this script without sourcing.
if [ "$0" = "${BASH_SOURCE[0]}" ]; then
echo "setenv-macos.sh is usually sourced, but not this time."
fi
# This is fixed since we are building for MacOS
MACOS_SDK=MacOSX
# This supports 'source setenv-macos.sh x86_64' and
# 'source setenv-macos.sh MACOS_CPU=arm64'
if [[ -n "$1" ]]
then
arg1=$(echo "$1" | cut -f 1 -d '=')
arg2=$(echo "$1" | cut -f 2 -d '=')
if [[ -n "${arg2}" ]]; then
MACOS_CPU="${arg2}"
else
MACOS_CPU="${arg1}"
fi
printf "Using positional arg, MACOS_CPU=%s\n" "${MACOS_CPU}"
fi
# Sane default. Use current machine.
if [ -z "$MACOS_CPU" ]; then
MACOS_CPU="$(uname -m 2>/dev/null)"
if [[ "$MACOS_CPU" == "Power"* ]] ; then
if sysctl -a 2>/dev/null | grep -q 'hw.cpu64bit_capable: 1'; then
MACOS_CPU="ppc64"
else
MACOS_CPU="ppc"
fi
fi
fi
if [ -z "$MACOS_CPU" ]; then
echo "MACOS_CPU is not set. Please set it"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
DEF_CPPFLAGS="-DNDEBUG"
DEF_CFLAGS="-Wall -g2 -O3 -fPIC"
DEF_CXXFLAGS="-Wall -g2 -O3 -fPIC"
DEF_LDFLAGS=""
#########################################
##### Clear old options #####
#########################################
unset IS_IOS
unset IS_MACOS
unset IS_ANDROID
unset IS_ARM_EMBEDDED
unset MACOS_CPPFLAGS
unset MACOS_CFLAGS
unset MACOS_CXXFLAGS
unset MACOS_LDFLAGS
unset MACOS_SYSROOT
#########################################
##### Small Fixups, if needed #####
#########################################
MACOS_CPU=$(tr '[:upper:]' '[:lower:]' <<< "${MACOS_CPU}")
# Old world Macs
if [[ "$MACOS_CPU" == "power macintosh" || "$MACOS_CPU" == "powerpc" ]] ; then
MACOS_CPU=ppc
fi
if [[ "$MACOS_CPU" == "ppc64" || "$MACOS_CPU" == "powerpc64" ]] ; then
MACOS_CPU=ppc64
fi
if [[ "$MACOS_CPU" == "386" || "$MACOS_CPU" == "i686" || "$MACOS_CPU" == "686" ]] ; then
MACOS_CPU=i386
fi
if [[ "$MACOS_CPU" == "amd64" || "$MACOS_CPU" == "x86_64" ]] ; then
MACOS_CPU=x86_64
fi
if [[ "$MACOS_CPU" == "aarch64" || "$MACOS_CPU" == "arm64"* || "$MACOS_CPU" == "armv8"* ]] ; then
MACOS_CPU=arm64
fi
echo "Configuring for $MACOS_SDK ($MACOS_CPU)"
########################################
##### Environment #####
########################################
# The flags below were tested with Xcode 8 on Travis. If
# you use downlevel versions of Xcode, then you can push
# xxx-version-min=n lower. For example, Xcode 7 can use
# -mmacosx-version-min=5. However, you cannot link
# against LLVM's libc++.
# Also see https://github.com/rust-lang/rust/issues/48862
# and https://developer.apple.com/documentation/bundleresources/information_property_list/minimumosversion
# PowerMacs and Intels can be either 32-bit or 64-bit
if [[ "$MACOS_CPU" == "ppc" ]]; then
MIN_VER="-mmacosx-version-min=10.4"
elif [[ "$MACOS_CPU" == "ppc64" ]]; then
MIN_VER="-mmacosx-version-min=10.4"
elif [[ "$MACOS_CPU" == "i386" ]]; then
MIN_VER="-mmacosx-version-min=10.7"
elif [[ "$MACOS_CPU" == "x86_64" ]]; then
MIN_VER="-mmacosx-version-min=10.7"
elif [[ "$MACOS_CPU" == "arm64" ]]; then
MIN_VER="-mmacosx-version-min=11.0"
# And the final catch-all
else
echo "MACOS_CPU is not valid. Please fix it"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# The first cut if MIN_VER gets the full version, like 10.7. The
# second cut gets the major or minor version
if echo "${MIN_VER}" | grep -q '.'; then
MAJOR_VER=$(echo "${MIN_VER}" | head -n 1 | cut -f 2 -d '=' | cut -f 1 -d '.')
MINOR_VER=$(echo "${MIN_VER}" | head -n 1 | cut -f 2 -d '=' | cut -f 2 -d '.')
else
MAJOR_VER=$(echo "${MIN_VER}" | head -n 1 | cut -f 2 -d '=' | cut -f 1 -d '.')
MINOR_VER=0
fi
# OS X 10.7 minimum required for LLVM and -stdlib=libc++
if [[ "${MAJOR_VER}" -eq 10 && "${MINOR_VER}" -ge 7 ]]; then
MACOS_STDLIB="-stdlib=libc++"
elif [[ "${MAJOR_VER}" -ge 11 ]]; then
MACOS_STDLIB="-stdlib=libc++"
fi
# Allow a user override? I think we should be doing this. The use case is:
# move /Applications/Xcode somewhere else for a side-by-side installation.
if [ -z "${XCODE_DEVELOPER-}" ]; then
XCODE_DEVELOPER=$(xcode-select -print-path 2>/dev/null)
fi
if [ ! -d "${XCODE_DEVELOPER}" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER directory."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
if [[ "${XCODE_DEVELOPER}" == "/Developer"* ]]; then
ANTIQUE_XCODE=1
DEF_CFLAGS=$(echo "$DEF_CFLAGS" | sed 's/-Wall //g')
DEF_CXXFLAGS=$(echo "$DEF_CXXFLAGS" | sed 's/-Wall //g')
fi
# Command Line Tools show up here on a Mac-mini M1
if [[ "${XCODE_DEVELOPER}" == "/Library"* ]]; then
CLT_XCODE=1
fi
# XCODE_DEVELOPER_SDK is the SDK location.
if [[ "${ANTIQUE_XCODE}" == "1" ]]
then
if [[ -d "${XCODE_DEVELOPER}/SDKs" ]]; then
XCODE_DEVELOPER_SDK="${XCODE_DEVELOPER}/SDKs"
fi
if [ ! -d "${XCODE_DEVELOPER_SDK}" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER_SDK directory."
echo " Is the SDK supported by Xcode and installed?"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
elif [[ "${CLT_XCODE}" == "1" ]]
then
if [[ -d "${XCODE_DEVELOPER}/SDKs" ]]; then
XCODE_DEVELOPER_SDK="${XCODE_DEVELOPER}/SDKs"
fi
if [ ! -d "${XCODE_DEVELOPER_SDK}" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER_SDK directory."
echo " Is the SDK supported by Xcode and installed?"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
else
if [[ -d "${XCODE_DEVELOPER}/Platforms/${MACOS_SDK}.platform" ]]; then
XCODE_DEVELOPER_SDK="${XCODE_DEVELOPER}/Platforms/${MACOS_SDK}.platform/Developer/SDKs"
fi
fi
# XCODE_SDK is the SDK name/version being used - adjust the list as appropriate.
# For example, remove 4.3, 6.2, and 6.1 if they are not installed. We go back to
# the 1.0 SDKs because Apple WatchOS uses low numbers, like 2.0 and 2.1.
XCODE_SDK=""
if [[ "${ANTIQUE_XCODE}" == "1" ]]
then
for i in 10.7 10.6 10.5 10.4 10.3 10.2 10.0
do
if [ -d "${XCODE_DEVELOPER_SDK}/${MACOS_SDK}$i.sdk" ]; then
XCODE_SDK="${MACOS_SDK}$i.sdk"
break
fi
done
else
for i in $(seq 30 -1 5) # SDK major
do
for j in $(seq 20 -1 0) # SDK minor
do
SDK_VER="$i.$j"
if [ -d "${XCODE_DEVELOPER_SDK}/${MACOS_SDK}${SDK_VER}.sdk" ]; then
XCODE_SDK="${MACOS_SDK}${SDK_VER}.sdk"
break 2
fi
done
done
fi
# Error checking
if [ -z "${XCODE_SDK}" ]; then
echo "ERROR: unable to find a SDK."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# XCODE_DEVELOPER_SDK is the SDK location.
if [[ "${ANTIQUE_XCODE}" == "1" ]]
then
# XCODE_DEVELOPER_SDK for old Xcode is above
:
else
if [ ! -d "${XCODE_DEVELOPER_SDK}" ]; then
echo "ERROR: unable to find XCODE_DEVELOPER_SDK directory."
echo " Is the SDK supported by Xcode and installed?"
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
fi
# XCODE_TOOLCHAIN is the location of the actual compiler tools.
if [[ "${ANTIQUE_XCODE}" == "1" ]]
then
if [ -d "${XCODE_DEVELOPER}/usr/bin" ]; then
XCODE_TOOLCHAIN="${XCODE_DEVELOPER}/usr/bin"
fi
elif [[ "${CLT_XCODE}" == "1" ]]
then
if [ -d "${XCODE_DEVELOPER}/usr/bin" ]; then
XCODE_TOOLCHAIN="${XCODE_DEVELOPER}/usr/bin"
fi
else
if [ -d "${XCODE_DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/" ]; then
XCODE_TOOLCHAIN="${XCODE_DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/"
elif [ -d "${XCODE_DEVELOPER_SDK}/Developer/usr/bin/" ]; then
XCODE_TOOLCHAIN="${XCODE_DEVELOPER_SDK}/Developer/usr/bin/"
elif [ -d "${XCODE_DEVELOPER_SDK}/usr/bin/" ]; then
XCODE_TOOLCHAIN="${XCODE_DEVELOPER_SDK}/usr/bin/"
fi
fi
if [ ! -d "${XCODE_TOOLCHAIN}" ]; then
echo "ERROR: unable to find Xcode cross-compiler tools."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
MACOS_CFLAGS="-arch $MACOS_CPU $MIN_VER -fno-common"
MACOS_CXXFLAGS="-arch $MACOS_CPU $MIN_VER ${MACOS_STDLIB} -fno-common"
MACOS_SYSROOT="${XCODE_DEVELOPER_SDK}/${XCODE_SDK}"
if [ ! -d "${MACOS_SYSROOT}" ]; then
echo "ERROR: unable to find Xcode sysroot."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
#####################################################################
CPP="cpp"; CC="clang"; CXX="clang++"; LD="ld"
AS="as"; AR="libtool"; RANLIB="ranlib"
STRIP="strip"; OBJDUMP="objdump"
if [[ "${ANTIQUE_XCODE}" == "1" ]]
then
CC="gcc"; CXX="g++";
fi
# Error checking
if [ ! -e "${XCODE_TOOLCHAIN}/$CC" ]; then
echo "ERROR: Failed to find MacOS clang. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${XCODE_TOOLCHAIN}/$CXX" ]; then
echo "ERROR: Failed to find MacOS clang++. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${XCODE_TOOLCHAIN}/$RANLIB" ]; then
echo "ERROR: Failed to find MacOS ranlib. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${XCODE_TOOLCHAIN}/$AR" ]; then
echo "ERROR: Failed to find MacOS ar. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${XCODE_TOOLCHAIN}/$AS" ]; then
echo "ERROR: Failed to find MacOS as. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
# Error checking
if [ ! -e "${XCODE_TOOLCHAIN}/$LD" ]; then
echo "ERROR: Failed to find MacOS ld. Please edit this script."
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
fi
#####################################################################
# Add tools to head of path, if not present already
LENGTH=${#XCODE_TOOLCHAIN}
SUBSTR=${PATH:0:$LENGTH}
if [ "${SUBSTR}" != "${XCODE_TOOLCHAIN}" ]; then
PATH="${XCODE_TOOLCHAIN}:$PATH"
export PATH
fi
#####################################################################
VERBOSE=${VERBOSE:-1}
if [ "$VERBOSE" -gt 0 ]; then
echo "XCODE_TOOLCHAIN: ${XCODE_TOOLCHAIN}"
echo "MACOS_SDK: ${MACOS_SDK}"
echo "MACOS_CPU: ${MACOS_CPU}"
if [ -n "${MACOS_CPPFLAGS}" ]; then
echo "MACOS_CPPFLAGS: ${MACOS_CPPFLAGS}"
fi
echo "MACOS_CFLAGS: ${MACOS_CFLAGS}"
echo "MACOS_CXXFLAGS: ${MACOS_CXXFLAGS}"
if [ -n "${MACOS_LDFLAGS}" ]; then
echo "MACOS_LDFLAGS: ${MACOS_LDFLAGS}"
fi
echo "MACOS_SYSROOT: ${MACOS_SYSROOT}"
fi
#####################################################################
# GNUmakefile-cross and Autotools expect these to be set.
# Note: prior to Crypto++ 8.6, CPPFLAGS, CXXFLAGS and LDFLAGS were not
# exported. At Crypto++ 8.6 CPPFLAGS, CXXFLAGS and LDFLAGS were exported.
export IS_MACOS=1
export CPP CC CXX LD AS AR RANLIB STRIP OBJDUMP
if [[ "${ANTIQUE_XCODE}" == "1" ]]
then
CPPFLAGS="${DEF_CPPFLAGS} ${MACOS_CPPFLAGS} -isysroot ${MACOS_SYSROOT}"
CFLAGS="${DEF_CFLAGS} ${MACOS_CFLAGS}"
CXXFLAGS="${DEF_CXXFLAGS} ${MACOS_CXXFLAGS}"
LDFLAGS="${DEF_LDFLAGS} ${MACOS_LDFLAGS} -sysroot=${MACOS_SYSROOT}"
else
CPPFLAGS="${DEF_CPPFLAGS} ${MACOS_CPPFLAGS} -isysroot ${MACOS_SYSROOT}"
CFLAGS="${DEF_CFLAGS} ${MACOS_CFLAGS}"
CXXFLAGS="${DEF_CXXFLAGS} ${MACOS_CXXFLAGS}"
LDFLAGS="${DEF_LDFLAGS} ${MACOS_LDFLAGS} --sysroot ${MACOS_SYSROOT}"
fi
# Trim whitespace as needed
CPPFLAGS=$(echo "${CPPFLAGS}" | awk '{$1=$1;print}')
CFLAGS=$(echo "${CFLAGS}" | awk '{$1=$1;print}')
CXXFLAGS=$(echo "${CXXFLAGS}" | awk '{$1=$1;print}')
LDFLAGS=$(echo "${LDFLAGS}" | awk '{$1=$1;print}')
export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
#####################################################################
echo
echo "*******************************************************************************"
echo "It looks the the environment is set correctly. Your next step is build"
echo "the library with 'make -f GNUmakefile-cross'."
echo "*******************************************************************************"
echo
[ "$0" = "${BASH_SOURCE[0]}" ] && exit 0 || return 0