From 1967594392a3641f695c3dba569600f90d17e115 Mon Sep 17 00:00:00 2001 From: Anton Tieleman Date: Sun, 18 Sep 2016 16:14:11 +0200 Subject: [PATCH 1/3] Specify build configuration with command line parameters - Added help message - Command line arguments processing - Retrieve latest version from 1.0.2 branch in case no version is specified - Use script location as working dir - Add summary of build options - Clean up directories before build --- build-libssl.sh | 219 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 176 insertions(+), 43 deletions(-) diff --git a/build-libssl.sh b/build-libssl.sh index eb4ee32..599a7ad 100755 --- a/build-libssl.sh +++ b/build-libssl.sh @@ -18,31 +18,38 @@ # 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" +DEFAULTBRANCH="1.0.2" # Default branch in case no version or branch 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 " --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 latest version in branch ${DEFAULTBRANCH}" + 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 +91,100 @@ 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="" +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 + ;; + --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 + # Default branch or user provided (in latter case verify number format) + # For future use (when adding 1.1.0), so the user can select a default branch + BRANCH="${DEFAULTBRANCH}" + + # Determine latest version of selected branch + echo "Checking latest version of ${BRANCH} branch on GitHub..." + GITHUB_VERSION=$(curl ${CURL_OPTIONS} -Ls https://github.com/openssl/openssl/releases.atom | grep "OpenSSL_${BRANCH//./_}" | head -1 | sed -E "s|^.*title>OpenSSL_(${BRANCH//./_}[a-z]*)</title.*$|\1|g") + + # Verify result + if [ -z "${GITHUB_VERSION}" ]; then + echo "Could not determine latest version, please check https://github.com/openssl/openssl/releases and use --version option" + exit 1 + fi + + VERSION="${GITHUB_VERSION//_/.}" +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 +192,84 @@ 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=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) +case "${CURRENTPATH}" in + *\ * ) + echo "Your path contains whitespaces, which is not supported by 'make install'." + exit 1 + ;; +esac +if [[ "${CURRENTPATH}" == "/" || "${CURRENTPATH}" == "/usr" || "${CURRENTPATH}" == "/usr/local" ]]; then + echo "This script should not be executed from directory ${CURRENTPATH}" + exit 1 +fi +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 present +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 + +# (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 +323,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" From 98738414bb8ecdc9e1484214bf38986aa0075757 Mon Sep 17 00:00:00 2001 From: Anton Tieleman <git@oneton.nl> Date: Sun, 18 Sep 2016 16:15:39 +0200 Subject: [PATCH 2/3] Command line options for Travis build. Added no parallel due to PR #115 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index afc7680..b34d9e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 From 1d9c39286474cc64db8bfcb7704b7d2f24203f78 Mon Sep 17 00:00:00 2001 From: Anton Tieleman <git@oneton.nl> Date: Sun, 18 Sep 2016 17:34:44 +0200 Subject: [PATCH 3/3] Review comments - Maintain fixed default version in script - Add --cleanup option for concious cleanup before building and remove directory-check - Remove (for now) option to build latest version --- build-libssl.sh | 58 ++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/build-libssl.sh b/build-libssl.sh index 599a7ad..c8cda01 100755 --- a/build-libssl.sh +++ b/build-libssl.sh @@ -22,7 +22,7 @@ # -u Attempt to use undefined variable outputs error message, and forces an exit set -u -DEFAULTBRANCH="1.0.2" # Default branch in case no version or branch is specified +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 @@ -36,6 +36,7 @@ echo_help() 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" @@ -43,7 +44,8 @@ echo_help() 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 latest version in branch ${DEFAULTBRANCH}" + 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" @@ -93,6 +95,7 @@ check_status() # Init optional command line vars ARCHS="" +CLEANUP="" CONFIG_ENABLE_EC_NISTP_64_GCC_128="" IOS_SDKVERSION="" PARALLEL="" @@ -108,6 +111,9 @@ case $i in ARCHS="${i#*=}" shift ;; + --cleanup) + CLEANUP="true" + ;; --ec-nistp-64-gcc-128) CONFIG_ENABLE_EC_NISTP_64_GCC_128="true" ;; @@ -153,21 +159,7 @@ if [ -n "${VERSION}" ]; then # Default OpenSSL version else - # Default branch or user provided (in latter case verify number format) - # For future use (when adding 1.1.0), so the user can select a default branch - BRANCH="${DEFAULTBRANCH}" - - # Determine latest version of selected branch - echo "Checking latest version of ${BRANCH} branch on GitHub..." - GITHUB_VERSION=$(curl ${CURL_OPTIONS} -Ls https://github.com/openssl/openssl/releases.atom | grep "<title>OpenSSL_${BRANCH//./_}" | head -1 | sed -E "s|^.*title>OpenSSL_(${BRANCH//./_}[a-z]*)</title.*$|\1|g") - - # Verify result - if [ -z "${GITHUB_VERSION}" ]; then - echo "Could not determine latest version, please check https://github.com/openssl/openssl/releases and use --version option" - exit 1 - fi - - VERSION="${GITHUB_VERSION//_/.}" + VERSION="${DEFAULTVERSION}" fi # Set GITHUB_VERSION (version with underscores instead of dots) @@ -193,17 +185,13 @@ if [ "${PARALLEL}" != "false" ]; then fi # Write files relative to script location and validate directory -CURRENTPATH=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) +CURRENTPATH=$(pwd) case "${CURRENTPATH}" in *\ * ) echo "Your path contains whitespaces, which is not supported by 'make install'." exit 1 ;; esac -if [[ "${CURRENTPATH}" == "/" || "${CURRENTPATH}" == "/usr" || "${CURRENTPATH}" == "/usr/local" ]]; then - echo "This script should not be executed from directory ${CURRENTPATH}" - exit 1 -fi cd "${CURRENTPATH}" # Validate Xcode Developer path @@ -252,18 +240,20 @@ else echo "Using ${OPENSSL_ARCHIVE_FILE_NAME}" fi -# Clean up target directories if present -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" +# 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