Makefile 6.0 KB

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