Cross-Platform build scripts for audio plugins
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
6.2KB

  1. #!/bin/bash
  2. # ---------------------------------------------------------------------------------------------------------------------
  3. # OS setup
  4. if [ "${LINUX}" -eq 1 ]; then
  5. APP_EXT=""
  6. CMAKE_SYSTEM_NAME="Linux"
  7. PAWPAW_TARGET="linux"
  8. elif [ "${MACOS}" -eq 1 ]; then
  9. APP_EXT=""
  10. CMAKE_SYSTEM_NAME="Darwin"
  11. if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  12. PAWPAW_TARGET="macos-universal"
  13. else
  14. PAWPAW_TARGET="macos"
  15. fi
  16. elif [ "${WIN32}" -eq 1 ]; then
  17. APP_EXT=".exe"
  18. CMAKE_SYSTEM_NAME="Windows"
  19. if [ "${WIN64}" -eq 1 ]; then
  20. PAWPAW_TARGET="win64"
  21. else
  22. PAWPAW_TARGET="win32"
  23. fi
  24. else
  25. echo "Unknown target '${target}'"
  26. if [ -z "${SOURCING_FILES}" ]; then
  27. exit 4
  28. else
  29. APP_EXT=""
  30. CMAKE_SYSTEM_NAME="Unknown"
  31. PAWPAW_TARGET="unknown"
  32. INVALID_TARGET=1
  33. fi
  34. fi
  35. # ---------------------------------------------------------------------------------------------------------------------
  36. # PawPaw setup
  37. PAWPAW_DIR="${HOME}/PawPawBuilds"
  38. PAWPAW_DOWNLOADDIR="${PAWPAW_DIR}/downloads"
  39. PAWPAW_BUILDDIR="${PAWPAW_DIR}/builds/${PAWPAW_TARGET}"
  40. PAWPAW_PREFIX="${PAWPAW_DIR}/targets/${PAWPAW_TARGET}"
  41. PAWPAW_TMPDIR="/tmp"
  42. # ---------------------------------------------------------------------------------------------------------------------
  43. # build environment
  44. ## build flags
  45. BUILD_FLAGS="-O2 -pipe -I${PAWPAW_PREFIX}/include ${EXTRA_FLAGS}"
  46. BUILD_FLAGS+=" -ffast-math"
  47. BUILD_FLAGS+=" -fPIC -DPIC -DNDEBUG -D_FORTIFY_SOURCE=2"
  48. BUILD_FLAGS+=" -fdata-sections -ffunction-sections -fno-common -fstack-protector -fvisibility=hidden"
  49. if [ -z "${PAWPAW_SKIP_LTO}" ] || [ "${PAWPAW_SKIP_LTO}" -eq 0 ]; then
  50. BUILD_FLAGS+=" -fno-strict-aliasing -flto"
  51. fi
  52. if [ "${TOOLCHAIN_PREFIX}" = "arm-linux-gnueabihf" ]; then
  53. BUILD_FLAGS+=" -mfpu=neon-vfpv4 -mfloat-abi=hard"
  54. elif [ "${TOOLCHAIN_PREFIX}" != "aarch64-linux-gnu" ]; then
  55. BUILD_FLAGS+=" -mtune=generic -msse -msse2"
  56. if [ "${MACOS_UNIVERSAL}" -eq 0 ]; then
  57. BUILD_FLAGS+=" -mfpmath=sse"
  58. fi
  59. fi
  60. if [ "${MACOS}" -eq 1 ]; then
  61. if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  62. BUILD_FLAGS+=" -DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_12"
  63. BUILD_FLAGS+=" -DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_12"
  64. BUILD_FLAGS+=" -mmacosx-version-min=10.12"
  65. BUILD_FLAGS+=" -arch x86_64 -arch arm64"
  66. export MACOSX_DEPLOYMENT_TARGET="10.12"
  67. else
  68. BUILD_FLAGS+=" -DMAC_OS_X_VERSION_MAX_ALLOWED=MAC_OS_X_VERSION_10_8"
  69. BUILD_FLAGS+=" -DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_8"
  70. BUILD_FLAGS+=" -mmacosx-version-min=10.8"
  71. BUILD_FLAGS+=" -stdlib=libc++"
  72. BUILD_FLAGS+=" -arch x86_64"
  73. BUILD_FLAGS+=" -Wno-deprecated-declarations"
  74. export MACOSX_DEPLOYMENT_TARGET="10.8"
  75. fi
  76. BUILD_FLAGS+=" -Werror=objc-method-access"
  77. elif [ "${WIN32}" -eq 1 ]; then
  78. BUILD_FLAGS+=" -D__STDC_FORMAT_MACROS=1"
  79. BUILD_FLAGS+=" -D__USE_MINGW_ANSI_STDIO=1"
  80. BUILD_FLAGS+=" -DPTW32_STATIC_LIB"
  81. BUILD_FLAGS+=" -mstackrealign"
  82. else
  83. BUILD_FLAGS+=" -fno-gnu-unique"
  84. fi
  85. # anything that talks to db should have this
  86. BUILD_FLAGS+=" -DHAVE_MIXED_SIZE_ADDRESSING"
  87. TARGET_CFLAGS="${BUILD_FLAGS}"
  88. TARGET_CXXFLAGS="${BUILD_FLAGS} -fvisibility-inlines-hidden"
  89. ## link flags
  90. LINK_FLAGS="-L${PAWPAW_PREFIX}/lib ${BUILD_FLAGS} ${EXTRA_FLAGS}"
  91. if [ -z "${PAWPAW_SKIP_LTO}" ] || [ "${PAWPAW_SKIP_LTO}" -eq 0 ]; then
  92. LINK_FLAGS+=" -Werror=odr -Werror=lto-type-mismatch"
  93. fi
  94. if [ "${MACOS}" -eq 1 ]; then
  95. LINK_FLAGS+=" -Wl,-dead_strip -Wl,-dead_strip_dylibs -Wl,-x"
  96. if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  97. LINK_FLAGS+=" -mmacosx-version-min=10.12 -arch x86_64 -arch arm64"
  98. else
  99. LINK_FLAGS+=" -mmacosx-version-min=10.8 -stdlib=libc++ -arch x86_64"
  100. fi
  101. else
  102. LINK_FLAGS+=" -Wl,-O1 -Wl,--as-needed -Wl,--gc-sections -Wl,--no-undefined -Wl,--strip-all"
  103. if [ "${WIN32}" -eq 1 ]; then
  104. LINK_FLAGS+=" -static -static-libgcc -static-libstdc++ -Wl,-Bstatic"
  105. if [ "${CROSS_COMPILING}" -eq 0 ] && [ -e "/usr/lib/libssp.a" ]; then
  106. LINK_FLAGS+=" -lssp"
  107. else
  108. LINK_FLAGS+=" -lssp_nonshared"
  109. fi
  110. else
  111. LINK_FLAGS+=" -static-libgcc -static-libstdc++"
  112. fi
  113. fi
  114. TARGET_LDFLAGS="${LINK_FLAGS}"
  115. ## toolchain
  116. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  117. if [ "${WIN64}" -eq 1 ]; then
  118. TOOLCHAIN_PREFIX="x86_64-w64-mingw32"
  119. TOOLCHAIN_PREFIX_="${TOOLCHAIN_PREFIX}-"
  120. elif [ "${WIN32}" -eq 1 ]; then
  121. TOOLCHAIN_PREFIX="i686-w64-mingw32"
  122. TOOLCHAIN_PREFIX_="${TOOLCHAIN_PREFIX}-"
  123. fi
  124. else
  125. unset TOOLCHAIN_PREFIX
  126. unset TOOLCHAIN_PREFIX_
  127. fi
  128. TARGET_AR="${TOOLCHAIN_PREFIX_}ar"
  129. TARGET_CC="${TOOLCHAIN_PREFIX_}gcc"
  130. TARGET_CXX="${TOOLCHAIN_PREFIX_}g++"
  131. TARGET_DLLWRAP="${TOOLCHAIN_PREFIX_}dllwrap"
  132. TARGET_LD="${TOOLCHAIN_PREFIX_}ld"
  133. TARGET_STRIP="${TOOLCHAIN_PREFIX_}strip"
  134. TARGET_WINDRES="${TOOLCHAIN_PREFIX_}windres"
  135. TARGET_PATH="${PAWPAW_PREFIX}/bin:/usr/${TOOLCHAIN_PREFIX}/bin:${PATH}"
  136. TARGET_PKG_CONFIG="${PAWPAW_PREFIX}/bin/pkg-config --static"
  137. TARGET_PKG_CONFIG_PATH="${PAWPAW_PREFIX}/lib/pkgconfig"
  138. # ---------------------------------------------------------------------------------------------------------------------
  139. # other
  140. MAKE_ARGS=""
  141. WAF_ARGS=""
  142. unset EXE_WRAPPER
  143. unset WINEARCH
  144. unset WINEDLLOVERRIDES
  145. unset WINEPREFIX
  146. if which nproc > /dev/null; then
  147. MAKE_ARGS+="-j $(nproc)"
  148. WAF_ARGS+="-j $(nproc)"
  149. elif [ "${MACOS}" -eq 1 ]; then
  150. MAKE_ARGS+="-j $(sysctl -n hw.logicalcpu)"
  151. WAF_ARGS+="-j $(sysctl -n hw.logicalcpu)"
  152. fi
  153. if [ "${CROSS_COMPILING}" -eq 1 ]; then
  154. MAKE_ARGS+=" CROSS_COMPILING=true"
  155. if [ "${WIN32}" -eq 1 ]; then
  156. export EXE_WRAPPER="wine"
  157. export WINEARCH="${PAWPAW_TARGET}"
  158. export WINEDLLOVERRIDES="mscoree,mshtml="
  159. export WINEPREFIX="${PAWPAW_PREFIX}/wine"
  160. fi
  161. fi
  162. if [ "${MACOS}" -eq 1 ]; then
  163. MAKE_ARGS+=" MACOS=true"
  164. if [ "${MACOS_UNIVERSAL}" -eq 1 ]; then
  165. MAKE_ARGS+=" MACOS_UNIVERSAL=true"
  166. fi
  167. elif [ "${WIN32}" -eq 1 ]; then
  168. MAKE_ARGS+=" WINDOWS=true WIN32=true"
  169. if [ "${WIN64}" -eq 1 ]; then
  170. MAKE_ARGS+=" WIN64=true"
  171. fi
  172. fi
  173. # ---------------------------------------------------------------------------------------------------------------------