summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--setup/openvpn/Sources8
-rwxr-xr-xsetup/openvpn/build.zsh195
2 files changed, 130 insertions, 73 deletions
diff --git a/setup/openvpn/Sources b/setup/openvpn/Sources
index 6be04860..e2fe7bb3 100644
--- a/setup/openvpn/Sources
+++ b/setup/openvpn/Sources
@@ -1,4 +1,4 @@
-lzo -2.06 .tar.gz
-opensc -0.12.2 .tar.gz
-openssl -1.0.1c .tar.gz
-
+lzo -2.06 .tar.gz
+opensc -0.12.2 .tar.gz
+openssl -1.0.1c .tar.gz
+polarssl -1.1.4 .tgz
diff --git a/setup/openvpn/build.zsh b/setup/openvpn/build.zsh
index cc5d17bb..87c591cc 100755
--- a/setup/openvpn/build.zsh
+++ b/setup/openvpn/build.zsh
@@ -1,4 +1,4 @@
-#!/usr/bin/env zsh
+#!/bin/zsh
#
# Copyright (C) 2012 Denis Roio <jaromil@dyne.org>
#
@@ -31,11 +31,11 @@ error() { if [[ $QUIET == 0 ]]; then print "$fg[red][!]$fg[default] $1" >&2; fi
func() { if [[ $DEBUG == 1 ]]; then print "$fg[blue][D]$fg[default] $1" >&2; fi }
act() {
if [[ $QUIET == 0 ]]; then
- if [ "$1" = "-n" ]; then
- print -n "$fg_bold[white] . $fg_no_bold[default] $2" >&2;
- else
- print "$fg_bold[white] . $fg_no_bold[default] $1" >&2;
- fi
+ if [ "$1" = "-n" ]; then
+ print -n "$fg_bold[white] . $fg_no_bold[default] $2" >&2;
+ else
+ print "$fg_bold[white] . $fg_no_bold[default] $1" >&2;
+ fi
fi
}
@@ -50,85 +50,142 @@ act() {
return 0
}
-notice "OpenVPN build in ${TOPSRC}"
+os="`uname -s`"
+target="$1"
+notice "OpenVPN build on $os for $target in ${TOPSRC}"
prepare_sources() {
notice "Preparing sources"
# look for a file names "Sources", download and decompress entries
# format of file: name version compression (complete filename when merged)
{ test -r Sources } || {
- error "Sources not found, nothing to build here"
- return 1
+ error "Sources not found, nothing to build here"
+ return 1
}
for src in `cat Sources | awk '
/^#/ {next}
/^./ { print $1 ";" $2 ";" $3 }'`; do
- name="${src[(ws:;:)1]}"
- ver="${src[(ws:;:)2]}"
- arch="${src[(ws:;:)3]}"
- file="${name}${ver}${arch}"
- func "preparing source for ${name}${ver}"
- # download the file
- { test -r ${file} } || {
- act "downloading ${file}"
- wget ${REPO}/${file}
- }
- # decompress the file
- { test -r ${name} } || {
- act "decompressing ${name}"
- case $arch in
- ## BARE SOURCE
- .tar.gz) tar xfz ${file}; mv ${name}${ver} ${name} ;;
- .tar.bz2) tar xfj ${file}; mv ${name}${ver} ${name} ;;
- *) error "compression not supported: $arch"
- esac
- }
- act "${name} source ready"
+ name="${src[(ws:;:)1]}"
+ ver="${src[(ws:;:)2]}"
+ arch="${src[(ws:;:)3]}"
+ file="${name}${ver}${arch}"
+ func "preparing source for ${name}${ver}"
+
+ { test "$1" != "" } && {
+ test "$1" != "$name" } && {
+ continue }
+
+ # download the file
+ { test -r ${file} } || {
+ act "downloading ${file}"
+ curl ${REPO}/${file} -o ${file}
+ }
+ # decompress the file
+ { test -r ${name} } || {
+ act "decompressing ${name}"
+ case $arch in
+ ## BARE SOURCE
+ .tar.gz) tar xfz ${file}; mv ${name}${ver} ${name} ;;
+ .tar.bz2) tar xfj ${file}; mv ${name}${ver} ${name} ;;
+ .tgz) tar xfz ${file}; mv ${name}${ver} ${name} ;;
+ *) error "compression not supported: $arch"
+ esac
+ }
+ act "${name} source ready"
done
}
-prepare_sources
+act "Downloading sources"
-# tap windows
-{ test -r tap-windows } || { git clone https://github.com/OpenVPN/tap-windows.git }
+# git clone latest openvpn
+{ test -r openvpn } || { git clone https://github.com/OpenVPN/openvpn.git }
+
+case "$os" in
+ Darwin)
+ prepare_sources lzo
+ prepare_sources polarssl
+ ;;
+ Linux) # Cross-compile for Win32
+ prepare_sources lzo
+ prepare_sources opensc
+ prepare_sources openssl
+ # tap windows
+ { test -r tap-windows } || { git clone https://github.com/OpenVPN/tap-windows.git }
+ ;;
+esac
notice "Sources ready, now compiling..."
LOG="`pwd`/build.log"; touch ${LOG}
act "logs saved in build.log"
-{ test -r lzo/src/liblzo2.la } || { pushd lzo
- act "building LZO lib"
- ./configure --host=i586-mingw32msvc >> ${LOG}
- make >> ${LOG}; popd }
-# openssl
-{ test -r openssl/libssl.a } || {
- act "building OpenSSL lib"
- pushd openssl
- ./Configure --cross-compile-prefix=i586-mingw32msvc- mingw >> ${LOG}
- make ${LOG}; popd }
-
-# openvpn
-{ test -r openvpn } || { git clone https://github.com/OpenVPN/openvpn.git }
-pushd openvpn
-act "building latest OpenVPN"
-{ test -r configure } || {
- sed -i -e 's/-municode//' src/openvpn/Makefile.am
- autoreconf -i >> ${LOG}
-}
-CFLAGS="-I/usr/i586-mingw32msvc/include/ddk -D_WIN32_WINNT=0x0501" \
-LZO_LIBS="${TOPSRC}/lzo/src/liblzo2.la" \
-LZO_CFLAGS="-I${TOPSRC}/lzo/include" \
-TAP_CFLAGS="-I${TOPSRC}/tap-windows/src" \
-OPENSSL_SSL_CFLAGS="-I${TOPSRC}/openssl/include" \
-OPENSSL_CRYPTO_CFLAGS="-I${TOPSRC}/openssl/crypto" \
-OPENSSL_SSL_LIBS="${TOPSRC}/openssl/libssl.a" \
-OPENSSL_CRYPTO_LIBS="${TOPSRC}/openssl/libcrypto.a" \
-./configure --host=i586-mingw32msvc >> ${LOG}
-make >> ${LOG}
-popd
-notice "Done."
-act "If OpenVPN build reports a final error on linkage, it might be due to a libtool bug"
-act "(something like undefined reference to `_WinMain@16')"
-act "You need to go inside openvpn/src/openvpn and issue the last compile line manually"
-act "adding an flat '-shared' at the end of it, then do 'cp .libs/openvpn.exe .'"
-act "Happy hacking."
+case "$target" in
+ osx)
+ { test -r polarssl/library/libpolarssl.a } || {
+ act "building PolarSSL..."
+ pushd polarssl
+ CC=clang cmake . >> ${LOG}
+ make -C library clean
+ cat CMakeCache.txt | awk '
+/^CMAKE_C_COMPILER/ { print "CMAKE_C_COMPILER:FILEPATH=/usr/bin/clang"; next }
+/^CMAKE_BUILD_TYPE/ { print $1 "Release"; next }
+/^CMAKE_C_FLAGS:STRING/ { print "CMAKE_C_FLAGS:STRING=-arch x86_64 -arch i386"; next }
+{ print $0 }
+' > CMakeCache.leap
+ cp CMakeCache.leap CMakeCache.txt
+ make -C library >> ${LOG}
+ popd
+ act "done."
+ }
+
+ act "building OpenVPN"
+ pushd openvpn
+ CC=clang CFLAGS="-arch x86_64 -arch i386" \
+ LZO_LIBS="/opt/local/lib/liblzo2.a" LZO_CFLAGS="-I/opt/local/include" \
+ POLARSSL_CFLAGS="-I${TOPSRC}/polarssl/include" \
+ POLARSSL_LIBS="${TOPSRC}/polarssl/library/libpolarssl.a" \
+ ./configure --with-crypto-library=polarssl >> ${LOG}
+ make src/openvpn/openvpn
+ popd
+ act "done."
+ ;;
+
+ win32)
+ { test -r lzo/src/liblzo2.la } || { pushd lzo
+ act "building LZO lib"
+ ./configure --host=i586-mingw32msvc >> ${LOG}
+ make >> ${LOG}; popd }
+ # openssl
+ { test -r openssl/libssl.a } || {
+ act "building OpenSSL lib"
+ pushd openssl
+ ./Configure --cross-compile-prefix=i586-mingw32msvc- mingw >> ${LOG}
+ make ${LOG}; popd }
+
+ pushd openvpn
+ act "building latest OpenVPN"
+ { test -r configure } || {
+ sed -i -e 's/-municode//' src/openvpn/Makefile.am
+ autoreconf -i >> ${LOG}
+ }
+ CFLAGS="-I/usr/i586-mingw32msvc/include/ddk -D_WIN32_WINNT=0x0501" \
+ LZO_LIBS="${TOPSRC}/lzo/src/liblzo2.la" \
+ LZO_CFLAGS="-I${TOPSRC}/lzo/include" \
+ TAP_CFLAGS="-I${TOPSRC}/tap-windows/src" \
+ OPENSSL_SSL_CFLAGS="-I${TOPSRC}/openssl/include" \
+ OPENSSL_CRYPTO_CFLAGS="-I${TOPSRC}/openssl/crypto" \
+ OPENSSL_SSL_LIBS="${TOPSRC}/openssl/libssl.a" \
+ OPENSSL_CRYPTO_LIBS="${TOPSRC}/openssl/libcrypto.a" \
+ ./configure --host=i586-mingw32msvc >> ${LOG}
+ make >> ${LOG}
+ popd
+
+ act "If OpenVPN build reports a final error on linkage, it might be due to a libtool bug"
+ act "(something like undefined reference to _WinMain@16)"
+ act "You need to go inside openvpn/src/openvpn and issue the last compile line manually"
+ act "adding an flat '-shared' at the end of it, then do 'cp .libs/openvpn.exe .'"
+ act "Happy hacking."
+ ;;
+ *)
+ error "Unknown target: $target"
+ ;;
+esac \ No newline at end of file