Makefile 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. GNUMAKEFLAGS+= --no-print-directory
  2. export GNUMAKEFLAGS
  3. export CCWS_ROOT=$(shell pwd)
  4. export CCWS_DIR=${CCWS_ROOT}/ccws
  5. -include ${CCWS_DIR}/make/config.mk
  6. export WORKSPACE_DIR?=${CCWS_ROOT}
  7. WORKSPACE_SRC?=${WORKSPACE_DIR}/src
  8. override export WORKSPACE_SRC::=$(shell realpath "${WORKSPACE_SRC}")
  9. -include ${WORKSPACE_SRC}/.ccws/config.mk
  10. # obtain from gitconfig by default
  11. export EMAIL?=$(shell git config --get user.email || echo "ccws@ccws.net")
  12. export AUTHOR?=$(shell git config --get user.name || echo "ccws")
  13. # no default, can be derived in many cases, in some must be set explicitly
  14. export ROS_DISTRO
  15. # build profiles (comma separated)
  16. BUILD_PROFILE?=reldebug
  17. # TODO DEPRECATED[use BUILD_PROFILE] used in build profile mixins and profile creation targets
  18. BASE_BUILD_PROFILE?=
  19. export CCWS_BUILD_PROFILES=$(shell echo "${BUILD_PROFILE},${BASE_BUILD_PROFILE}" | sed -e 's/,,//g' -e 's/,$$//g')
  20. export CCWS_BUILD_PROFILES_ID=$(shell echo "${CCWS_BUILD_PROFILES}" | sed -e 's/,/_/g')
  21. export CCWS_PRIMARY_BUILD_PROFILE=$(shell echo ${CCWS_BUILD_PROFILES} | cut -f 1 -d ',')
  22. export CCWS_SECONDARY_BUILD_PROFILE=$(shell echo ${CCWS_BUILD_PROFILES} | cut -f 2 -d ',')
  23. export CCWS_BUILD_PROFILES_TAIL=$(shell echo ${CCWS_BUILD_PROFILES} | cut -f 2- -d ',')
  24. export CCWS_BUILD_SPACE_DIR=${WORKSPACE_DIR}/build/${CCWS_BUILD_PROFILES_ID}
  25. # default package type
  26. export PKG_TYPE?=catkin
  27. # global version, string, added to deb package names to enable multiple installations
  28. export VERSION?=staging
  29. # Used in binary package names
  30. export VENDOR?=ccws
  31. # default new package license
  32. export LICENSE?=Apache 2.0
  33. export REPO_LIST_FORMAT?=repos
  34. export WORKSPACE_INSTALL?=${WORKSPACE_DIR}/install/${CCWS_BUILD_PROFILES}
  35. export ARTIFACTS_DIR=${WORKSPACE_DIR}/artifacts
  36. # maximum amout of memory required for a single compilation job -- used to compute job limit
  37. MEMORY_PER_JOB_MB?=2048
  38. export JOBS?=$(shell ${CCWS_DIR}/scripts/guess_jobs.sh ${MEMORY_PER_JOB_MB})
  39. # Cache directory
  40. # 1. keep cache in ccws root directory, old behavior, restore using config.mk if necessary
  41. #export CCWS_CACHE?=${WORKSPACE_DIR}/cache
  42. # 2. follow XDG specification
  43. XDG_CACHE_HOME?=${HOME}/.cache
  44. export CCWS_CACHE?=${XDG_CACHE_HOME}/ccws
  45. export OS_DISTRO_BUILD?=$(shell lsb_release -cs)
  46. # default package to build can be specified in source directory or via command line,
  47. # when not provided usually all packages in the workspace are processed
  48. export PKG?=$(shell (cat "${WORKSPACE_SRC}/.ccws/package" 2> /dev/null | sed -e 's/[[:space:]]*\#.*//' -e '/^[[:space:]]*$$/d' | paste -d ' ' -s) || echo "")
  49. export PKG_ID=$(shell echo "${PKG}" | md5sum | cut -f 1 -d ' ')
  50. # helpers
  51. export BUILD_PROFILES_DIR=${CCWS_DIR}/profiles/build/
  52. export EXEC_PROFILES_DIR=${CCWS_DIR}/profiles/exec/
  53. MAKE_QUIET=${MAKE} --quiet --no-print-directory
  54. SETUP_SCRIPT?=source ${BUILD_PROFILES_DIR}/${CCWS_PRIMARY_BUILD_PROFILE}/setup.bash ${CCWS_BUILD_PROFILES_TAIL}
  55. CMD_PKG_NAME_LIST=colcon --log-base /dev/null list --topological-order --names-only --base-paths ${WORKSPACE_SRC}
  56. CMD_PKG_LIST=colcon --log-base /dev/null list --topological-order --base-paths ${WORKSPACE_SRC}
  57. CMD_PKG_INFO=colcon --log-base /dev/null info --base-paths ${WORKSPACE_SRC}
  58. CMD_PKG_GRAPH=colcon graph --base-paths ${WORKSPACE_SRC} --dot --dot-cluster
  59. CMD_WSHANDLER=${CCWS_DIR}/scripts/wshandler -r ${WORKSPACE_SRC} -t ${REPO_LIST_FORMAT} -c ${CCWS_CACHE}/wshandler
  60. ##
  61. ## Default target (build)
  62. ##
  63. default: build
  64. .DEFAULT:
  65. make build_glob PKG_NAME_PART=$@
  66. # include after default targets to avoid shadowing them
  67. -include ${CCWS_DIR}/profiles/*/*/*.mk
  68. -include ${CCWS_DIR}/make/*.mk
  69. # make tries to remake missing files, intercept these attempts
  70. %.mk:
  71. @false
  72. ${WORKSPACE_SRC}/.ccws/config.mk:
  73. @false
  74. ##
  75. ## Workspace targets
  76. ##
  77. log_output:
  78. mkdir -p ${ARTIFACTS_DIR}/${MAKE}
  79. ${MAKE} log_output_to_file OUTPUT_LOG_FILE=\"${ARTIFACTS_DIR}/${MAKE}/${TARGET}_${OUTPUT_LOG_ID}_`env | md5sum | cut -f 1 -d ' '`.log\"
  80. log_output_to_file:
  81. ${MAKE} ${TARGET} 2>&1 | ts "[%F %T %.s]" > ${OUTPUT_LOG_FILE}
  82. # warning: MAKEFLAGS set in setup scripts is overriden by make
  83. wswraptarget:
  84. bash -c "time (${SETUP_SCRIPT}; ${MAKE} --no-print-directory ${TARGET})"
  85. wslist:
  86. @test -z "${PKG}" || ${CMD_PKG_NAME_LIST} --packages-up-to ${PKG}
  87. @test -n "${PKG}" || ${CMD_PKG_NAME_LIST}
  88. # Reset & initialize workspace
  89. wsinit:
  90. ! ${CMD_WSHANDLER} is_source_space
  91. mkdir -p "${WORKSPACE_SRC}"
  92. touch "${WORKSPACE_SRC}/.${REPO_LIST_FORMAT}"
  93. cd ${WORKSPACE_SRC}; bash -c "echo '${REPOS}' | sed -e 's/ \+/ /g' -e 's/ /\n/g' | xargs -P ${JOBS} --no-run-if-empty -I {} git clone {}"
  94. -${MAKE} wsscrape_all
  95. ${MAKE} wsupdate
  96. # Status packages in the workspace
  97. wsstatus:
  98. test ! -d .git || git status
  99. ${MAKE} wsstatuspkg
  100. wsstatuspkg:
  101. ${CMD_WSHANDLER} status
  102. # Add new packages to the workspace
  103. wsscrape:
  104. ${CMD_WSHANDLER} scrape
  105. wsscrape_all:
  106. ${CMD_WSHANDLER} -p add scrape
  107. # Update workspace & all packages
  108. wsupdate:
  109. -git pull --rebase
  110. ${MAKE} wsupdate_pkgs
  111. wsupdate_shallow:
  112. -git pull --rebase
  113. ${MAKE} wsupdate_pkgs_shallow
  114. # Update workspace & all packages
  115. wsupdate_pkgs:
  116. ${CMD_WSHANDLER} -j ${JOBS} -k update
  117. wsupdate_pkgs_shallow:
  118. ${CMD_WSHANDLER} -j ${JOBS} -p shallow update
  119. wsupdate_pkgs_shallow_rebase:
  120. ${CMD_WSHANDLER} -j ${JOBS} -p shallow,rebase update
  121. ccache_stats:
  122. bash -c "${SETUP_SCRIPT}; ccache --show-stats"
  123. ##
  124. ## Package targets
  125. ##
  126. assert_PKG_arg_must_be_specified:
  127. test "${PKG}" != ""
  128. assert_AUTHOR_must_not_be_empty:
  129. test "${AUTHOR}" != ""
  130. assert_EMAIL_must_not_be_empty:
  131. test "${EMAIL}" != ""
  132. assert_JOBS_arg_must_be_positive_integer:
  133. test "${JOBS}" -gt 0
  134. build_glob:
  135. bash -c "${MAKE} PKG=\"\$$(${CMD_PKG_NAME_LIST} | grep '${PKG_NAME_PART}' | paste -d ' ' -s)\""
  136. build_all:
  137. bash -c "${MAKE} PKG=\"\$$(${CMD_PKG_NAME_LIST} | paste -d ' ' -s)\""
  138. build: assert_BUILD_PROFILES_must_exist
  139. ${MAKE} wswraptarget TARGET=bp_${CCWS_PRIMARY_BUILD_PROFILE}_build
  140. bp_%_build: private_build
  141. # skip to default
  142. # --log-level DEBUG
  143. private_build: assert_PKG_arg_must_be_specified assert_JOBS_arg_must_be_positive_integer
  144. mkdir -p "${CCWS_BUILD_SPACE_DIR}"
  145. # override make flags to enable multithreaded builds
  146. env MAKEFLAGS="-j${JOBS}" ${CCWS_BUILD_WRAPPER} colcon \
  147. --log-base ${CCWS_LOG_DIR} \
  148. build \
  149. --event-handlers console_direct+ \
  150. --merge-install \
  151. --executor sequential \
  152. --base-paths ${WORKSPACE_SRC} \
  153. --build-base "${CCWS_BUILD_SPACE_DIR}" \
  154. --install-base "${CCWS_INSTALL_DIR_BUILD}" \
  155. --cmake-args -DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN_FILE}" \
  156. --packages-up-to ${PKG}
  157. add:
  158. ${CMD_WSHANDLER} is_source_space || ${MAKE} wsinit
  159. bash -c "\
  160. DIR=\$$(basename ${REPO} | sed -e 's/\.git$$//'); \
  161. ${CMD_WSHANDLER} add git \$${DIR} ${REPO} ${VERSION}"
  162. graph:
  163. @test -z "${PKG}" || ${CMD_PKG_GRAPH} --packages-up-to ${PKG}
  164. @test -n "${PKG}" || ${CMD_PKG_GRAPH}
  165. graph_reverse: assert_PKG_arg_must_be_specified
  166. @test -z "${PKG}" || ${CMD_PKG_GRAPH} --packages-above ${PKG}
  167. ##
  168. ## Other targets
  169. ##
  170. help:
  171. @grep -v "^ " Makefile ${CCWS_DIR}/make/*.mk | grep -v "^ " | grep -v "^$$" | grep -v "^\." | grep -v ".mk:$$"
  172. .PHONY: build clean test install