Skip to content

Commit

Permalink
tooling: Fix interspersed $() and ${} in Makefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
cassava committed Dec 5, 2023
1 parent cd01eee commit 149cf69
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 165 deletions.
57 changes: 28 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ GNUMAKEFLAGS := --no-print-directory
SUBMAKEFLAGS :=

CLOE_ROOT := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
CLOE_LAUNCH := PYTHONPATH="${CLOE_ROOT}/cli" python3 -m cloe_launch
CLOE_LAUNCH := PYTHONPATH="$(CLOE_ROOT)/cli" python3 -m cloe_launch

include ${CLOE_ROOT}/Makefile.help
include $(CLOE_ROOT)/Makefile.help

# Set the clang-format command line to use:
CLANG_FORMAT := $(shell command -v clang-format 2>/dev/null)
Expand All @@ -31,7 +31,7 @@ CONAN_OPTIONS :=
# Lockfile for cloe-meta:
META_LOCKFILE_SOURCE := meta/conanfile.py
META_BUILD_LOCKFILE := meta/build/conan.lock
META_LOCKFILE_OPTION := --lockfile="${CLOE_ROOT}/${META_BUILD_LOCKFILE}"
META_LOCKFILE_OPTION := --lockfile="$(CLOE_ROOT)/$(META_BUILD_LOCKFILE)"

.DEFAULT_GOAL := help
.PHONY: help
Expand All @@ -46,11 +46,11 @@ help::
# Setup targets ---------------------------------------------------------------
include Makefile.setup

${META_BUILD_LOCKFILE}:
${MAKE} -C meta LOCKFILE_SOURCE=conanfile.py lockfile
$(META_BUILD_LOCKFILE):
$(MAKE) -C meta LOCKFILE_SOURCE=conanfile.py lockfile

.PHONY: lockfile
lockfile: ${META_BUILD_LOCKFILE}
lockfile: $(META_BUILD_LOCKFILE)

# Workspace targets -----------------------------------------------------------
help::
Expand All @@ -61,60 +61,59 @@ help::
.PHONY: docs
docs:
$(call print_header, "Generating Doxygen documentation...")
${MAKE} -C docs doxygen
$(MAKE) -C docs doxygen
$(call print_header, "Generating Sphinx documentation...")
${MAKE} -C docs html
$(MAKE) -C docs html

help::
$(call print_help_target, export-cli, "export ${_yel}cloe-launch-profile${_rst} Conan recipe")
$(call print_help_target, deploy-cli, "install ${_yel}cloe-launch${_rst} with ${_dim}${PIPX}${_rst}")
$(call print_help_target, export-cli, "export $(_yel)cloe-launch-profile$(_rst) Conan recipe")
$(call print_help_target, deploy-cli, "install $(_yel)cloe-launch$(_rst) with $(_dim)$(PIPX)$(_rst)")
echo

.PHONY: export-cli
export-cli:
${MAKE} -C cli export
$(MAKE) -C cli export

.PHONY: deploy-cli
deploy-cli:
$(call print_header, "Deploying cloe-launch binary with pip...")
${MAKE} -C cli install
$(MAKE) -C cli install

help::
$(call print_help_target, lockfile, "create a lockfile for cloe-meta package")
$(call print_help_target, status-all, "show status of each of the Conan packages")
$(call print_help_target, export-all, "export all package sources to Conan cache")
$(call print_help_target, build-all, "build individual packages locally in-source")
$(call print_help_target, deploy-all, "deploy Cloe to INSTALL_DIR [=${INSTALL_DIR}]")
$(call print_help_target, deploy-all, "deploy $(_yel)cloe$(_rst) to $(_grn)INSTALL_DIR$(_rst)=$(_dim)$(INSTALL_DIR)$(_rst)")
$(call print_help_target, clean-all, "clean entire repository of temporary files")
$(call print_help_target, purge-all, "remove all cloe packages (in any version) from Conan cache")
echo

.PHONY: build-all
build-all: lockfile
${MAKE} all-select UNSELECT_PKGS="meta" CONAN_OPTIONS="${CONAN_OPTIONS} ${META_LOCKFILE_OPTION}"
$(MAKE) all-select UNSELECT_PKGS="meta" CONAN_OPTIONS="$(CONAN_OPTIONS) $(META_LOCKFILE_OPTION)"

.PHONY: status-all
status-all: ${META_BUILD_LOCKFILE}
@for pkg in ${ALL_PKGS}; do \
[ -d $${pkg} ] || continue; \
${MAKE} LOCKFILE_SOURCE="" LOCKFILE_OPTION=${META_LOCKFILE_OPTION} -C $${pkg} status || true; \
status-all: $(META_BUILD_LOCKFILE)
@for pkg in $(ALL_PKGS); do \
$(MAKE) LOCKFILE_SOURCE="" LOCKFILE_OPTION=$(META_LOCKFILE_OPTION) -C $${pkg} status || true; \
done

