Merge pull request #116 from oneton/1.0.2-command-line

Specify build configuration with command line parameters
This commit is contained in:
Felix Schulze 2016-09-18 19:53:27 +02:00 committed by GitHub
commit 48e6942d79
2 changed files with 167 additions and 44 deletions

View File

@ -1,7 +1,7 @@
osx_image: xcode8
language: objective-c
before_install:
- ./build-libssl.sh verbose-on-error
- ./build-libssl.sh --noparallel --verbose-on-error
- xcrun -sdk iphoneos lipo -info ./lib/*.a
- ./create-openssl-framework.sh
- xcrun -sdk iphoneos lipo -info openssl.framework/openssl

View File

@ -18,31 +18,40 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
# Change values here #
# #
VERSION="1.0.2h" #
IOS_SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version` #
TVOS_SDKVERSION=`xcrun -sdk appletvos --show-sdk-version` #
CONFIG_OPTIONS="" #
CURL_OPTIONS="" #
# ARCHS is a space-separated list of architectures to build
# Options: x86_64 i386 arm64 armv7s armv7 tv_x86_64 tv_arm64
# Please note: The framework will contain include files from the architecture listed first
ARCHS="x86_64 i386 arm64 armv7s armv7 tv_x86_64 tv_arm64"
# -u Attempt to use undefined variable outputs error message, and forces an exit
set -u
# Set to false to disable make with multiple parallel jobs
PARALLEL="true"
DEFAULTVERSION="1.0.2h" # Default version in case no version is specified
IOS_MIN_SDK_VERSION="7.0" # Minimum iOS SDK version to build for
TVOS_MIN_SDK_VERSION="9.0" # Minimum tvOS SDK version to build for
# Init optional env variables
CURL_OPTIONS="${CURL_OPTIONS:-}"
CONFIG_OPTIONS="${CONFIG_OPTIONS:-}"
echo_help()
{
echo "Usage: $0 [options...]"
echo " --archs=\"ARCH ARCH ...\" Space-separated list of architectures to build"
echo " Options: x86_64 i386 arm64 armv7s armv7 tv_x86_64 tv_arm64"
echo " Note: The framework will contain include files from the architecture listed first"
echo " --cleanup Clean up build directories (bin, include/openssl, lib, src) before starting build"
echo " --ec-nistp-64-gcc-128 Enable config option enable-ec_nistp_64_gcc_128 for 64 bit builds"
echo " -h, --help Print help (this message)"
echo " --ios-sdk=SDKVERSION Override iOS SDK version"
echo " --noparallel Disable running make with parallel jobs (make -j)"
echo " --tvos-sdk=SDKVERSION Override tvOS SDK version"
echo " -v, --verbose Enable verbose logging"
echo " --verbose-on-error Dump last 500 lines from log file if an error occurs (for Travis builds)"
echo " --version=VERSION OpenSSL version to build (defaults to ${DEFAULTVERSION})"
echo " Note: This script does not yet work with OpenSSL 1.1.0"
echo
echo "For custom configure options, set variable CONFIG_OPTIONS"
echo "For custom cURL options, set variable CURL_OPTIONS"
echo " Example: CURL_OPTIONS=\"--proxy 192.168.1.1:8080\" ./build-libssl.sh"
}
# To set "enable-ec_nistp_64_gcc_128" configuration for x64 archs set next variable to "true"
ENABLE_EC_NISTP_64_GCC_128="" #
# #
###########################################################################
# #
# Don't change anything under this line! #
# #
###########################################################################
spinner()
{
local pid=$!
@ -84,11 +93,90 @@ check_status()
fi
}
CURRENTPATH=`pwd`
DEVELOPER=`xcode-select -print-path`
IOS_MIN_SDK_VERSION="7.0"
TVOS_MIN_SDK_VERSION="9.0"
LOG_VERBOSE="$1" # Options: verbose (full output) or verbose-on-error (echo last 500 logged lines when error occurs)
# Init optional command line vars
ARCHS=""
CLEANUP=""
CONFIG_ENABLE_EC_NISTP_64_GCC_128=""
IOS_SDKVERSION=""
PARALLEL=""
LOG_VERBOSE=""
TVOS_SDKVERSION=""
VERSION=""
# Process command line arguments
for i in "$@"
do
case $i in
--archs=*)
ARCHS="${i#*=}"
shift
;;
--cleanup)
CLEANUP="true"
;;
--ec-nistp-64-gcc-128)
CONFIG_ENABLE_EC_NISTP_64_GCC_128="true"
;;
-h|--help)
echo_help
exit
;;
--ios-sdk=*)
IOS_SDKVERSION="${i#*=}"
shift
;;
--noparallel)
PARALLEL="false"
shift
;;
--tvos-sdk=*)
TVOS_SDKVERSION="${i#*=}"
shift
;;
-v|--verbose)
LOG_VERBOSE="verbose"
;;
--verbose-on-error)
LOG_VERBOSE="verbose-on-error"
;;
--version=*)
VERSION="${i#*=}"
shift
;;
*)
echo "Unknown argument: ${i}"
;;
esac
done
# Preprocess/validate OpenSSL version
if [ -n "${VERSION}" ]; then
# Verify version number format. Expected: dot notation
if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+[a-z]*$ ]]; then
echo "Unknown version number format. Examples: 1.0.2, 1.0.2h"
exit 1
fi
# Default OpenSSL version
else
VERSION="${DEFAULTVERSION}"
fi
# Set GITHUB_VERSION (version with underscores instead of dots)
GITHUB_VERSION="${VERSION//./_}"
# Determine SDK versions
if [ ! -n "${IOS_SDKVERSION}" ]; then
IOS_SDKVERSION=$(xcrun -sdk iphoneos --show-sdk-version)
fi
if [ ! -n "${TVOS_SDKVERSION}" ]; then
TVOS_SDKVERSION=$(xcrun -sdk appletvos --show-sdk-version)
fi
# Set default for ARCHS if not specified
if [ ! -n "${ARCHS}" ]; then
ARCHS="x86_64 i386 arm64 armv7s armv7 tv_x86_64 tv_arm64"
fi
# Determine number of cores for (parallel) build
BUILD_THREADS=1
@ -96,47 +184,82 @@ if [ "${PARALLEL}" != "false" ]; then
BUILD_THREADS=$(sysctl hw.ncpu | awk '{print $2}')
fi
if [ ! -d "$DEVELOPER" ]; then
echo "xcode path is not set correctly $DEVELOPER does not exist"
# Write files relative to script location and validate directory
CURRENTPATH=$(pwd)
case "${CURRENTPATH}" in
*\ * )
echo "Your path contains whitespaces, which is not supported by 'make install'."
exit 1
;;
esac
cd "${CURRENTPATH}"
# Validate Xcode Developer path
DEVELOPER=$(xcode-select -print-path)
if [ ! -d "${DEVELOPER}" ]; then
echo "Xcode path is not set correctly ${DEVELOPER} does not exist"
echo "run"
echo "sudo xcode-select -switch <xcode path>"
echo "sudo xcode-select -switch <Xcode path>"
echo "for default installation:"
echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer"
exit 1
fi
case $DEVELOPER in
case "${DEVELOPER}" in
*\ * )
echo "Your Xcode path contains whitespaces, which is not supported."
exit 1
;;
esac
case $CURRENTPATH in
*\ * )
echo "Your path contains whitespaces, which is not supported by 'make install'."
exit 1
;;
esac
# Show build options
echo
echo "Build options"
echo " OpenSSL version: ${VERSION}"
echo " Architectures: ${ARCHS}"
echo " iOS SDK: ${IOS_SDKVERSION}"
echo " tvOS SDK: ${TVOS_SDKVERSION}"
echo " Number of make threads: ${BUILD_THREADS}"
if [ -n "${CONFIG_OPTIONS}" ]; then
echo " Configure options: ${CONFIG_OPTIONS}"
fi
echo " Script directory and build location: ${CURRENTPATH}"
echo
# -e Abort script at first error, when a command exits with non-zero status (except in until or while loops, if-tests, list constructs)
# -u Attempt to use undefined variable outputs error message, and forces an exit
# -o pipefail Causes a pipeline to return the exit status of the last command in the pipe that returned a non-zero return value
set -euo pipefail
set -eo pipefail
# Download OpenSSL when not present
OPENSSL_ARCHIVE_BASE_NAME=OpenSSL_${VERSION//./_}
OPENSSL_ARCHIVE_BASE_NAME=OpenSSL_${GITHUB_VERSION}
OPENSSL_ARCHIVE_FILE_NAME=${OPENSSL_ARCHIVE_BASE_NAME}.tar.gz
if [ ! -e ${OPENSSL_ARCHIVE_FILE_NAME} ]; then
echo "Downloading ${OPENSSL_ARCHIVE_FILE_NAME}"
echo "Downloading ${OPENSSL_ARCHIVE_FILE_NAME}..."
curl ${CURL_OPTIONS} -L -O https://github.com/openssl/openssl/archive/${OPENSSL_ARCHIVE_FILE_NAME}
else
echo "Using ${OPENSSL_ARCHIVE_FILE_NAME}"
fi
mkdir -p "${CURRENTPATH}/src"
# Clean up target directories if requested and present
if [ "${CLEANUP}" == "true" ]; then
if [ -d "${CURRENTPATH}/bin" ]; then
rm -r "${CURRENTPATH}/bin"
fi
if [ -d "${CURRENTPATH}/include/openssl" ]; then
rm -r "${CURRENTPATH}/include/openssl"
fi
if [ -d "${CURRENTPATH}/lib" ]; then
rm -r "${CURRENTPATH}/lib"
fi
if [ -d "${CURRENTPATH}/src" ]; then
rm -r "${CURRENTPATH}/src"
fi
fi
# (Re-)create target directories
mkdir -p "${CURRENTPATH}/bin"
mkdir -p "${CURRENTPATH}/lib"
mkdir -p "${CURRENTPATH}/src"
# Init vars for library references
INCLUDE_DIR=""
@ -190,7 +313,7 @@ do
# Add optional enable-ec_nistp_64_gcc_128 configure option for 64 bit builds
LOCAL_CONFIG_OPTIONS="${CONFIG_OPTIONS}"
if [ "${ENABLE_EC_NISTP_64_GCC_128}" == "true" ]; then
if [ "${CONFIG_ENABLE_EC_NISTP_64_GCC_128}" == "true" ]; then
case "${ARCH}" in
*64*)
LOCAL_CONFIG_OPTIONS="${LOCAL_CONFIG_OPTIONS} enable-ec_nistp_64_gcc_128"