Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified checkout system for Git #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# build-openssl-android
A simple bash script for building openssl android.
A simple shell script for building openssl android.

Now that OpenSSL moved from their webpage to a GitHub repository the previous script from @xvtom doesn't work anymore, now we have to deal with tags so basically this script will download the master and then it will try to checkout the tag that you specify (1.0.2h otherwise).


All comments and help are welcome.


Tested on OSX 10.11.5 (El Captain)


## Setup Android Development on Mac OS X

Expand All @@ -24,24 +33,17 @@ source ~/.bashrc
```

## Usage: `./build-openssl-android.sh <version>`
* Build openssl-1.0.1j
* Build openssl-1.0.2h

```!bash
./build-openssl-android.sh 1.0.1j
./build-openssl-android.sh 1_0_2h
```

* Build openssl-1.0.2-beta3

```!bash
./build-openssl-android.sh 1.0.2-beta3
```

* Build for Android-L

```!bash
# Install Android-L sdk using `android` command first
_ANDROID_API="android-L" ./build-openssl-android.sh
./build-openssl-android.sh 1_0_2-beta3
```

## Reference
* http://wiki.openssl.org/index.php/Android
* http://wiki.openssl.org/index.php/Android
171 changes: 123 additions & 48 deletions build-openssl-android.sh
Original file line number Diff line number Diff line change
@@ -1,55 +1,130 @@
#!/bin/bash -e

OPENSSL_VERSION=${1:-"1.0.1j"}
OPENSSL_TARBALL=openssl-${OPENSSL_VERSION}.tar.gz
#
#This shell script will download the env setup for android as well the source code from GitHub
#
#Usage ./build-openssl.sh 1_0_2h
#
#
TAG_NAME=${1:-"1_0_2h"}
OPENSSL_VERSION=${TAG_NAME}
OPENSSL_DIR=openssl-${OPENSSL_VERSION}
OPENSSL_BUILD_LOG=openssl-${OPENSSL_VERSION}.log
today=`date +%Y-%m-%d.%H_%M_%S`
OPENSSL_BUILD_LOG=openssl-${OPENSSL_VERSION}-${today}.log

reset=`tput sgr0`
red=`tput setaf 1`
green=`tput setaf 2`

# Download setenv_android.sh
if [ ! -e setenv-android.sh ]; then
echo "Downloading setenv_android.sh..."
curl -# -o setenv-android.sh http://wiki.openssl.org/images/7/70/Setenv-android.sh
chmod a+x setenv-android.sh
fi

# Download openssl source
if [ ! -e ${OPENSSL_TARBALL} ]; then
echo "Downloading openssl-${OPENSSL_VERSION}.tar.gz..."
curl -# -O http://www.openssl.org/source/${OPENSSL_TARBALL}
fi

# Verify the source file
if [ ! -e ${OPENSSL_TARBALL}.sha1 ]; then
echo -n "Verifying... "
curl -o ${OPENSSL_TARBALL}.sha1 -s http://www.openssl.org/source/${OPENSSL_TARBALL}.sha1
CHECKSUM=`cat ${OPENSSL_TARBALL}.sha1`
ACTUAL=`shasum ${OPENSSL_TARBALL} | awk '{ print \$1 }'`
if [ "x$ACTUAL" == "x$CHECKSUM" ]; then
echo "OK"
downloadingSetEnv(){
if [ ! -e setenv-android.sh ]; then
echo "${green}Downloading setenv_android.sh...${reset}"
curl -# -o setenv-android.sh https://wiki.openssl.org/images/7/70/Setenv-android.sh
chmod a+x setenv-android.sh
fi
}

validateSettings(){
if [ -z "$ANDROID_NDK_ROOT" ] || [ ! -d "$ANDROID_NDK_ROOT" ]; then
echo "${red}ANDROID_NDK_ROOT is not a valid path, please declare a valid path${reset}"
exit 1
fi

validateGIT
}

#Checking if GIT is available
validateGIT(){
hash git 2>/dev/null || { echo >&2 "${red}I require git but it's not installed. Aborting.${reset}"; exit 1; }
}


# Download openssl source from git
cloneRepository(){
OUT=0
if [ ! -d "$OPENSSL_DIR" ]; then
echo "${green}Cloning Openssl v${OPENSSL_VERSION}...${reset}"
git clone git://git.openssl.org/openssl.git ${OPENSSL_DIR}
OUT=$?
else
echo "${green}A folder for the given Openssl version already exists: ${OPENSSL_DIR} ${reset}"
fi

if [ $OUT -gt 0 ];then
echo "${red}Error during Cloning process ${reset}"
removeDir
exit 1
else
echo "FAIL"
rm -f ${OPENSSL_TARBALL}
rm -f ${OPENSSL_TARBALL}.sha1
return 1
androidSetup
cd ${OPENSSL_DIR}
windowsSetup
fi
fi

# Untar the file
if [ ! -e ${OPENSSL_DIR} ]; then
tar zxf ${OPENSSL_TARBALL}
fi

# Setup the environment
. ./setenv-android.sh

# Build
echo "Compiling..."
cd ${OPENSSL_DIR}
perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
./config shared -no-ssl2 -no-ssl3 -no-comp -no-hw -no-engine --openssldir=/usr/local/ssl/$ANDROID_API > ../${OPENSSL_BUILD_LOG}
make depend >> ../${OPENSSL_BUILD_LOG}
make all >> ../${OPENSSL_BUILD_LOG}

# Installing
echo "Installing..."
sudo -E make install CC=$ANDROID_TOOLCHAIN/arm-linux-androideabi-gcc RANLIB=$ANDROID_TOOLCHAIN/arm-linux-androideabi-ranlib >> ../${OPENSSL_BUILD_LOG}
}


#in case this a windows setup we need to double confirm this
windowsSetup(){
git config core.autocrlf false
git config core.eol lf
git checkout .
}

androidSetup(){
echo "${green}Setting up android build environment...${reset}"
. ./setenv-android.sh
}


removeDir(){
rm -rf $OPENSSL_DIR
}

#Checking specific TAG/Version of Openssl
verifyTag(){
echo "${green}Checking tag ${TAG_NAME}...${reset}"
git ls-remote --tags 2>/dev/null | grep $TAG_NAME 1>/dev/null
if [ "$?" == 0 ]; then
echo "${green}Git tag $TAG_NAME exists.${reset}"
else
echo "${red}Git tag $TAG_NAME does not exist.${reset}"
cd ..
removeDir
exit 1
fi
}


checkoutTag(){
verifyTag
echo "${green}Checking out the specific TAG (${TAG_NAME})...${reset}"
#we should be already inside openssl dir ($OPENSSL_DIR)
git checkout tags/OpenSSL_${TAG_NAME}
}


# Building for android
build(){
echo "${green}Compiling Openssl (${OPENSSL_VERSION})...${reset}"
perl -pi -e 's/install: all install_docs install_sw/install: install_docs install_sw/g' Makefile.org
./config shared -no-ssl2 -no-ssl3 -no-comp -no-hw -no-engine --openssldir=/usr/local/ssl/$ANDROID_API > ../${OPENSSL_BUILD_LOG}
make depend >> ../${OPENSSL_BUILD_LOG}
make all >> ../${OPENSSL_BUILD_LOG}
}

# Installing in the toolchain of the ANDROID_NDK_ROOT
install(){
echo "${green}Installing in Android NDK Toolchain PATH : ${ANDROID_TOOLCHAIN} ${reset}"
sudo -E make install CC=$ANDROID_TOOLCHAIN/arm-linux-androideabi-gcc RANLIB=$ANDROID_TOOLCHAIN/arm-linux-androideabi-ranlib >> ../${OPENSSL_BUILD_LOG}
PHYS_DIR=`pwd -P`
echo "${green}All done, log can be view it at : ${PHYS_DIR}/${OPENSSL_BUILD_LOG} ${reset}"
}

#Main process
validateSettings
downloadingSetEnv
cloneRepository
checkoutTag
build
install
exit 0
Loading