1#!/usr/bin/env bash 2 3############################################################################# 4# 5# This script tests the Autotools gear. 6# 7# Written and placed in public domain by Jeffrey Walton. 8# 9# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2) 10# licensed under the Boost Software License 1.0, while the individual files 11# in the compilation are all public domain. 12# 13# See https://www.cryptopp.com/wiki/Autotools for more details 14# 15############################################################################# 16 17# Default tools 18GREP=grep 19SED=sed 20AWK=awk 21MAKE=make 22 23############################################################################# 24 25# Fixup, Solaris and friends 26if [[ -d /usr/xpg4/bin ]]; then 27 SED=/usr/xpg4/bin/sed 28 AWK=/usr/xpg4/bin/awk 29 GREP=/usr/xpg4/bin/grep 30elif [[ -d /usr/bin/posix ]]; then 31 SED=/usr/bin/posix/sed 32 AWK=/usr/bin/posix/awk 33 GREP=/usr/bin/posix/grep 34fi 35 36# Fixup for sed and "illegal byte sequence" 37IS_DARWIN=$(uname -s 2>/dev/null | "$GREP" -i -c darwin) 38if [[ "$IS_DARWIN" -ne 0 ]]; then 39 export LC_ALL=C 40fi 41 42# Fixup for Solaris and BSDs 43if [[ -n "$(command -v gmake 2>/dev/null)" ]]; then 44 MAKE=gmake 45else 46 MAKE=make 47fi 48 49# Fixup for missing libtool 50if [[ ! -z $(command -v glibtoolize 2>/dev/null) ]]; then 51 export LIBTOOLIZE=$(command -v glibtoolize) 52elif [[ ! -z $(command -v libtoolize 2>/dev/null) ]]; then 53 export LIBTOOLIZE=$(command -v libtoolize) 54elif [[ ! -z $(command -v glibtool 2>/dev/null) ]]; then 55 export LIBTOOLIZE=$(command -v glibtool) 56elif [[ ! -z $(command -v libtool 2>/dev/null) ]]; then 57 export LIBTOOLIZE=$(command -v libtool) 58fi 59 60# In case libtool is located in /opt, like under MacPorts or Compile Farm 61if [[ -z $(command -v glibtoolize 2>/dev/null) ]]; then 62 export LIBTOOLIZE=$(find /opt -name libtool 2>/dev/null | head -n 1) 63fi 64 65############################################################################# 66 67if [[ -z $(command -v aclocal 2>/dev/null) ]]; then 68 echo "Cannot find aclocal. Things may fail." 69fi 70 71if [[ -z $(command -v autoupdate 2>/dev/null) ]]; then 72 echo "Cannot find autoupdate. Things may fail." 73fi 74 75if [[ -z "$LIBTOOLIZE" ]]; then 76 echo "Cannot find libtoolize. Things may fail." 77fi 78 79if [[ -z $(command -v automake 2>/dev/null) ]]; then 80 echo "Cannot find automake. Things may fail." 81fi 82 83if [[ -z $(command -v autoreconf 2>/dev/null) ]]; then 84 echo "Cannot find autoreconf. Things may fail." 85fi 86 87if [[ -z $(command -v curl 2>/dev/null) ]]; then 88 echo "Cannot find cURL. Things may fail." 89fi 90 91############################################################################# 92 93files=(configure.ac Makefile.am libcryptopp.pc.in) 94 95for file in "${files[@]}"; do 96 echo "Downloading $file" 97 if ! curl -L -s -o "$file" "https://raw.githubusercontent.com/noloader/cryptopp-autotools/master/$file"; then 98 echo "$file download failed" 99 exit 1 100 fi 101 # Throttle 102 sleep 1 103done 104 105mkdir -p m4/ 106 107############################################################################# 108 109echo "Running aclocal" 110if ! aclocal &>/dev/null; then 111 echo "aclocal failed." 112 exit 1 113fi 114 115echo "Running autoupdate" 116if ! autoupdate &>/dev/null; then 117 echo "autoupdate failed." 118 exit 1 119fi 120 121# Run autoreconf twice on failure. Also see 122# https://github.com/tracebox/tracebox/issues/57 123echo "Running autoreconf" 124if ! autoreconf --force --install &>/dev/null; then 125 echo "autoreconf failed, running again." 126 if ! autoreconf --force --install; then 127 echo "autoreconf failed, again." 128 exit 1 129 fi 130fi 131 132############################################################################# 133 134# Update config.sub config.guess. GNU recommends using the latest for all projects. 135echo "Updating config.sub" 136curl -L -s -o config.sub.new 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub' 137 138# Solaris removes +w, can't overwrite 139chmod +w build-aux/config.sub 140mv config.sub.new build-aux/config.sub 141chmod +x build-aux/config.sub 142 143if [[ "$IS_DARWIN" -ne 0 ]] && [[ -n $(command -v xattr 2>/dev/null) ]]; then 144 echo "Removing config.sub quarantine" 145 xattr -d "com.apple.quarantine" build-aux/config.sub &>/dev/null 146fi 147 148echo "Updating config.guess" 149curl -L -s -o config.guess.new 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess' 150 151# Solaris removes +w, can't overwrite 152chmod +w build-aux/config.guess 153mv config.guess.new build-aux/config.guess 154chmod +x build-aux/config.guess 155 156if [[ "$IS_DARWIN" -ne 0 ]] && [[ -n $(command -v xattr 2>/dev/null) ]]; then 157 echo "Removing config.guess quarantine" 158 xattr -d "com.apple.quarantine" build-aux/config.guess &>/dev/null 159fi 160 161############################################################################# 162 163echo "Running configure" 164echo "" 165 166if ! ./configure; then 167 echo "configure failed." 168 exit 1 169fi 170 171############################################################################# 172 173echo "" 174echo "Building test artifacts" 175echo "" 176 177"$MAKE" clean &>/dev/null 178 179if ! "$MAKE" -j2 -f Makefile; then 180 echo "make failed." 181 exit 1 182fi 183 184############################################################################# 185 186echo "" 187echo "Testing library" 188echo "" 189 190if ! ./cryptest v; then 191 echo "cryptest v failed." 192 exit 1 193fi 194 195if ! ./cryptest tv all; then 196 echo "cryptest tv all failed." 197 exit 1 198fi 199 200############################################################################# 201 202echo "" 203echo "Building tarball" 204echo "" 205 206if ! make dist; then 207 echo "make dist failed." 208 exit 1 209fi 210 211# Return success 212exit 0 213