.PHONY: export-all
export-all:
$(call print_header, "Exporting all cloe Conan packages...")
${MAKE} export-select export-cli export
$(MAKE) export-select export-cli export

.PHONY: deploy-all
deploy-all:
$(call print_header, "Deploying binaries to ${INSTALL_DIR}...")
conan install ${CONAN_OPTIONS} --install-folder ${BUILD_DIR}/deploy -g deploy .
mkdir -p ${INSTALL_DIR}
cp -r ${BUILD_DIR}/deploy/cloe-*/* ${INSTALL_DIR}/
$(call print_header, "Deploying binaries to $(INSTALL_DIR)...")
conan install $(CONAN_OPTIONS) --install-folder $(BUILD_DIR)/deploy -g deploy .
mkdir -p $(INSTALL_DIR)
cp -r $(BUILD_DIR)/deploy/cloe-*/* $(INSTALL_DIR)/

.PHONY: clean-all
clean-all:
${MAKE} clean clean-select
$(MAKE) clean clean-select

.PHONY: purge-all
purge-all:
Expand All @@ -137,19 +136,19 @@ format:
# continues to work as expected.
#
# See: https://www.moxio.com/blog/43/ignoring-bulk-change-commits-with-git-blame
find . -type f -not -path '*/\.git/*' -and \( -name '*.cpp' -o -name '*.hpp' \) -exec ${CLANG_FORMAT} ${CLANG_FORMAT_ARGS} -i {} \;
find . -type f -not -path '*/\.git/*' -and \( -name '*.cpp' -o -name '*.hpp' \) -exec $(CLANG_FORMAT) $(CLANG_FORMAT_ARGS) -i {} \;

.PHONY: todos
todos:
${AG} TODO
${AG} FIXME
${AG} XXX
$(AG) TODO
$(AG) FIXME
$(AG) XXX

# Hidden development targets --------------------------------------------------

.PHONY: grep-uuids
grep-uuids:
${AG} "\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b"
$(AG) "\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b"

.PHONY: find-missing-eol
find-missing-eol:
Expand Down
62 changes: 31 additions & 31 deletions Makefile.all
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,32 @@ SUBMAKEFLAGS :=

META_PKG := meta
PLUGIN_PKGS := plugins/basic plugins/gndtruth_extractor plugins/minimator plugins/mocks plugins/noisy_sensor plugins/speedometer plugins/virtue
ALL_PKGS := fable runtime models oak engine ${PLUGIN_PKGS} ${META_PKG}
ALL_PKGS := fable runtime models oak engine $(PLUGIN_PKGS) $(META_PKG)
WITHOUT_PKGS :=
UNSELECT_PKGS := ${WITHOUT_PKGS}
UNSELECT_PKGS := $(WITHOUT_PKGS)
WITH_PKGS :=
SELECT_PKGS := $(call uniq, $(filter-out ${UNSELECT_PKGS}, ${ALL_PKGS}) ${WITH_PKGS})
.PHONY: ${ALL_PKGS}
SELECT_PKGS := $(call uniq, $(filter-out $(UNSELECT_PKGS), $(ALL_PKGS)) $(WITH_PKGS))
.PHONY: $(ALL_PKGS)

## VENDOR PACKAGE SELECTION
##
## Functions analogously to normal package selection.
##
ALL_VENDOR :=
WITHOUT_VENDOR :=
UNSELECT_VENDOR := ${WITHOUT_VENDOR}
UNSELECT_VENDOR := $(WITHOUT_VENDOR)
WITH_VENDOR :=
SELECT_VENDOR := $(call uniq, $(filter-out ${UNSELECT_VENDOR}, ${ALL_VENDOR}) ${WITH_VENDOR})
.PHONY: ${ALL_VENDOR}
SELECT_VENDOR := $(call uniq, $(filter-out $(UNSELECT_VENDOR), $(ALL_VENDOR)) $(WITH_VENDOR))
.PHONY: $(ALL_VENDOR)

# Specify dependencies:
fable:
runtime: fable
models: runtime
oak: runtime
engine: models oak
${PLUGIN_PKGS}: runtime models
${META_PKG}: fable runtime models oak engine ${PLUGIN_PKGS}
$(PLUGIN_PKGS): runtime models
$(META_PKG): fable runtime models oak engine $(PLUGIN_PKGS)

## BUILD_POLICY
## Usage: make BUILD_POLICY="missing"
Expand Down Expand Up @@ -93,36 +93,36 @@ CONAN_OPTIONS :=

# Usage: $(call _make_target_rule, TARGET-NAME, MAKE-TARGET, HELP-DESCRIPTION, MAKE-ARGUMENTS)
define _make_target_rule
${1}:
$(call print_header, "Proceeding to $(call unquote, ${3})")
${MAKE} ${SUBMAKEFLAGS} ${4} ${2}
$(1):
$(call print_header, "Proceeding to $(call unquote, $(3))")
$(MAKE) $(SUBMAKEFLAGS) $(4) $(2)
endef

