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 Jun 3, 2024
1 parent b3ff8f1 commit 0ff3718
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 291 deletions.
62 changes: 31 additions & 31 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,8 +31,8 @@ CONAN_OPTIONS :=

# Lockfile for cloe-deployment:
DEPLOY_LOCKFILE_SOURCE := tests/conanfile_deployment.py
DEPLOY_BUILD_LOCKFILE := ${DEPLOY_DIR}/conan.lock
DEPLOY_LOCKFILE_OPTION := --lockfile="${CLOE_ROOT}/${DEPLOY_BUILD_LOCKFILE}"
DEPLOY_BUILD_LOCKFILE := $(DEPLOY_DIR)/conan.lock
DEPLOY_LOCKFILE_OPTION := --lockfile="$(CLOE_ROOT)/$(DEPLOY_BUILD_LOCKFILE)"

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

${DEPLOY_BUILD_LOCKFILE}:
mkdir -p "${DEPLOY_DIR}"
conan lock create --lockfile-out "${DEPLOY_BUILD_LOCKFILE}" --build -- "${DEPLOY_LOCKFILE_SOURCE}"
$(DEPLOY_BUILD_LOCKFILE):
mkdir -p "$(DEPLOY_DIR)"
conan lock create --lockfile-out "$(DEPLOY_BUILD_LOCKFILE)" --build -- "$(DEPLOY_LOCKFILE_SOURCE)"

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

# Workspace targets -----------------------------------------------------------
help::
Expand All @@ -63,60 +63,60 @@ 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 deployment packages")
$(call print_help_target, package-all, "package all cloe deployment packages")
$(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 CONAN_OPTIONS="${CONAN_OPTIONS} ${DEPLOY_LOCKFILE_OPTION}"
$(MAKE) all-select CONAN_OPTIONS="$(CONAN_OPTIONS) $(DEPLOY_LOCKFILE_OPTION)"

.PHONY: status-all
status-all: ${DEPLOY_BUILD_LOCKFILE}
@for pkg in ${ALL_PKGS}; do \
${MAKE} LOCKFILE_SOURCE="" LOCKFILE_OPTION=${DEPLOY_LOCKFILE_OPTION} -C $${pkg} status || true; \
status-all: $(DEPLOY_BUILD_LOCKFILE)
@for pkg in $(ALL_PKGS); do \
$(MAKE) LOCKFILE_SOURCE="" LOCKFILE_OPTION=$(DEPLOY_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 ${DEPLOY_DIR} -g deploy .
mkdir -p ${INSTALL_DIR}
cp -r ${DEPLOY_DIR}/cloe-*/* ${INSTALL_DIR}/
$(call print_header, "Deploying binaries to $(INSTALL_DIR)...")
conan install $(CONAN_OPTIONS) --install-folder $(DEPLOY_DIR) -g deploy .
mkdir -p $(INSTALL_DIR)
cp -r $(DEPLOY_DIR)/cloe-*/* $(INSTALL_DIR)/

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

.PHONY: purge-all
purge-all:
Expand All @@ -127,7 +127,7 @@ purge-all:

.PHONY: package-all
package-all:
conan install ${CONAN_OPTIONS} --install-folder ${DEPLOY_DIR} --build=missing --build=outdated ${DEPLOY_LOCKFILE_SOURCE}
conan install $(CONAN_OPTIONS) --install-folder $(DEPLOY_DIR) --build=missing --build=outdated $(DEPLOY_LOCKFILE_SOURCE)

# Development targets ---------------------------------------------------------
help::
Expand All @@ -143,19 +143,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"

grep-conan-requires:
@rg -t py '^.*requires\(f?["](.+/[0-9]+\.[^)]+)["].*\).*$$' -r '$$1' -I --no-heading --no-line-number | sort | uniq
Expand Down
60 changes: 30 additions & 30 deletions Makefile.all
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ ALL_PKGS := \
osi \
oak \
engine \
${PLUGIN_PKGS}
$(PLUGIN_PKGS)
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 := $(wildcard 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:
Expand All @@ -78,7 +78,7 @@ models: runtime
osi: runtime models
oak: runtime
engine: models oak
${PLUGIN_PKGS}: runtime models
$(PLUGIN_PKGS): runtime models
plugins/esmini: osi

vendor/esmini: vendor/open-simulation-interface
Expand Down Expand Up @@ -114,36 +114,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 @@ -154,7 +154,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 @@ -189,19 +189,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 0ff3718

Please sign in to comment.