apple-ios.command 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. # Cache this for later.
  6. # Point sysdir to iOS SDK
  7. RELEASE_SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
  8. SIMULATOR_SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk"
  9. WORKSPACE="$(pwd)"
  10. OUTPUT="$WORKSPACE/Binaries"
  11. X64_SIMULATOR_STAGING="$WORKSPACE/x86_64-apple-ios-simulator"
  12. ARM64_STAGING="$WORKSPACE/arm64-apple-ios"
  13. ARMV7_STAGING="$WORKSPACE/armv7-apple-ios"
  14. # Function declaration
  15. create_enet_symlink() {
  16. # Only symlink if we don't have one already
  17. if [ ! -d "Sources" ]; then
  18. # Symlink work directory sources.
  19. ln -s "$WORKSPACE/../Source/Native" "Sources"
  20. if [ $? -ne 0 ]; then
  21. echo "ERROR: Failed to make symlink to ENet source code. Did you git pull this correctly? Build script aborted."
  22. exit $?
  23. fi
  24. fi
  25. }
  26. make_enet_directories() {
  27. # Output
  28. if [ ! -d "$OUTPUT" ]; then
  29. mkdir "$OUTPUT"
  30. if [ $? -ne 0 ]; then
  31. echo "ERROR: Failed to make staging directory for x64 Simulator. Build script aborted."
  32. exit $?
  33. fi
  34. else
  35. rm -rfv "$OUTPUT"/*
  36. if [ $? -ne 0 ]; then
  37. echo "ERROR: Failed to delete files inside output directory. Build script aborted."
  38. exit $?
  39. fi
  40. fi
  41. # Simulator
  42. if [ ! -d "$X64_SIMULATOR_STAGING" ]; then
  43. # Make it.
  44. mkdir "$X64_SIMULATOR_STAGING"
  45. if [ $? -ne 0 ]; then
  46. echo "ERROR: Failed to make staging directory for x64 Simulator. Build script aborted."
  47. exit $?
  48. fi
  49. else
  50. # Purge it.
  51. echo "Cleaning out existing x64 Simulator staging directory."
  52. rm -rfv "$X64_SIMULATOR_STAGING"/*
  53. if [ $? -ne 0 ]; then
  54. echo "ERROR: Failed to delete files inside staging directory. Build script aborted."
  55. exit $?
  56. fi
  57. fi
  58. # ARMv7
  59. if [ ! -d "$ARMV7_STAGING" ]; then
  60. # Make it.
  61. mkdir "$ARMV7_STAGING"
  62. if [ $? -ne 0 ]; then
  63. echo "ERROR: Failed to make staging directory for ARMv7. Build script aborted."
  64. exit $?
  65. fi
  66. else
  67. # Purge it.
  68. echo "Cleaning out existing ARMv7 staging directory."
  69. rm -rfv "$ARMV7_STAGING"/*
  70. if [ $? -ne 0 ]; then
  71. echo "ERROR: Failed to delete files inside staging directory. Build script aborted."
  72. exit $?
  73. fi
  74. fi
  75. # ARM64
  76. if [ ! -d "$ARM64_STAGING" ]; then
  77. # Make it.
  78. mkdir "$ARM64_STAGING"
  79. if [ $? -ne 0 ]; then
  80. echo "ERROR: Failed to make staging directory for ARM64. Build script aborted."
  81. exit $?
  82. fi
  83. else
  84. # Purge it.
  85. echo "Cleaning out existing ARM64 staging directory."
  86. rm -rfv "$ARM64_STAGING"/*
  87. if [ $? -ne 0 ]; then
  88. echo "ERROR: Failed to delete files inside staging directory. Build script aborted."
  89. exit $?
  90. fi
  91. fi
  92. }
  93. compile_enet_x64simulator () {
  94. echo "Start compiling x64 Simulator"
  95. export SDKROOT=$SIMULATOR_SDKROOT
  96. cd "$X64_SIMULATOR_STAGING"
  97. # Pre-clean
  98. rm -vf *.a *.o
  99. create_enet_symlink
  100. # Release Binaries
  101. gcc -c Sources/enet.c -fembed-bitcode -target x86_64-apple-ios-simulator
  102. if [ $? -ne 0 ]; then
  103. echo "ERROR: Compile step resulted in failure."
  104. exit $?
  105. fi
  106. # Create static library
  107. libtool -static enet.o -o libenet-release-simulator64.a
  108. if [ $? -ne 0 ]; then
  109. echo "ERROR: Libtool step resulted in failure."
  110. exit $?
  111. fi
  112. # Cleanup
  113. rm -vf *.o
  114. # Debug Binaries
  115. gcc -DENET_DEBUG=1 -c Sources/enet.c -fembed-bitcode -target x86_64-apple-ios-simulator
  116. if [ $? -ne 0 ]; then
  117. echo "ERROR: Compile step resulted in failure."
  118. exit $?
  119. fi
  120. libtool -static enet.o -o libenet-debug-simulator64.a
  121. if [ $? -ne 0 ]; then
  122. echo "ERROR: Libtool step resulted in failure."
  123. exit $?
  124. fi
  125. # Copy.
  126. cp -v *.a "$OUTPUT"
  127. }
  128. compile_enet_armv7 () {
  129. echo "Start compiling ARMv7"
  130. export SDKROOT=$RELEASE_SDKROOT
  131. cd "$ARMV7_STAGING"
  132. # Pre-clean
  133. rm -vf *.a *.o
  134. create_enet_symlink
  135. # Release Binaries
  136. gcc -c Sources/enet.c -fembed-bitcode -target armv7-apple-ios
  137. if [ $? -ne 0 ]; then
  138. echo "ERROR: Compile step resulted in failure."
  139. exit $?
  140. fi
  141. # Create static library
  142. libtool -static enet.o -o libenet-release-armv7.a
  143. if [ $? -ne 0 ]; then
  144. echo "ERROR: Libtool step resulted in failure."
  145. exit $?
  146. fi
  147. # Cleanup
  148. rm -vf *.o
  149. # Debug Binaries
  150. gcc -DENET_DEBUG=1 -c Sources/enet.c -fembed-bitcode -target armv7-apple-ios
  151. if [ $? -ne 0 ]; then
  152. echo "ERROR: Compile step resulted in failure."
  153. exit $?
  154. fi
  155. libtool -static enet.o -o libenet-debug-armv7.a
  156. if [ $? -ne 0 ]; then
  157. echo "ERROR: Libtool step resulted in failure."
  158. exit $?
  159. fi
  160. # Copy.
  161. cp -v *.a "$OUTPUT"
  162. }
  163. compile_enet_arm64 () {
  164. echo "Start compiling ARM64"
  165. export SDKROOT=$RELEASE_SDKROOT
  166. cd "$ARM64_STAGING"
  167. # Pre-clean
  168. rm -vf *.a *.o
  169. create_enet_symlink
  170. # Release Binaries
  171. gcc -c Sources/enet.c -fembed-bitcode -target arm64-apple-ios
  172. if [ $? -ne 0 ]; then
  173. echo "ERROR: Compile step resulted in failure."
  174. exit $?
  175. fi
  176. # Create static library
  177. libtool -static enet.o -o libenet-release-arm64.a
  178. if [ $? -ne 0 ]; then
  179. echo "ERROR: Libtool step resulted in failure."
  180. exit $?
  181. fi
  182. # Cleanup
  183. rm -v *.o
  184. # Debug Binaries
  185. gcc -DENET_DEBUG=1 -c Sources/enet.c -fembed-bitcode -target arm64-apple-ios
  186. if [ $? -ne 0 ]; then
  187. echo "ERROR: Compile step resulted in failure."
  188. exit $?
  189. fi
  190. libtool -static enet.o -o libenet-debug-arm64.a
  191. if [ $? -ne 0 ]; then
  192. echo "ERROR: Libtool step resulted in failure."
  193. exit $?
  194. fi
  195. # Copy.
  196. cp -v *.a "$OUTPUT"
  197. }
  198. compress_and_exfil() {
  199. # Good 'ol Zip.
  200. cd $OUTPUT
  201. if [ $? -ne 0 ]; then
  202. echo "WARNING: Looks like we can't enter the output directory, skipping compression phase"
  203. return
  204. fi
  205. echo "About to compress compiled binaries."
  206. zip -v -9 -j "libenet-combo-iOS.zip" *.a
  207. if [ $? -ne 0 ]; then
  208. echo "WARNING: Looks like the compression step failed, continuing as this is not fatal"
  209. fi
  210. }
  211. # Make staging directories and build.
  212. make_enet_directories
  213. compile_enet_x64simulator
  214. compile_enet_arm64
  215. compile_enet_armv7
  216. # Compress the goods.
  217. compress_and_exfil
  218. FINAL_STAND=$?
  219. echo "Build script has finished."
  220. exit $FINAL_STAND