# Usage: $(call _make_target_rules, TARGET-NAME, HELP-DESCRIPTION, HELP-CATEGORY, PACKAGE-DIRS)
define _make_target_rules
help::
$(call print_help_target, ${1}, ${2}, ${3})
$(call _make_target_rule,${1},${1}-each,${2},-f Makefile.all)
${1}-each: ${4}
$(call print_help_target, $(1), $(2), $(3))
$(call _make_target_rule,$(1),$(1)-each,$(2),-f Makefile.all)
$(1)-each: $(4)
endef

REGEX_TARGET := 's/(-vendor|-select)?-each//'
${ALL_PKGS} ${ALL_VENDOR}:
${MAKE} -C $@ $(shell echo ${MAKECMDGOALS} | sed -re ${REGEX_TARGET})
$(ALL_PKGS) $(ALL_VENDOR):
$(MAKE) -C $@ $(shell echo $(MAKECMDGOALS) | sed -re $(REGEX_TARGET))

# Usage: $(call make_vendor_target, TARGET-NAME, HELP-DESCRIPTION, HELP-CATEGORY)
define make_vendor_target
$(eval $(call _make_target_rules,${1},${2},${3},${SELECT_VENDOR}))
$(eval $(call _make_target_rules,$(1),$(2),$(3),$(SELECT_VENDOR)))
endef

# Usage: $(call make_every_target, TARGET-NAME, HELP-DESCRIPTION, HELP-CATEGORY)
define make_every_target
$(eval $(call _make_target_rules,${1},${2},${3},${ALL_PKGS}))
$(eval $(call _make_target_rules,$(1),$(2),$(3),$(ALL_PKGS)))
endef

# Usage: $(call make_select_target, TARGET-NAME, HELP-DESCRIPTION, HELP-CATEGORY)
define make_select_target
$(eval $(call _make_target_rules,${1},${2},${3},${SELECT_PKGS}))
$(eval $(call _make_target_rules,$(1),$(2),$(3),$(SELECT_PKGS)))
endef

# --------------------------------------------------------------------------- #
Expand All @@ -133,7 +133,7 @@ endef
help::
$(call print_help_section, "Available multi-package targets")

ifneq "${ALL_VENDOR}" ""
ifneq "$(ALL_VENDOR)" ""
help::
$(call make_vendor_target, export-vendor, "export all vendor packages", "[conan-cache]")
$(call make_vendor_target, package-vendor, "create all vendor packages", "[conan-cache]")
Expand Down Expand Up @@ -168,19 +168,19 @@ $(call make_select_target, clean-select, "remove build artifacts", "[in-source]"
help::
echo
$(call print_help_subsection, "Options")
ifneq "${ALL_VENDOR}" ""
$(call print_help_option, WITH_VENDOR, "", "include optional vendor packages from ${_grn}UNSELECT_VENDOR${_rst}")
ifneq "$(ALL_VENDOR)" ""
$(call print_help_option, WITH_VENDOR, "", "include optional vendor packages from $(_grn)UNSELECT_VENDOR$(_rst)")
endif
$(call print_help_option, WITH_PKGS, "", "include optional packages from ${_grn}UNSELECT_PKGS${_rst}")
$(call print_help_option, WITH_PKGS, "", "include optional packages from $(_grn)UNSELECT_PKGS$(_rst)")
$(call print_help_option, LOCKFILE_SOURCE, "", "use specified conanfile as lockfile source for build")
echo
$(call print_help_subsection, "Defines")
$(call print_help_option, BUILD_POLICY, ${BUILD_POLICY})
$(call print_help_define, CONAN_OPTIONS, ${CONAN_OPTIONS})
ifneq "${ALL_VENDOR}" ""
$(call print_help_define_lines, UNSELECT_VENDOR, ${UNSELECT_VENDOR})
$(call print_help_define_lines, SELECT_VENDOR, ${SELECT_VENDOR})
$(call print_help_option, BUILD_POLICY, $(BUILD_POLICY))
$(call print_help_define, CONAN_OPTIONS, $(CONAN_OPTIONS))
ifneq "$(ALL_VENDOR)" ""
$(call print_help_define_lines, UNSELECT_VENDOR, $(UNSELECT_VENDOR))
$(call print_help_define_lines, SELECT_VENDOR, $(SELECT_VENDOR))
endif
$(call print_help_define_lines, UNSELECT_PKGS, ${UNSELECT_PKGS})
$(call print_help_define_lines, SELECT_PKGS, ${SELECT_PKGS})
$(call print_help_define_lines, UNSELECT_PKGS, $(UNSELECT_PKGS))
$(call print_help_define_lines, SELECT_PKGS, $(SELECT_PKGS))
echo
Loading

0 comments on commit 149cf69

Please sign in to comment.