1#!/bin/sh 2 3# This script extracts an openssl tarball and applies all Apple-local changes. 4 5OUTDIR="$1" 6 7if [ ! -d "$OUTDIR" ]; then 8 echo "Output directory '$OUTDIR' missing" 9 exit 1 10fi 11 12if [ -d "$OUTDIR/src" ]; then 13 echo "'$OUTDIR/src' already exists" 14 exit 1 15fi 16 17pushd "$OUTDIR" > /dev/null 18OUTDIR=$( pwd -P ) 19popd > /dev/null 20 21SCRIPTDIR=$( dirname "$0" ) 22pushd "$SCRIPTDIR" > /dev/null 23SCRIPTDIR=$( pwd -P ) 24popd > /dev/null 25 26cd "$SCRIPTDIR/../patches/" || exit 1 27PATCHES=$(echo *.patch) 28 29# copy source 30 31VER=$(ls "$SCRIPTDIR"/../openssl-*.tar.gz | sort | tail -1 | sed 's|^.*/openssl-\(.*\).tar.gz|\1|') 32 33cd "$OUTDIR" || exit 1 34tar xzf "$SCRIPTDIR/../openssl-$VER.tar.gz" || exit 1 35mv "openssl-$VER" src 36cd src 37find . -type l -exec rm -f {} \; # remove symlinks; they'll be recreated as necessary by Configure 38 39echo Remove IDEA src 40 41# <rdar://problem/9396666> Code related to the IDEA encryption algorithm must be removed from OpenSSL before we ship 42find . -type f | xargs grep -l OPENSSL_NO_IDEA | egrep -v 'mk1mf.pl|Makefile' | awk '{print "unifdef -DOPENSSL_NO_IDEA -o "$0" "$0}' | sh - 43 44echo Applying patches... 45 46for patch in $PATCHES; do 47 echo " $patch" 48 patch -s -p0 < "$SCRIPTDIR/../patches/$patch" || exit 1 49done 50 51export PERL=/usr/bin/perl # make sure we use the perl in /usr/bin 52 53echo Configuring tools 54 55./Configure --openssldir="/System/Library/OpenSSL" threads shared zlib no-hw no-idea enable-rc5 enable-mdc2 enable-seed darwin64-x86_64-cc > /tmp/config.$$.out 56if [ "$?" != 0 ]; then 57 cat /tmp/config.$$.out 58 exit 1 59fi 60mv tools/c_rehash c_rehash 61 62echo Configuring i386 63 64./Configure --prefix=/usr --openssldir="/System/Library/OpenSSL" threads shared zlib no-hw no-idea enable-rc5 enable-mdc2 enable-seed darwin-i386-cc > /tmp/config.$$.out 65if [ "$?" != 0 ]; then 66 cat /tmp/config.$$.out 67 exit 1 68fi 69mv crypto/opensslconf.h i386.h 70 71echo Configuring x86_64 72 73./Configure --prefix=/usr --openssldir="/System/Library/OpenSSL" threads shared zlib no-hw no-idea enable-rc5 enable-mdc2 enable-seed darwin64-x86_64-cc > /tmp/config.$$.out 74if [ "$?" != 0 ]; then 75 cat /tmp/config.$$.out 76 exit 1 77fi 78mv crypto/opensslconf.h x86_64.h 79 80echo Merging configs 81 82diff --old-group-format='#ifdef __LP64__ 83%<#endif 84' \ 85--new-group-format='#ifndef __LP64__ 86%>#endif 87' \ 88--unchanged-group-format='%=' \ 89--changed-group-format='#ifdef __LP64__ 90%<#else 91%>#endif 92' x86_64.h i386.h > crypto/opensslconf.h 93rm -f x86_64.h i386.h 94 95# move c_rehash back 96 97mv c_rehash tools/c_rehash 98 99# we don't use these files and they just cause extraneous diffs, so remove them 100rm -f Makefile 101find . -name '*.orig' -or -name '*.bak' | xargs rm -f 102 103rm -f /tmp/config.$$.out 104echo $VER > .version 105