| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- #!/bin/bash
- # Script modified from upstream at the following URL:
- # https://github.com/nxrighthere/ENet-CSharp/blob/master/Source/Native/build-ios.sh
- # Original portions by JohannesDeml, modifications by Coburn.
- # Cache this for later.
- # Point sysdir to iOS SDK
- RELEASE_SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
- SIMULATOR_SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
- WORKSPACE="$(pwd)"
- OUTPUT="$WORKSPACE/Binaries"
- X64_SIMULATOR_STAGING="$WORKSPACE/x86_64-apple-ios-simulator"
- ARM64_STAGING="$WORKSPACE/arm64-apple-ios"
- ARMV7_STAGING="$WORKSPACE/armv7-apple-ios"
- # Function declaration
- create_enet_symlink() {
- # Only symlink if we don't have one already
- if [ ! -d "Sources" ]; then
- # Symlink work directory sources.
- ln -s "$WORKSPACE/../Source/Native" "Sources"
- if [ $? -ne 0 ]; then
- echo "ERROR: Failed to make symlink to ENet source code. Did you git pull this correctly? Build script aborted."
- exit $?
- fi
- fi
- }
- make_enet_directories() {
- # Output
- if [ ! -d "$OUTPUT" ]; then
- mkdir "$OUTPUT"
- if [ $? -ne 0 ]; then
- echo "ERROR: Failed to make staging directory for x64 Simulator. Build script aborted."
- exit $?
- fi
- else
- rm -rfv "$OUTPUT"/*
- if [ $? -ne 0 ]; then
- echo "ERROR: Failed to delete files inside output directory. Build script aborted."
- exit $?
- fi
- fi
-
- # Simulator
- if [ ! -d "$X64_SIMULATOR_STAGING" ]; then
- # Make it.
- mkdir "$X64_SIMULATOR_STAGING"
- if [ $? -ne 0 ]; then
- echo "ERROR: Failed to make staging directory for x64 Simulator. Build script aborted."
- exit $?
- fi
- else
- # Purge it.
- echo "Cleaning out existing x64 Simulator staging directory."
- rm -rfv "$X64_SIMULATOR_STAGING"/*
- if [ $? -ne 0 ]; then
- echo "ERROR: Failed to delete files inside staging directory. Build script aborted."
- exit $?
- fi
- fi
-
- # ARMv7
- if [ ! -d "$ARMV7_STAGING" ]; then
- # Make it.
- mkdir "$ARMV7_STAGING"
- if [ $? -ne 0 ]; then
- echo "ERROR: Failed to make staging directory for ARMv7. Build script aborted."
- exit $?
- fi
- else
- # Purge it.
- echo "Cleaning out existing ARMv7 staging directory."
- rm -rfv "$ARMV7_STAGING"/*
- if [ $? -ne 0 ]; then
- echo "ERROR: Failed to delete files inside staging directory. Build script aborted."
- exit $?
- fi
- fi
-
- # ARM64
- if [ ! -d "$ARM64_STAGING" ]; then
- # Make it.
- mkdir "$ARM64_STAGING"
- if [ $? -ne 0 ]; then
- echo "ERROR: Failed to make staging directory for ARM64. Build script aborted."
- exit $?
- fi
- else
- # Purge it.
- echo "Cleaning out existing ARM64 staging directory."
- rm -rfv "$ARM64_STAGING"/*
- if [ $? -ne 0 ]; then
- echo "ERROR: Failed to delete files inside staging directory. Build script aborted."
- exit $?
- fi
- fi
- }
- compile_enet_x64simulator () {
- echo "Start compiling x64 Simulator"
- export SDKROOT=$SIMULATOR_SDKROOT
- cd "$X64_SIMULATOR_STAGING"
- # Pre-clean
- rm -vf *.a *.o
-
- create_enet_symlink
-
- # Release Binaries
- gcc -c Sources/enet.c -fembed-bitcode -target x86_64-apple-ios-simulator
- if [ $? -ne 0 ]; then
- echo "ERROR: Compile step resulted in failure."
- exit $?
- fi
- # Create static library
- libtool -static enet.o -o libenet-release-simulator64.a
- if [ $? -ne 0 ]; then
- echo "ERROR: Libtool step resulted in failure."
- exit $?
- fi
- # Cleanup
- rm -vf *.o
-
- # Debug Binaries
- gcc -DENET_DEBUG=1 -c Sources/enet.c -fembed-bitcode -target x86_64-apple-ios-simulator
- if [ $? -ne 0 ]; then
- echo "ERROR: Compile step resulted in failure."
- exit $?
- fi
- libtool -static enet.o -o libenet-debug-simulator64.a
- if [ $? -ne 0 ]; then
- echo "ERROR: Libtool step resulted in failure."
- exit $?
- fi
- # Copy.
- cp -v *.a "$OUTPUT"
- }
- compile_enet_armv7 () {
- echo "Start compiling ARMv7"
- export SDKROOT=$RELEASE_SDKROOT
- cd "$ARMV7_STAGING"
-
- # Pre-clean
- rm -vf *.a *.o
-
- create_enet_symlink
-
- # Release Binaries
- gcc -c Sources/enet.c -fembed-bitcode -target armv7-apple-ios
- if [ $? -ne 0 ]; then
- echo "ERROR: Compile step resulted in failure."
- exit $?
- fi
- # Create static library
- libtool -static enet.o -o libenet-release-armv7.a
- if [ $? -ne 0 ]; then
- echo "ERROR: Libtool step resulted in failure."
- exit $?
- fi
-
- # Cleanup
- rm -vf *.o
-
- # Debug Binaries
- gcc -DENET_DEBUG=1 -c Sources/enet.c -fembed-bitcode -target armv7-apple-ios
- if [ $? -ne 0 ]; then
- echo "ERROR: Compile step resulted in failure."
- exit $?
- fi
- libtool -static enet.o -o libenet-debug-armv7.a
- if [ $? -ne 0 ]; then
- echo "ERROR: Libtool step resulted in failure."
- exit $?
- fi
- # Copy.
- cp -v *.a "$OUTPUT"
- }
- compile_enet_arm64 () {
- echo "Start compiling ARM64"
- export SDKROOT=$RELEASE_SDKROOT
- cd "$ARM64_STAGING"
-
- # Pre-clean
- rm -vf *.a *.o
-
- create_enet_symlink
-
- # Release Binaries
- gcc -c Sources/enet.c -fembed-bitcode -target arm64-apple-ios
- if [ $? -ne 0 ]; then
- echo "ERROR: Compile step resulted in failure."
- exit $?
- fi
- # Create static library
- libtool -static enet.o -o libenet-release-arm64.a
- if [ $? -ne 0 ]; then
- echo "ERROR: Libtool step resulted in failure."
- exit $?
- fi
- # Cleanup
- rm -v *.o
-
- # Debug Binaries
- gcc -DENET_DEBUG=1 -c Sources/enet.c -fembed-bitcode -target arm64-apple-ios
- if [ $? -ne 0 ]; then
- echo "ERROR: Compile step resulted in failure."
- exit $?
- fi
- libtool -static enet.o -o libenet-debug-arm64.a
- if [ $? -ne 0 ]; then
- echo "ERROR: Libtool step resulted in failure."
- exit $?
- fi
- # Copy.
- cp -v *.a "$OUTPUT"
- }
- compress_and_exfil() {
- # Good 'ol Zip.
- cd $OUTPUT
-
- if [ $? -ne 0 ]; then
- echo "WARNING: Looks like we can't enter the output directory, skipping compression phase"
- return
- fi
-
- echo "About to compress compiled binaries."
- zip -v -9 -j "libenet-combo-iOS.zip" *.a
-
- if [ $? -ne 0 ]; then
- echo "WARNING: Looks like the compression step failed, continuing as this is not fatal"
- fi
- }
- # Make staging directories and build.
- make_enet_directories
- compile_enet_x64simulator
- compile_enet_arm64
- compile_enet_armv7
- # Compress the goods.
- compress_and_exfil
- FINAL_STAND=$?
- echo "Build script has finished."
- exit $FINAL_STAND
|