Skip to content

Commit

Permalink
Extend PolarSSL build scripts to Apple family.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesyonan committed May 29, 2012
1 parent 1a61341 commit 350558d
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 26 deletions.
3 changes: 1 addition & 2 deletions openvpn/polarssl/ssl/sslctx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ namespace openvpn {

// init SSL object
ssl = new ssl_context;
std::memset(ssl, 0, sizeof(ssl));
status = ssl_init(ssl);
if (status < 0)
throw PolarSSLException("error in ssl_init", status);
Expand All @@ -321,7 +320,7 @@ namespace openvpn {

// allocate session object, but don't support SSL-level session resume
sess = new ssl_session;
std::memset(sess, 0, sizeof(sess));
std::memset(sess, 0, sizeof(*sess));
ssl_set_session(ssl, 0, 0, sess);

// set list of allowed ciphersuites
Expand Down
2 changes: 1 addition & 1 deletion polarssl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 2.6)
project(POLARSSL C)

if(CMAKE_COMPILER_IS_GNUCC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -O3 -Wall -W -Wdeclaration-after-statement")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} $ENV{LIB_FPIC} $ENV{LIB_OPT_LEVEL} $ENV{PLATFORM_FLAGS} -Wall -W -Wdeclaration-after-statement")
endif(CMAKE_COMPILER_IS_GNUCC)

if(OPENSSL_DIR)
Expand Down
4 changes: 4 additions & 0 deletions polarssl/apple.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# specify the cross compiler
SET(CMAKE_C_COMPILER clang)
SET(CMAKE_CXX_COMPILER clang++)
SET(CMAKE_COMPILER_IS_GNUCC 1)
23 changes: 20 additions & 3 deletions polarssl/build-mini-openssl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@ if [ -z "$OPENSSL_DIR" ]; then
echo OPENSSL_DIR must be defined
exit 1
fi

if [ "$APPLE_FAMILY" = "1" ] && [ -z "$GCC_CMD" ]; then
GCC_CMD=clang
fi

if [ "$APPLE_FAMILY" = "1" ]; then
NM_FLAGS=-P
BSD_SYMBOLS="1"
VISIBILITY="-fvisibility=hidden"
else
NM_FLAGS=-f posix
BSD_SYMBOLS="0"
VISIBILITY=""
fi

[ -z "$NM_CMD" ] && NM_CMD=nm
[ -z "$AR_CMD" ] && AR_CMD=ar
[ -z "$GCC_CMD" ] && GCC_CMD=gcc
Expand All @@ -20,15 +35,17 @@ cd $OPENSSL_DIR
cd lib
rm -rf tmp
mkdir tmp
$NM_CMD -f posix libcrypto.a >tmp/nm-file
$NM_CMD $NM_FLAGS libcrypto.a >tmp/nm-file
echo "NOTE: on BSD systems, don't worry about any 'no name list' errors above"
cd tmp
python $OVPN3_DIR/scripts/sym.py $PD/$1 nm-file $AR_CMD ../libcrypto.a libminicrypto.a buildmini ../mini-undef.sh
python $OVPN3_DIR/scripts/sym.py $PD/$1 nm-file $AR_CMD ../libcrypto.a libminicrypto.a buildmini ../mini-undef.sh $BSD_SYMBOLS
. buildmini

# need any special initialization?
. ../mini-undef.sh
if [ "$SYM_UNDEF_OPENSSL_ia32cap_P" ] && [ "$SYM_UNDEF_OPENSSL_cpuid_setup" ]; then
$GCC_CMD -O3 -fPIC -c $PD/intel_cpu.c
echo BUILDING STUB intel_cpu.c
$GCC_CMD $VISIBILITY $LIB_OPT_LEVEL $LIB_FPIC -c $PD/intel_cpu.c
$AR_CMD rs libminicrypto.a intel_cpu.o
fi

Expand Down
14 changes: 10 additions & 4 deletions polarssl/build-polarssl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Examples:
# AES_NI=1 $OVPN3_DIR/polarssl/build-polarssl
# AES_NI=1 ENABLE_TESTING=1 $OVPN3_DIR/polarssl/build-polarssl
# AES_NI=1 ENABLE_TESTING=1 VERBOSE=1 $OVPN3_DIR/polarssl/build-polarssl
# TARGET=android $OVPN3_DIR/polarssl/build-polarssl
#
# when TARGET is specified, use $TARGET.cmake as toolchain file
Expand All @@ -14,8 +14,8 @@ fi

# extract the PolarSSL source
PD=$OVPN3_DIR/polarssl
POLARSSL=polarssl-1.1.1
DIST=polarssl
POLARSSL=polarssl-1.1.3
DIST=polarssl-$PLATFORM
rm -rf $POLARSSL $DIST
mkdir $DIST
tar xfz $DL/$POLARSSL-gpl.tgz
Expand Down Expand Up @@ -52,6 +52,8 @@ fi
OPT_TARGET=""
if [ "$TARGET" ]; then
OPT_TARGET="-DCMAKE_TOOLCHAIN_FILE=$PD/$TARGET.cmake"
elif [ "$APPLE_FAMILY" = "1" ]; then
OPT_TARGET="-DCMAKE_TOOLCHAIN_FILE=$PD/apple.cmake"
fi

# combine options
Expand All @@ -62,7 +64,11 @@ echo OPTIONS $OPT
pwd
cd ../$DIST
cmake $OPT ../$POLARSSL
make
if [ "$VERBOSE" = "1" ]; then
make VERBOSE=1
else
make
fi

# test it
if [ "$ENABLE_TESTING" = "1" ]; then
Expand Down
26 changes: 13 additions & 13 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,9 @@ LIBS=""
LIBDIRS=""
EXTRA_SRC_OBJ=""

# building on Mac OS X?
if [ "$PLATFORM" = "osx" ] || [ "$PLATFORM" = "ios" ] || [ "$PLATFORM" = "iossim" ]; then
MAC=1
# building on Mac OS X for osx, ios, or iossim?
if [ "$APPLE_FAMILY" = "1" ]; then
[ -z "$CLANG" ] && CLANG=1
else
MAC=0
fi

# clang support
Expand All @@ -57,7 +54,7 @@ FLAGS="-Wall"
FLAGS="$FLAGS -Wno-sign-compare -Wno-unused-parameter"

# Mac flags
if [ "$MAC" = "1" ]; then
if [ "$APPLE_FAMILY" = "1" ]; then
CPPFLAGS="$CPPFLAGS -DBOOST_ASIO_DISABLE_KQUEUE"
fi

Expand All @@ -74,10 +71,12 @@ if [ "$PSSL" = "1" ]; then
fi

# OpenSSL
if [ "$MAC" = "1" ]; then
if [ "$APPLE_FAMILY" = "1" ]; then
# On Mac, only link with OpenSSL if OSSL is defined.
# On other platforms, always link with OpenSSL.
if [ "$SSL_BOTH" = "1" ]; then
# On other platforms, usually link with OpenSSL.
if [ "$PSSL" = "1" ]; then
true
elif [ "$SSL_BOTH" = "1" ]; then
CPPFLAGS="$CPPFLAGS -DUSE_APPLE_SSL -DUSE_OPENSSL"
LIBS="$LIBS -lcrypto -lssl -framework Security"
[ "$CLANG" = "1" ] && FLAGS="$FLAGS -Wno-deprecated-declarations"
Expand All @@ -91,10 +90,6 @@ if [ "$MAC" = "1" ]; then
LIBS="$LIBS -framework Security"
fi
fi

# Include other Mac frameworks
# -framework CoreServices
LIBS="$LIBS -framework CoreFoundation"
else
if [ "$NOSSL" != "1" ]; then
CPPFLAGS="$CPPFLAGS -DUSE_OPENSSL"
Expand All @@ -106,6 +101,11 @@ if [ "$OPENSSL_DIR" ] && [ "$NOSSL" != "1" ]; then
LIBDIRS="$LIBDIRS -L$OPENSSL_DIR/lib"
fi

# Apple libs
if [ "$APPLE_FAMILY" = "1" ]; then
LIBS="$LIBS -framework CoreFoundation"
fi

# boost
[ -z "$BOOST_STAGE" ] && BOOST_STAGE="stage/lib"
CPPFLAGS="$CPPFLAGS -I$BOOST_DIR"
Expand Down
16 changes: 16 additions & 0 deletions scripts/mac/build-openssl-small
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e
export OPENSSL=openssl-1.0.1c
export DIST=$(pwd)/openssl-$PLATFORM
rm -rf $OPENSSL $DIST
tar xfz ~/Downloads/$OPENSSL.tar.gz
cd $OPENSSL
NO_FLAGS="no-engine no-hw no-ssl2 no-ssl3 no-zlib no-rc2 no-idea no-des no-cast no-md2 no-mdc2 no-ripemd no-rc5 no-camellia no-seed no-krb5 no-socks no-ecdsa no-ec no-ecdh no-md2 no-md4 no-whirlpool no-dsa no-cms no-jpake no-gost"
./Configure $OPENSSL_TARGET no-shared threads no-idea no-mdc2 no-rc5 $NO_FLAGS --prefix=$DIST
sed -i "" -e "s|-O3|-O3 $PLATFORM_FLAGS|" Makefile
make CC="clang" build_libs
touch apps/openssl
touch openssl.pc
touch libcrypto.pc
touch libssl.pc
make install_sw
4 changes: 3 additions & 1 deletion vars-android
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export BOOST_DIR=$HOME/src/android/boost_1_48_0
export OPENSSL_DIR=$HOME/src/android/openssl
export SNAPPY_DIR=$HOME/src/android/snappy
export POLARSSL_DIR=$HOME/src/android/polarssl
export POLARSSL_DIR=$HOME/src/android/polarssl-android
export OVPN3_DIR=$HOME/src/ovpn3
export PLATFORM=android
export PATH="$OVPN3_DIR/scripts:$PATH"
Expand All @@ -10,3 +10,5 @@ export GCC_CMD=arm-linux-androideabi-gcc
export NM_CMD=arm-linux-androideabi-nm
export AR_CMD=arm-linux-androideabi-ar
export STRIP_CMD=arm-linux-androideabi-strip
export LIB_OPT_LEVEL="-O3"
export LIB_FPIC="-fPIC"
2 changes: 2 additions & 0 deletions vars-arm-cross
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export PLATFORM=linux-arm
export PATH="$OVPN3_DIR/scripts:$PATH"
export GPP_CMD=arm-linux-gnueabi-g++-4.6
export STRIP_CMD=arm-linux-gnueabi-strip
export LIB_OPT_LEVEL="-O3"
export LIB_FPIC="-fPIC"
4 changes: 4 additions & 0 deletions vars-ios
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export BOOST_DIR=$HOME/src/boost_1_49_0
export OVPN3_DIR=$HOME/src/ovpn3
export PLATFORM=ios
export APPLE_FAMILY=1
export BOOST_STAGE=stage-$PLATFORM/lib
export OPENSSL_DIR=$HOME/src/mac/openssl-$PLATFORM
export IOS_SDK="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk"
export PLATFORM_FLAGS="-arch armv7 -miphoneos-version-min=5.0 -isysroot $IOS_SDK"
export LIB_OPT_LEVEL="-O3"
export LIB_FPIC=""
export PATH="$OVPN3_DIR/scripts:$PATH"
11 changes: 11 additions & 0 deletions vars-iossim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export BOOST_DIR=$HOME/src/boost_1_49_0
export OVPN3_DIR=$HOME/src/ovpn3
export PLATFORM=iossim
export APPLE_FAMILY=1
export BOOST_STAGE=stage-$PLATFORM/lib
export OPENSSL_DIR=$HOME/src/mac/openssl-$PLATFORM
export IOS_SDK="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk"
export PLATFORM_FLAGS="-arch i386 -miphoneos-version-min=5.0 -isysroot $IOS_SDK"
export LIB_OPT_LEVEL="-O3"
export LIB_FPIC=""
export PATH="$OVPN3_DIR/scripts:$PATH"
4 changes: 3 additions & 1 deletion vars-linux
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export BOOST_DIR=$HOME/boost_1_49_0
export SNAPPY_DIR=$HOME/snappy
export LZ4_DIR=$HOME/lz4
export POLARSSL_DIR=$HOME/polarssl
export POLARSSL_DIR=$HOME/polarssl-linux
export JAVA_DIR=/usr/lib/jvm/java-7-openjdk-amd64
export OVPN3_DIR=$HOME/ovpn3
export PLATFORM=linux
export LIB_OPT_LEVEL="-O3"
export LIB_FPIC=""
export LD_LIBRARY_PATH="$BOOST_DIR/stage/lib:$SNAPPY_DIR/lib:$OVPN3_DIR/javacli"
export PATH="$OVPN3_DIR/scripts:$JAVA_DIR/bin:$PATH"
2 changes: 2 additions & 0 deletions vars-linux-openssl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ export LZ4_DIR=$HOME/lz4
export OPENSSL_DIR=$HOME/openssl-dist
export OVPN3_DIR=$HOME/ovpn3
export PLATFORM=linux
export LIB_OPT_LEVEL="-O3"
export LIB_FPIC="-fPIC"
export LD_LIBRARY_PATH="$BOOST_DIR/stage/lib:$SNAPPY_DIR/lib:$OPENSSL_DIR/lib"
export PATH="$OVPN3_DIR/scripts:$PATH"
8 changes: 7 additions & 1 deletion vars-mac → vars-osx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ export BOOST_DIR=$HOME/src/boost_1_49_0
export SNAPPY_DIR=$HOME/src/snappy
export OVPN3_DIR=$HOME/src/ovpn3
export PLATFORM=osx
export APPLE_FAMILY=1
export BOOST_STAGE=stage-$PLATFORM/lib
export OPENSSL_DIR=$HOME/src/mac/openssl-$PLATFORM
export OPENSSL_TARGET=darwin64-x86_64-cc
export POLARSSL_DIR=$HOME/src/mac/polarssl-$PLATFORM
export PLATFORM_FLAGS="-arch x86_64"
export LIB_OPT_LEVEL="-O3"
export LIB_FPIC=""
export PATH="$OVPN3_DIR/scripts:$PATH"
export PLATFORM_FLAGS=""
#export DYLD_LIBRARY_PATH="$BOOST_DIR/stage/lib:$SNAPPY_DIR/lib"
5 changes: 5 additions & 0 deletions vars-reset
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ unset IOS_SDK
unset BOOST_DIR
unset BOOST_STAGE
unset OPENSSL_DIR
unset OPENSSL_TARGET
unset SNAPPY_DIR
unset LZ4_DIR
unset JAVA_DIR
unset OVPN3_DIR
unset PLATFORM
unset GPP_CMD
unset GCC_CMD
unset STRIP_CMD
unset LD_LIBRARY_PATH
unset APPLE_FAMILY
unset LIB_OPT_LEVEL
unset LIB_FPIC

0 comments on commit 350558d

Please sign in to comment.