ios-autobuild.command 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 Sources "$WORKSPACE/../Source/Native"
  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. # Simulator
  27. if [ ! -d "$X64_SIMULATOR_STAGING" ]; then
  28. # Make it.
  29. mkdir "$X64_SIMULATOR_STAGING"
  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. # Purge it.
  36. echo "Cleaning out existing x64 Simulator staging directory."
  37. rm -rv "$X64_SIMULATOR_STAGING"/*
  38. if [ $? -ne 0 ]; then
  39. echo "ERROR: Failed to delete files inside staging directory. Build script aborted."
  40. exit $?
  41. fi
  42. fi
  43. # ARMv7
  44. if [ ! -d "$ARMV7_STAGING" ]; then
  45. # Make it.
  46. mkdir "$ARMV7_STAGING"
  47. if [ $? -ne 0 ]; then
  48. echo "ERROR: Failed to make staging directory for ARMv7. Build script aborted."
  49. exit $?
  50. fi
  51. else
  52. # Purge it.
  53. echo "Cleaning out existing ARMv7 staging directory."
  54. rm -rv "$ARMV7_STAGING"/*
  55. if [ $? -ne 0 ]; then
  56. echo "ERROR: Failed to delete files inside staging directory. Build script aborted."
  57. exit $?
  58. fi
  59. fi
  60. # ARM64
  61. if [ ! -d "$ARM64_STAGING" ]; then
  62. # Make it.
  63. mkdir "$ARM64_STAGING"
  64. if [ $? -ne 0 ]; then
  65. echo "ERROR: Failed to make staging directory for ARM64. Build script aborted."
  66. exit $?
  67. fi
  68. else
  69. # Purge it.
  70. echo "Cleaning out existing ARM64 staging directory."
  71. rm -rv "$ARM64_STAGING"/*
  72. if [ $? -ne 0 ]; then
  73. echo "ERROR: Failed to delete files inside staging directory. Build script aborted."
  74. exit $?
  75. fi
  76. fi
  77. }
  78. compile_enet_x64simulator () {
  79. cd "$X64_SIMULATOR_STAGING"
  80. # Pre-clean
  81. rm -v *.a *.o
  82. # Release Binaries
  83. gcc -c Sources/enet.c -fembed-bitcode -target x86_64-apple-ios-simulator
  84. # Create static library
  85. libtool -static enet.o -o libenet-release-simulator64.a
  86. # Cleanup
  87. rm -v *.o
  88. # Debug Binaries
  89. gcc -DENET_DEBUG=1 -c Sources/enet.c -fembed-bitcode -target x86_64-apple-ios-simulator
  90. libtool -static enet.o -o libenet-debug-simulator64.a
  91. # Copy.
  92. cp -v *.a "$OUTPUT"
  93. }
  94. compile_enet_armv7 () {
  95. cd "$ARMV7_STAGING"
  96. # Pre-clean
  97. rm -v *.a *.o
  98. create_enet_symlink
  99. # Release Binaries
  100. gcc -c Sources/enet.c -fembed-bitcode -target armv7-apple-ios
  101. # Create static library
  102. libtool -static enet.o -o libenet-release-armv7.a
  103. # Cleanup
  104. rm -v *.o
  105. # Debug Binaries
  106. gcc -DENET_DEBUG=1 -c Sources/enet.c -fembed-bitcode -target armv7-apple-ios
  107. libtool -static enet.o -o libenet-debug-armv7.a
  108. # Copy.
  109. cp -v *.a "$OUTPUT"
  110. }
  111. compile_enet_arm64 () {
  112. cd "$ARM64_STAGING"
  113. # Pre-clean
  114. rm -v *.a *.o
  115. create_enet_symlink()
  116. # Release Binaries
  117. gcc -c Sources/enet.c -fembed-bitcode -target arm64-apple-ios
  118. # Create static library
  119. libtool -static enet.o -o libenet-release-arm64.a
  120. # Cleanup
  121. rm -v *.o
  122. # Debug Binaries
  123. gcc -DENET_DEBUG=1 -c Sources/enet.c -fembed-bitcode -target arm64-apple-ios
  124. libtool -static enet.o -o libenet-debug-arm64.a
  125. # Copy.
  126. cp -v *.a "$OUTPUT"
  127. }
  128. compress_and_exfil() {
  129. # Good 'ol Zip.
  130. cd $OUTPUT
  131. echo "About to compress compiled binaries."
  132. zip -v -9 -j "libenet-combo-iOS.zip" *.a
  133. if [ $? -ne 0 ]; then
  134. echo "WARNING: Looks like the compression step failed, continuing as this is not fatal"
  135. fi
  136. }
  137. # ln -s Sources $WORKSPACE/../Source/Native
  138. # Make staging directories and build.
  139. make_enet_directories
  140. compile_enet_x64simulator
  141. compile_enet_arm64
  142. compile_enet_armv7
  143. # Compress the goods.
  144. compress_and_exfil
  145. FINAL_STAND=$?
  146. echo "Build script has finished."
  147. exit $FINAL_STAND