build_ios.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #!/bin/bash
  2. # Automatic build script for pbc-lua
  3. # for iPhoneOS and iPhoneSimulator
  4. ###########################################################################
  5. # Change values here
  6. #
  7. SDKVERSION=$(xcrun -sdk iphoneos --show-sdk-version);
  8. #
  9. ###########################################################################
  10. #
  11. # Don't change anything here
  12. WORKING_DIR="$(cd $(dirname $0))";
  13. cd "$WORKING_DIR";
  14. ARCHS="i386 x86_64 armv7 armv7s arm64";
  15. DEVELOPER_ROOT=$(xcode-select -print-path);
  16. ENABLE_PBC=0;
  17. # ======================= options =======================
  18. while getopts "a:d:hps:-" OPTION; do
  19. case $OPTION in
  20. a)
  21. ARCHS="$OPTARG";
  22. ;;
  23. d)
  24. DEVELOPER_ROOT="$OPTARG";
  25. ;;
  26. h)
  27. echo "usage: $0 [options] [-- [LUADIR=Lua include directory] [other make options]]";
  28. echo "options:";
  29. echo "-a [archs] which arch need to built, multiple values must be split by space(default: $ARCHS)";
  30. echo "-d [developer root directory] developer root directory, we use xcode-select -print-path to find default value.(default: $DEVELOPER_ROOT)";
  31. echo "-p integration pbc into this lib.";
  32. echo "-s [sdk version] sdk version, we use xcrun -sdk iphoneos --show-sdk-version to find default value.(default: $SDKVERSION)";
  33. echo "-h help message.";
  34. exit 0;
  35. ;;
  36. p)
  37. ENABLE_PBC=1;
  38. ;;
  39. s)
  40. SDKVERSION="$SDKVERSION";
  41. ;;
  42. -)
  43. break;
  44. ;;
  45. ?) #当有不认识的选项的时候arg为?
  46. echo "unkonw argument detected";
  47. exit 1;
  48. ;;
  49. esac
  50. done
  51. shift $(($OPTIND-1));
  52. echo "Ready to build for ios";
  53. echo "WORKING_DIR=${WORKING_DIR}";
  54. echo "ARCHS=${ARCHS}";
  55. echo "DEVELOPER_ROOT=${DEVELOPER_ROOT}";
  56. echo "SDKVERSION=${SDKVERSION}";
  57. echo "Integration pbc=${ENABLE_PBC}";
  58. echo "make options=$@";
  59. ##########
  60. cp -f Makefile Makefile.bak;
  61. perl -p -i -e "s;\\-shared;\\-c;g" Makefile;
  62. perl -p -i -e "s;\\s\\-[lL][^\\s]*; ;g" Makefile;
  63. for ARCH in ${ARCHS}; do
  64. echo "================== Compling $ARCH ==================";
  65. if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; then
  66. PLATFORM="iPhoneSimulator" ;
  67. else
  68. PLATFORM="iPhoneOS" ;
  69. fi
  70. echo "Building pbc-lua for ${PLATFORM} ${SDKVERSION} ${ARCH}" ;
  71. echo "Please stand by..." ;
  72. export DEVROOT="${DEVELOPER_ROOT}/Platforms/${PLATFORM}.platform/Developer" ;
  73. export SDKROOT="${DEVROOT}/SDKs/${PLATFORM}${SDKVERSION}.sdk" ;
  74. export BUILD_TOOLS="${DEVELOPER_ROOT}" ;
  75. #export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}" ;
  76. export CC=${BUILD_TOOLS}/usr/bin/gcc ;
  77. #export LD=${BUILD_TOOLS}/usr/bin/ld ;
  78. #export CPP=${BUILD_TOOLS}/usr/bin/cpp ;
  79. #export CXX=${BUILD_TOOLS}/usr/bin/g++ ;
  80. export AR=${DEVELOPER_ROOT}/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar;
  81. #export AS=${DEVROOT}/usr/bin/as ;
  82. #export NM=${DEVROOT}/usr/bin/nm ;
  83. #export CXXCPP=${BUILD_TOOLS}/usr/bin/cpp ;
  84. #export RANLIB=${BUILD_TOOLS}/usr/bin/ranlib ;
  85. export LDFLAGS="-arch ${ARCH} -isysroot ${SDKROOT} " ;
  86. export CFLAGS="-arch ${ARCH} -isysroot ${SDKROOT} -O2 -fPIC -Wall" ;
  87. make clean TARGET=libprotobuf.a;
  88. make clean TARGET=libprotobuf-$ARCH.a;
  89. make libprotobuf.a CC="$CC" CFLAGS="$CFLAGS" TARGET=libprotobuf.a $@;
  90. mv -f libprotobuf.a "libprotobuf-$ARCH.a";
  91. if [ 0 -ne $ENABLE_PBC ]; then
  92. ${AR} rc "libpbc-protobuf-$ARCH.a" "libprotobuf-$ARCH.a" ../../build/libpbc-${ARCH}.a ;
  93. fi
  94. done
  95. mv -f Makefile.bak Makefile;
  96. cd "$WORKING_DIR";
  97. echo "Linking and packaging library...";
  98. LIPO_LIBS="libprotobuf";
  99. if [ 0 -ne $ENABLE_PBC ]; then
  100. LIPO_LIBS="$LIPO_LIBS libpbc-protobuf";
  101. fi
  102. for LIB_NAME in $LIPO_LIBS; do
  103. lipo -create $LIB_NAME-*.a -output "$LIB_NAME.a";
  104. echo "$LIB_NAME.a built.";
  105. done