-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jobs
authored and
jobs
committed
Apr 20, 2017
0 parents
commit 3bfb139
Showing
3 changed files
with
337 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#!/bin/bash | ||
|
||
# Bundle config | ||
: ${BUNDLE:=} | ||
: ${DOWNLOAD_URL:=} | ||
: ${LIBRARY:=libsecp256k1.a} | ||
|
||
# framework config | ||
: ${FRAMEWORK_NAME:=secp256k1} | ||
: ${FRAMEWORK_VERSION:=A} | ||
: ${FRAMEWORK_CURRENT_VERSION:=1.0.0} | ||
: ${FRAMEWORK_IDENTIFIER:=org.secp256k1lib} | ||
|
||
# iphone SDK version | ||
: ${IPHONE_SDKVERSION:=9.1} | ||
|
||
source shared.sh | ||
|
||
untarLzippedBundle() { | ||
echo "Untar bundle to $SRC_DIR..." | ||
tar -zxvf secp256k1-1.0.0.tar.gz -C $SRC_DIR | ||
doneSection | ||
} | ||
|
||
exportConfig() { | ||
echo "Export configuration..." | ||
IOS_ARCH=$1 | ||
if [ "$IOS_ARCH" == "i386" ]; then | ||
IOS_SYSROOT=$XCODE_SIMULATOR_SDK | ||
else | ||
IOS_SYSROOT=$XCODE_DEVICE_SDK | ||
fi | ||
CFLAGS="-arch $IOS_ARCH -fPIC -g -Os -pipe --sysroot=$IOS_SYSROOT" | ||
if [ "$IOS_ARCH" == "armv7s" ] || [ "$IOS_ARCH" == "armv7" ]; then | ||
CFLAGS="$CFLAGS -mios-version-min=6.0" | ||
else | ||
CFLAGS="$CFLAGS -mios-version-min=7.0" | ||
fi | ||
CXXFLAGS=$CFLAGS | ||
CPPFLAGS=$CFLAGS | ||
CC_FOR_BUILD=/usr/bin/clang | ||
export CC=clang | ||
export CXX=clang++ | ||
export CFLAGS | ||
export CXXFLAGS | ||
export IOS_SYSROOT | ||
export CC_FOR_BUILD | ||
export PATH="$XCODE_TOOLCHAIN_USR_BIN":"$XCODE_USR_BIN":"$ORIGINAL_PATH" | ||
echo "IOS_ARC: $IOS_ARCH" | ||
echo "CC: $CC" | ||
echo "CXX: $CXX" | ||
echo "LDFLAGS: $LDFLAGS" | ||
echo "CC_FOR_BUILD: $CC_FOR_BUILD" | ||
echo "CFLAGS: $CFLAGS" | ||
echo "CXXFLAGS: $CXXFLAGS" | ||
echo "IOS_SYSROOT: $IOS_SYSROOT" | ||
echo "PATH: $PATH" | ||
doneSection | ||
} | ||
|
||
moveHeadersToFramework() { | ||
echo "Copying includes to $FRAMEWORK_BUNDLE/Headers/..." | ||
cp -r $BUILD_DIR/armv7/include/*.h $FRAMEWORK_BUNDLE/Headers/ | ||
doneSection | ||
} | ||
|
||
compileSrcForArch() { | ||
local buildArch=$1 | ||
configureForArch $buildArch | ||
echo "Building source for architecture $buildArch..." | ||
( cd $SRC_DIR/$FRAMEWORK_NAME-$FRAMEWORK_CURRENT_VERSION; \ | ||
echo "Calling make clean..." | ||
make clean; \ | ||
echo "Calling make check..." | ||
make check; \ | ||
echo "Calling make..." | ||
make; | ||
echo "Calling make install..." | ||
make install; \ | ||
echo "Place libgmp.a for lipoing..." ) | ||
mv $BUILD_DIR/$buildArch/lib/$LIBRARY $BUILD_DIR/$buildArch | ||
doneSection | ||
} | ||
|
||
configureForArch() { | ||
local buildArch=$1 | ||
cleanUpSrc | ||
createDirs | ||
untarLzippedBundle | ||
echo "Configure for architecture $buildArch..." | ||
( cd $SRC_DIR/$FRAMEWORK_NAME-$FRAMEWORK_CURRENT_VERSION; \ | ||
./configure --prefix $BUILD_DIR/$buildArch --disable-shared --host="none-apple-darwin" --enable-static --disable-assembly --enable-module-recovery) | ||
doneSection | ||
} | ||
|
||
echo "=================================================================" | ||
echo "Start" | ||
echo "=================================================================" | ||
showConfig | ||
developerToolsPresent | ||
if [ "$ENV_ERROR" == "0" ]; then | ||
cleanUp | ||
createDirs | ||
downloadSrc | ||
# untarLzippedBundle | ||
compileSrcForAllArchs | ||
buildUniversalLib | ||
moveHeadersToFramework | ||
buildFrameworkPlist | ||
echo "Completed successfully.." | ||
else | ||
echo "Build failed..." | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
#!/bin/bash | ||
|
||
# build directories | ||
: ${WORKING_DIR:=`pwd`} | ||
: ${SRC_DIR:=`pwd`/src} | ||
: ${BUILD_DIR:=`pwd`/build} | ||
: ${FRAMEWORK_DIR:=`pwd`/framework} | ||
|
||
# build architectures | ||
# BUILD_ARCHS="i386 armv7s armv7 arm64" | ||
BUILD_ARCHS="armv7s armv7 arm64 i386" | ||
#BUILD_ARCHS="i386" | ||
|
||
# XCode directories | ||
: ${XCODE_ROOT:=`xcode-select -print-path`} | ||
XCODE_SIMULATOR=$XCODE_ROOT/Platforms/iPhoneSimulator.platform/Developer | ||
XCODE_DEVICE=$XCODE_ROOT/Platforms/iPhoneOS.platform/Developer | ||
|
||
XCODE_SIMULATOR_SDK=$XCODE_SIMULATOR/SDKs/iPhoneSimulator$IPHONE_SDKVERSION.sdk | ||
XCODE_DEVICE_SDK=$XCODE_DEVICE/SDKs/iPhoneOS$IPHONE_SDKVERSION.sdk | ||
|
||
XCODE_TOOLCHAIN_USR_BIN=$XCODE_ROOT/Toolchains/XcodeDefault.xctoolchain/usr/bin/ | ||
XCODE_USR_BIN=$XCODE_ROOT/usr/bin/ | ||
|
||
# framework setup | ||
FRAMEWORK_BUNDLE=$FRAMEWORK_DIR/$FRAMEWORK_NAME.framework | ||
FRAMEWORK_INSTALL_NAME=$FRAMEWORK_BUNDLE/Versions/$FRAMEWORK_VERSION/$FRAMEWORK_NAME | ||
|
||
# save path | ||
ORIGINAL_PATH=$PATH | ||
|
||
# commands | ||
: ${LIPO="xcrun -sdk iphoneos lipo"} | ||
|
||
doneSection() { | ||
echo | ||
echo "=================================================================" | ||
echo "Done" | ||
echo | ||
} | ||
|
||
showConfig() { | ||
echo "Bundle Configuration..." | ||
echo "BUNDLE: $BUNDLE" | ||
echo "DOWNLOAD_URL: $DOWNLOAD_URL" | ||
echo | ||
echo "Framework Configuration" | ||
echo "FRAMEWORK_NAME: $FRAMEWORK_NAME" | ||
echo "FRAMEWORK_VERSION: $FRAMEWORK_VERSION" | ||
echo "FRAMEWORK_CURRENT_VERSION: $FRAMEWORK_CURRENT_VERSION" | ||
echo "FRAMEWORK_IDENTIFIER: $FRAMEWORK_IDENTIFIER" | ||
echo | ||
echo "Build Directories..." | ||
echo "WORKING_DIR: $WORKING_DIR" | ||
echo "SRC_DIR: $SRC_DIR" | ||
echo "BUILD_DIR: $BUILD_DIR" | ||
echo "FRAMEWORK_DIR: $FRAMEWORK_DIR" | ||
echo | ||
echo "XCode Directories..." | ||
echo "XCODE_SIMULATOR: $XCODE_SIMULATOR" | ||
echo "XCODE_DEVICE: $XCODE_DEVICE" | ||
echo "XCODE_SIMULATOR_SDK: $XCODE_SIMULATOR_SDK" | ||
echo "XCODE_DEVICE_SDK: $XCODE_DEVICE_SDK" | ||
echo "XCODE_TOOLCHAIN_USR_BIN: $XCODE_TOOLCHAIN_USR_BIN" | ||
echo "XCODE_USR_BIN: $XCODE_USR_BIN" | ||
echo | ||
echo "FRAMEWORK_BUNDLE: $FRAMEWORK_BUNDLE" | ||
echo "FRAMEWORK_INSTALL_NAME: $FRAMEWORK_INSTALL_NAME" | ||
doneSection | ||
} | ||
|
||
developerToolsPresent () { | ||
echo "Check that developer tools present..." | ||
ENV_ERROR=0 | ||
|
||
# check for root directories | ||
if [ ! -d "$XCODE_SIMULATOR" ]; then | ||
echo "ERROR: unable to find Xcode Simulator directory: $XCODE_SIMULATOR" | ||
ENV_ERROR=1 | ||
fi | ||
|
||
# check for device directory | ||
if [ ! -d "$XCODE_DEVICE" ]; then | ||
echo "ERROR: unable to find Xcode Device directory: $XCODE_DEVICE" | ||
ENV_ERROR=1 | ||
fi | ||
|
||
#check for SDKs | ||
if [ ! -d "$XCODE_SIMULATOR_SDK" ]; then | ||
echo "ERROR: Simulator SDK not found" | ||
ENV_ERROR=1 | ||
fi | ||
|
||
if [ ! -d "$XCODE_DEVICE_SDK" ]; then | ||
echo "ERROR: Device SDK not found" | ||
ENV_ERROR=1 | ||
fi | ||
|
||
# check for presence oc cross compiler tools | ||
if [ ! -d "$XCODE_TOOLCHAIN_USR_BIN" ]; then | ||
echo "ERROR: unable to find Xcode toolchain usr/bin directory: $XCODE_TOOLCHAIN_USR_BIN" | ||
ENV_ERROR=1 | ||
fi | ||
|
||
if [ ! -d "$XCODE_USR_BIN" ]; then | ||
echo "ERROR: unable to find Xcode usr/bin directory: $XCODE_USR_BIN" | ||
ENV_ERROR=1 | ||
fi | ||
|
||
local targetTools="clang++ clang ar ranlib libtool ld lipo" | ||
for tool in $targetTools | ||
do | ||
if [ ! -e "$XCODE_TOOLCHAIN_USR_BIN/$tool" ] && [ ! -e "$XCODE_USR_BIN/$tool" ]; then | ||
echo "ERROR: unable to find $tool at device or simulator IOS_TOOLCHAIN or XCODE_TOOLCHAIN" | ||
ENV_ERROR=1 | ||
fi | ||
done | ||
|
||
doneSection | ||
} | ||
|
||
createDirs () { | ||
echo "Create directories..." | ||
[ -d $SRC_DIR ] || mkdir -p $SRC_DIR | ||
[ -d $BUILD_DIR ] || mkdir -p $BUILD_DIR | ||
[ -d $FRAMEWORK_DIR ] || mkdir -p $FRAMEWORK_DIR | ||
|
||
mkdir -p $FRAMEWORK_BUNDLE | ||
mkdir -p $FRAMEWORK_BUNDLE/Versions | ||
mkdir -p $FRAMEWORK_BUNDLE/Versions/$FRAMEWORK_VERSION | ||
mkdir -p $FRAMEWORK_BUNDLE/Versions/$FRAMEWORK_VERSION/Resources | ||
mkdir -p $FRAMEWORK_BUNDLE/Versions/$FRAMEWORK_VERSION/Headers | ||
mkdir -p $FRAMEWORK_BUNDLE/Versions/$FRAMEWORK_VERSION/Documentation | ||
|
||
ln -s $FRAMEWORK_VERSION $FRAMEWORK_BUNDLE/Versions/Current | ||
ln -s Versions/Current/Headers $FRAMEWORK_BUNDLE/Headers | ||
ln -s Versions/Current/Resources $FRAMEWORK_BUNDLE/Resources | ||
ln -s Versions/Current/Documentation $FRAMEWORK_BUNDLE/Documentation | ||
ln -s Versions/Current/$FRAMEWORK_NAME $FRAMEWORK_BUNDLE/$FRAMEWORK_NAME | ||
|
||
doneSection | ||
} | ||
|
||
cleanUp() { | ||
echo "Cleaning up before build..." | ||
rm -rf $SRC_DIR | ||
rm -rf $BUILD_DIR | ||
rm -rf $FRAMEWORK_DIR | ||
doneSection | ||
} | ||
cleanUpSrc() { | ||
echo "Cleaning up src before build..." | ||
rm -rf $SRC_DIR | ||
doneSection | ||
} | ||
|
||
buildFrameworkPlist() { | ||
echo "Framework: Creating plist..." | ||
cat > $FRAMEWORK_BUNDLE/Resources/Info.plist <<EOF | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>English</string> | ||
<key>CFBundleExecutable</key> | ||
<string>${FRAMEWORK_NAME}</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>${FRAMEWORK_IDENTIFIER}</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundlePackageType</key> | ||
<string>FMWK</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>${FRAMEWORK_CURRENT_VERSION}</string> | ||
</dict> | ||
</plist> | ||
EOF | ||
doneSection | ||
} | ||
|
||
unzipBundle() { | ||
echo "Unzip bundle to $SRC_DIR..." | ||
unzip $BUNDLE -d $SRC_DIR | ||
doneSection | ||
} | ||
|
||
untarGzippedBundle() { | ||
echo "Untar gzipped bundle to $SRC_DIR..." | ||
tar -xzvf $BUNDLE -C $SRC_DIR | ||
doneSection | ||
} | ||
|
||
downloadSrc() { | ||
echo "Download source if needed..." | ||
if [ ! -e "$WORKING_DIR/$BUNDLE" ]; then | ||
wget $DOWNLOAD_URL -O $WORKING_DIR/$BUNDLE | ||
fi | ||
doneSection | ||
} | ||
|
||
compileSrcForAllArchs() { | ||
for buildArch in $BUILD_ARCHS | ||
do | ||
exportConfig $buildArch | ||
compileSrcForArch $buildArch | ||
done | ||
} | ||
|
||
buildUniversalLib() { | ||
echo "Lipoing library to $FRAMEWORK_INSTALL_NAME..." | ||
$LIPO \ | ||
-create \ | ||
-arch armv7 "$BUILD_DIR/armv7/$LIBRARY" \ | ||
-arch armv7s "$BUILD_DIR/armv7s/$LIBRARY" \ | ||
-arch i386 "$BUILD_DIR/i386/$LIBRARY" \ | ||
-arch arm64 "$BUILD_DIR/arm64/$LIBRARY" \ | ||
-o "$FRAMEWORK_INSTALL_NAME" \ | ||
|| abort "lipo failed" | ||
doneSection | ||
} |