build.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/env bash
  2. set -e
  3. set -x
  4. export PATH=/usr/sbin:/usr/bin:/sbin:/bin
  5. if uname -a | grep -qi freebsd; then
  6. export PATH="${PATH}:/usr/local/bin:/usr/local/sbin"
  7. fi
  8. if [ "${USE_CCACHE}" = "true" ] && [ -n "${CCACHE_DIR}" ] && command -v ccache >/dev/null; then
  9. # create dir first, required by realpath
  10. mkdir -p "${CCACHE_DIR}"
  11. # fix for ccache: error: BASEDIR: not an absolute path
  12. export CCACHE_DIR=$(realpath "${CCACHE_DIR}")
  13. export CCACHE_BASEDIR=$(realpath "${CCACHE_BASEDIR}")
  14. if [ -d "/usr/lib64/ccache" ]; then
  15. # fedora
  16. export PATH="/usr/lib64/ccache:${PATH}"
  17. elif [ -d "/usr/local/libexec/ccache/" ]; then
  18. # freebsd
  19. export PATH="/usr/local/libexec/ccache:${PATH}"
  20. else
  21. # debian, .....
  22. export PATH="/usr/lib/ccache:${PATH}"
  23. fi
  24. echo 'max_size = 100M' > "${CCACHE_DIR}/ccache.conf"
  25. else
  26. export USE_CCACHE="false"
  27. fi
  28. if command -v lsb_release >/dev/null && lsb_release -d | grep -qi -e debian -e ubuntu; then
  29. eval "$(dpkg-buildflags --export=sh)"
  30. export DEB_HOST_MULTIARCH=$(dpkg-architecture -qDEB_HOST_MULTIARCH)
  31. export PYTHONS="$(pyversions -v -r '>= 2.3'; py3versions -v -r '>= 3.4')"
  32. SCONSOPTS="${SCONSOPTS} libdir=/usr/lib/${DEB_HOST_MULTIARCH}"
  33. else
  34. SCONSOPTS="${SCONSOPTS} libdir=/usr/lib"
  35. fi
  36. SCONSOPTS="${SCONSOPTS} $@ prefix=/usr"
  37. SCONSOPTS="${SCONSOPTS} systemd=yes"
  38. SCONSOPTS="${SCONSOPTS} nostrip=yes"
  39. SCONSOPTS="${SCONSOPTS} dbus_export=yes"
  40. SCONSOPTS="${SCONSOPTS} docdir=/usr/share/doc/gpsd"
  41. SCONSOPTS="${SCONSOPTS} gpsd_user=gpsd"
  42. SCONSOPTS="${SCONSOPTS} gpsd_group=dialout"
  43. SCONSOPTS="${SCONSOPTS} debug=yes"
  44. # set qt_versioned here only for non-CentOS systems (CentOS below)
  45. if [ ! -f "/etc/centos-release" ]; then
  46. SCONSOPTS="${SCONSOPTS} qt_versioned=5"
  47. fi
  48. export SCONS=$(command -v scons)
  49. if command -v nproc >/dev/null; then
  50. NPROC=$(nproc)
  51. SCONS_PARALLEL="-j ${NPROC} "
  52. if [ "${SLOW_CHECK}" != "yes" ]; then
  53. CHECK_NPROC=$(( 4 * ${NPROC} ))
  54. SCONS_CHECK_PARALLEL="-j ${CHECK_NPROC} "
  55. else
  56. SCONS_CHECK_PARALLEL="${SCONS_PARALLEL}"
  57. fi
  58. else
  59. SCONS_PARALLEL=""
  60. SCONS_CHECK_PARALLEL=""
  61. fi
  62. if [ -f "/etc/centos-release" ]; then
  63. if grep -q "^CentOS Linux release 7" /etc/centos-release ; then
  64. export PYTHONS="2"
  65. # Qt version 5 currently doesn't compile, so omit versioning
  66. # for now
  67. #SCONSOPTS="${SCONSOPTS} qt_versioned=5"
  68. elif grep -q "^CentOS Linux release 8" /etc/centos-release ; then
  69. export SCONS=$(command -v scons-3)
  70. export PYTHONS="3"
  71. SCONSOPTS="${SCONSOPTS} qt_versioned=5"
  72. else
  73. # other CentOS versions not explicitly considered here, handle
  74. # as per non-CentOS logic
  75. SCONSOPTS="${SCONSOPTS} qt_versioned=5"
  76. fi
  77. fi
  78. export SCONSOPTS
  79. if [ -z "$PYTHONS" ]; then
  80. export PYTHONS="3"
  81. fi
  82. if [ -n "${SCAN_BUILD}" ]; then
  83. export PYTHONS="3"
  84. fi
  85. for py in $PYTHONS; do
  86. _SCONS="${SCONS} target_python=python${py}"
  87. python${py} ${_SCONS} ${SCONSOPTS} --clean
  88. rm -f .sconsign.*.dblite
  89. ${SCAN_BUILD} python${py} ${_SCONS} ${SCONS_PARALLEL}${SCONSOPTS} build-all
  90. if [ -z "${NOCHECK}" ]; then
  91. python${py} ${_SCONS} ${SCONS_CHECK_PARALLEL}${SCONSOPTS} check
  92. fi
  93. done
  94. if [ "${USE_CCACHE}" = "true" ]; then
  95. ccache -s
  96. fi