lnsocket

A minimal C library for connecting to the lightning network
git clone git://jb55.com/lnsocket
Log | Files | Refs | Submodules | README | LICENSE

commit e064b1b361800f98e421d85f7d2b300ac0d49bd0
parent 6df4644ddf4a180cc4e4a1e97182d97776ef119e
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 29 Jan 2022 18:30:26 -0800

ios: secp256k1 build

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
MMakefile | 26++++++++++++++++----------
Atools/secp-ios.sh | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile @@ -19,7 +19,7 @@ DEPS=$(OBJS) $(ARS) config.h all: $(BINS) lnsocket.a -ios: target/universal/lnsocket.a target/universal/libsodium.a +ios: target/ios/lnsocket.a target/ios/libsodium.a target/ios/libsecp256k1.a deps/libsodium/.git: @tools/refresh-submodules.sh $(SUBMODULES) @@ -38,19 +38,19 @@ target/x86_64/lnsocket.a: $(X86_64_OBJS) @mkdir -p target/x86_64 ar rcs $@ $^ -target/universal/lnsocket.a: target/x86_64/lnsocket.a target/arm64/lnsocket.a - @mkdir -p target/universal +target/ios/lnsocket.a: target/x86_64/lnsocket.a target/arm64/lnsocket.a + @mkdir -p target/ios lipo -create $^ -output $@ %-arm64.o: %.c config.h @echo "cc $@" - @$(CC) $(CFLAGS) -DARCH=arm64 -c $< -o $@ -arch arm64 -isysroot $(IOS_SDK) -target arm64-apple-ios -fembed-bitcode + @$(CC) $(CFLAGS) -c $< -o $@ -arch arm64 -isysroot $(IOS_SDK) -target arm64-apple-ios -fembed-bitcode %-x86_64.o: %.c config.h @echo "cc $@" - @$(CC) $(CFLAGS) -DARCH=x86_64 -c $< -o $@ -arch x86_64 -isysroot $(SIM_SDK) -mios-simulator-version-min=6.0.0 -target x86_64-apple-ios-simulator + @$(CC) $(CFLAGS) -c $< -o $@ -arch x86_64 -isysroot $(SIM_SDK) -mios-simulator-version-min=6.0.0 -target x86_64-apple-ios-simulator -# TODO cross compilation settings?? +# TODO cross compiled config?? config.h: configurator ./configurator > $@ @@ -63,11 +63,11 @@ configurator: configurator.c deps/secp256k1/src/libsecp256k1-config.h: deps/secp256k1/configure cd deps/secp256k1; \ - ./configure --enable-module-ecdh + ./configure --disable-shared --enable-module-ecdh deps/libsodium/config.status: deps/libsodium/configure cd deps/libsodium; \ - ./configure --enable-minimal + ./configure --disable-shared --enable-minimal deps/secp256k1/configure: deps/secp256k1/.git cd deps/secp256k1; \ @@ -87,13 +87,19 @@ libsecp256k1.a: deps/secp256k1/.libs/libsecp256k1.a libsodium.a: deps/libsodium/src/libsodium/.libs/libsodium.a cp $< $@ -target/universal/libsodium.a: deps/libsodium/libsodium-ios/lib/libsodium.a +target/ios/libsodium.a: deps/libsodium/libsodium-ios/lib/libsodium.a + cp $< $@ + +target/ios/libsecp256k1.a: deps/secp256k1/libsecp256k1-ios/lib/libsecp256k1.a cp $< $@ deps/libsodium/libsodium-ios/lib/libsodium.a: cd deps/libsodium; \ ./dist-build/ios.sh +deps/secp256k1/libsecp256k1-ios/lib/libsecp256k1.a: + ./tools/secp-ios.sh + deps/libsodium/src/libsodium/.libs/libsodium.a: deps/libsodium/config.status cd deps/libsodium/src/libsodium; \ make -j2 libsodium.la @@ -113,7 +119,7 @@ clean: fake rm -rf $(BINS) config.h $(OBJS) $(ARM64_OBJS) $(X86_64_OBJS) target distclean: clean - rm -rf $(ARS) deps/secp256k1/src/libsecp256k1-config.h deps/libsodium/libsodium-ios + rm -rf $(ARS) deps/secp256k1/src/libsecp256k1-config.h deps/libsodium/libsodium-ios deps/secp256k1/libsecp256k1-ios cd deps/secp256k1; \ make distclean cd deps/libsodium; \ diff --git a/tools/secp-ios.sh b/tools/secp-ios.sh @@ -0,0 +1,74 @@ +#! /usr/bin/env bash +# +# Step 1. +# Configure for base system so simulator is covered +# +# Step 2. +# Make for iOS and iOS simulator +# +# Step 3. +# Merge libs into final version for xcode import + +cd deps/secp256k1 + +export PREFIX="$(pwd)/libsecp256k1-ios" +export IOS64_PREFIX="$PREFIX/tmp/ios64" +export SIMULATOR64_PREFIX="$PREFIX/tmp/simulator64" +export XCODEDIR=$(xcode-select -p) +export IOS_SIMULATOR_VERSION_MIN=${IOS_SIMULATOR_VERSION_MIN-"6.0.0"} +export IOS_VERSION_MIN=${IOS_VERSION_MIN-"6.0.0"} + +mkdir -p $SIMULATOR64_PREFIX $IOS64_PREFIX || exit 1 + +# Build for the simulator +export BASEDIR="${XCODEDIR}/Platforms/iPhoneSimulator.platform/Developer" +export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH" +export SDK="${BASEDIR}/SDKs/iPhoneSimulator.sdk" + +## x86_64 simulator +export CFLAGS="-O2 -arch x86_64 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN} -flto" +export LDFLAGS="-arch x86_64 -isysroot ${SDK} -mios-simulator-version-min=${IOS_SIMULATOR_VERSION_MIN} -flto" + +make distclean > /dev/null + +./configure --host=x86_64-apple-darwin10 \ + --disable-shared \ + --enable-module-ecdh \ + --prefix="$SIMULATOR64_PREFIX" + +make -j3 install || exit 1 + +# Build for iOS +export BASEDIR="${XCODEDIR}/Platforms/iPhoneOS.platform/Developer" +export PATH="${BASEDIR}/usr/bin:$BASEDIR/usr/sbin:$PATH" +export SDK="${BASEDIR}/SDKs/iPhoneOS.sdk" + +## 64-bit iOS +export CFLAGS="-O2 -arch arm64 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN} -flto -fembed-bitcode" +export LDFLAGS="-arch arm64 -isysroot ${SDK} -mios-version-min=${IOS_VERSION_MIN} -flto -fembed-bitcode" + +make distclean > /dev/null + +./configure --host=arm-apple-darwin10 \ + --disable-shared \ + --enable-module-ecdh \ + --prefix="$IOS64_PREFIX" || exit 1 + +make -j3 install || exit 1 + +# Create universal binary and include folder +rm -fr -- "$PREFIX/include" "$PREFIX/libsecp256k1.a" 2> /dev/null +mkdir -p -- "$PREFIX/lib" +lipo -create \ + "$SIMULATOR64_PREFIX/lib/libsecp256k1.a" \ + "$IOS64_PREFIX/lib/libsecp256k1.a" \ + -output "$PREFIX/lib/libsecp256k1.a" + +echo +echo "libsecp256k1 has been installed into $PREFIX" +echo +file -- "$PREFIX/lib/libsecp256k1.a" + +# Cleanup +rm -rf -- "$PREFIX/tmp" +make distclean > /dev/null