ios-autobuild.command 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #!/bin/bash
  2. # Script modified from upstream at the following URL:
  3. # https://github.com/nxrighthere/ENet-CSharp/blob/master/Source/Native/build-ios.sh
  4. # Original portions by JohannesDeml, modifications by Coburn.
  5. # Point sysdir to iOS SDK
  6. export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
  7. # Cache this for later.
  8. WORKSPACE=$(pwd)
  9. OUTPUT="$WORKSPACE/Binaries"
  10. X64_SIMULATOR_STAGING="$WORKSPACE/x86_64-apple-ios-simulator"
  11. ARM64_STAGING="$WORKSPACE/arm64-apple-ios"
  12. ARMV7_STAGING="$WORKSPACE/armv7-apple-ios"
  13. # Function declaration
  14. create_enet_symlink() {
  15. # Only symlink if we don't have one already
  16. if [ ! -d "Sources" ]; then
  17. # Symlink work directory sources.
  18. ln -s "$WORKSPACE/../Source/Native" "Sources"
  19. if [ $? -ne 0 ]; then
  20. echo "ERROR: Failed to make symlink to ENet source code. Did you git pull this correctly? Build script aborted."
  21. exit $?
  22. fi
  23. fi
  24. }
  25. make_enet_directories() {
  26. # Output
  27. if [ ! -d "$OUTPUT" ]; then
  28. mkdir "$OUTPUT"
  29. if [ $? -ne 0 ]; then
  30. echo "ERROR: Failed to make staging directory for x64 Simulator. Build script aborted."
  31. exit $?
  32. fi
  33. else
  34. rm -rfv "$OUTPUT"/*
  35. if [ $? -ne 0 ]; then
  36. echo "ERROR: Failed to delete files inside output directory. Build script aborted."
  37. exit $?
  38. fi
  39. fi
  40. # Simulator
  41. if [ ! -d "$X64_SIMULATOR_STAGING" ]; then
  42. # Make it.
  43. mkdir "$X64_SIMULATOR_STAGING"
  44. if [ $? -ne 0 ]; then
  45. echo "ERROR: Failed to make staging directory for x64 Simulator. Build script aborted."
  46. exit $?
  47. fi
  48. else
  49. # Purge it.
  50. echo "Cleaning out existing x64 Simulator staging directory."
  51. rm -rfv "$X64_SIMULATOR_STAGING"/*
  52. if [ $? -ne 0 ]; then
  53. echo "ERROR: Failed to delete files inside staging directory. Build script aborted."
  54. exit $?
  55. fi
  56. fi
  57. # ARMv7
  58. if [ ! -d "$ARMV7_STAGING" ]; then
  59. # Make it.
  60. mkdir "$ARMV7_STAGING"
  61. if [ $? -ne 0 ]; then
  62. echo "ERROR: Failed to make staging directory for ARMv7. Build script aborted."
  63. exit $?
  64. fi
  65. else
  66. # Purge it.
  67. echo "Cleaning out existing ARMv7 staging directory."
  68. rm -rfv "$ARMV7_STAGING"/*
  69. if [ $? -ne 0 ]; then
  70. echo "ERROR: Failed to delete files inside staging directory. Build script aborted."
  71. exit $?
  72. fi
  73. fi
  74. # ARM64
  75. if [ ! -d "$ARM64_STAGING" ]; then
  76. # Make it.
  77. mkdir "$ARM64_STAGING"
  78. if [ $? -ne 0 ]; then
  79. echo "ERROR: Failed to make staging directory for ARM64. Build script aborted."
  80. exit $?
  81. fi
  82. else
  83. # Purge it.
  84. echo "Cleaning out existing ARM64 staging directory."
  85. rm -rfv "$ARM64_STAGING"/*
  86. if [ $? -ne 0 ]; then
  87. echo "ERROR: Failed to delete files inside staging directory. Build script aborted."
  88. exit $?
  89. fi
  90. fi
  91. }
  92. compile_enet_x64simulator () {
  93. echo "Start compiling x64 Simulator"
  94. cd "$X64_SIMULATOR_STAGING"
  95. # Pre-clean
  96. rm -vf *.a *.o
  97. create_enet_symlink
  98. # Release Binaries
  99. gcc -c Sources/enet.c -fembed-bitcode -target x86_64-apple-ios-simulator
  100. # Create static library
  101. libtool -static enet.o -o libenet-release-simulator64.a
  102. # Cleanup
  103. rm -vf *.o
  104. # Debug Binaries
  105. gcc -DENET_DEBUG=1 -c Sources/enet.c -fembed-bitcode -target x86_64-apple-ios-simulator
  106. libtool -static enet.o -o libenet-debug-simulator64.a
  107. # Copy.
  108. cp -v *.a "$OUTPUT"
  109. }
  110. compile_enet_armv7 () {
  111. echo "Start compiling ARMv7"
  112. cd "$ARMV7_STAGING"
  113. # Pre-clean
  114. rm -vf *.a *.o
  115. create_enet_symlink
  116. # Release Binaries
  117. gcc -c Sources/enet.c -fembed-bitcode -target armv7-apple-ios
  118. # Create static library
  119. libtool -static enet.o -o libenet-release-armv7.a
  120. # Cleanup
  121. rm -vf *.o
  122. # Debug Binaries
  123. gcc -DENET_DEBUG=1 -c Sources/enet.c -fembed-bitcode -target armv7-apple-ios
  124. libtool -static enet.o -o libenet-debug-armv7.a
  125. # Copy.
  126. cp -v *.a "$OUTPUT"
  127. }
  128. compile_enet_arm64 () {
  129. echo "Start compiling ARM64"
  130. cd "$ARM64_STAGING"
  131. # Pre-clean
  132. rm -vf *.a *.o
  133. create_enet_symlink
  134. # Release Binaries
  135. gcc -c Sources/enet.c -fembed-bitcode -target arm64-apple-ios
  136. # Create static library
  137. libtool -static enet.o -o libenet-release-arm64.a
  138. # Cleanup
  139. rm -v *.o
  140. # Debug Binaries
  141. gcc -DENET_DEBUG=1 -c Sources/enet.c -fembed-bitcode -target arm64-apple-ios
  142. libtool -static enet.o -o libenet-debug-arm64.a
  143. # Copy.
  144. cp -v *.a "$OUTPUT"
  145. }
  146. compress_and_exfil() {
  147. # Good 'ol Zip.
  148. cd $OUTPUT
  149. if [ $? -ne 0 ]; then
  150. echo "WARNING: Looks like we can't enter the output directory, skipping compression phase"
  151. return
  152. fi
  153. echo "About to compress compiled binaries."
  154. zip -v -9 -j "libenet-combo-iOS.zip" *.a
  155. if [ $? -ne 0 ]; then
  156. echo "WARNING: Looks like the compression step failed, continuing as this is not fatal"
  157. fi
  158. }
  159. # Make staging directories and build.
  160. make_enet_directories
  161. compile_enet_x64simulator
  162. compile_enet_arm64
  163. compile_enet_armv7
  164. # Compress the goods.
  165. compress_and_exfil
  166. FINAL_STAND=$?
  167. echo "Build script has finished."
  168. exit $FINAL_STAND