From 6c1060851a09a4611169eb1cbb919787eb08fff8 Mon Sep 17 00:00:00 2001 From: Jacob Faibussowitsch Date: Fri, 25 Jul 2025 11:32:42 -0400 Subject: [PATCH 1/4] Move more default makefile variables to aedifix --- src/aedifix/config.py | 7 +- src/aedifix/templates/variables.mk.in | 98 ++++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 2 deletions(-) diff --git a/src/aedifix/config.py b/src/aedifix/config.py index afc508d..80d4d5c 100644 --- a/src/aedifix/config.py +++ b/src/aedifix/config.py @@ -52,7 +52,12 @@ def __init__( config_file = config_file.with_suffix("") self._project_variables_file = self.project_arch_dir / config_file.name - self._default_subst = {"PYTHON_EXECUTABLE": sys.executable} + self._default_subst = { + "PYTHON_EXECUTABLE": sys.executable, + "PROJECT_NAME": manager.project_name_upper, + "PROJECT_DIR_NAME": manager.project_dir_name, + "PROJECT_ARCH_NAME": manager.project_arch_name, + } @property def template_file(self) -> Path: diff --git a/src/aedifix/templates/variables.mk.in b/src/aedifix/templates/variables.mk.in index 7275eb2..3fcdf72 100644 --- a/src/aedifix/templates/variables.mk.in +++ b/src/aedifix/templates/variables.mk.in @@ -1,5 +1,101 @@ # -*- mode: makefile-gmake -*- +export SHELL ?= /usr/bin/env bash +export AWK ?= awk export PYTHON ?= @AEDIFIX_PYTHON_EXECUTABLE@ export CMAKE ?= @CMAKE_COMMAND@ -export CMAKE_BUILD_PARALLEL_LEVEL ?= @CMAKE_BUILD_PARALLEL_LEVEL@ export CMAKE_GENERATOR ?= @CMAKE_GENERATOR@ + +ifeq (4.2,$(firstword $(sort $(MAKE_VERSION) 4.2))) + # Since make 4.2: + # + # * The amount of parallelism can be determined by querying MAKEFLAGS, even when + # the job server is enabled (previously MAKEFLAGS would always contain only + # "-j", with no number, when job server was enabled). + # + # https://lists.gnu.org/archive/html/info-gnu/2016-05/msg00013.html + JOBS = $(patsubst -j%,%,$(filter -j%,$(MAKEFLAGS))) +else + JOBS = +endif + +ifeq ($(strip $(JOBS)),) + # Parse the number of jobs from inspecting process list + MAKE_PID = $(shell echo $$PPID) + ifeq ($(strip $(MAKE_PID)),) + JOBS = + else + SED ?= sed + PS ?= ps + JOBS = $(strip $(shell $(PS) T | $(SED) -n 's%.*$(MAKE_PID).*$(MAKE).* \(-j\|--jobs\) *\([0-9][0-9]*\).*%\2%p')) + endif +endif + +# Order of precedence is as follows: +# +# 1. -j N, if given by the user. +# 2. CMAKE_BUILD_PARALLEL_LEVEL if defined in the environment. +# 3. CMAKE_BUILD_PARALLEL_LEVEL from default by configure. +ifeq ($(strip $(JOBS)),) + export CMAKE_BUILD_PARALLEL_LEVEL ?= @CMAKE_BUILD_PARALLEL_LEVEL@ +else + # use := to override any potential value of CMAKE_BUILD_PARALLEL_LEVEL + export CMAKE_BUILD_PARALLEL_LEVEL := $(JOBS) +endif + +ifeq ($(strip $(V)),1) + export VERBOSE ?= 1 +else ifeq ($(strip $(V)),0) + export VERBOSE ?= 0 +endif + +AEDIFIX_CMAKE_DIR = $(@AEDIFIX_PROJECT_DIR_NAME@)/$(@AEDIFIX_PROJECT_ARCH_NAME@)/cmake_build + +export @AEDIFIX_PROJECT_NAME_UPPER@_BUILD_COMMAND ?= $(CMAKE) --build $(AEDIFIX_CMAKE_DIR) +export @AEDIFIX_PROJECT_NAME_UPPER@_INSTALL_COMMAND ?= $(CMAKE) --install $(AEDIFIX_CMAKE_DIR) + +ifeq ($(strip $(PREFIX)),) +export @AEDIFIX_PROJECT_NAME_UPPER@_INSTALL_PREFIX_COMMAND = # nothing +else +export @AEDIFIX_PROJECT_NAME_UPPER@_INSTALL_PREFIX_COMMAND = --prefix $(PREFIX) +endif + +ifndef NINJA_STATUS +SELECTED_COLOR = $(shell aedifix-select-arch-color $(@AEDIFIX_PROJECT_ARCH_NAME@)) +COLOR_ARCH = $(shell $(CMAKE) -E cmake_echo_color --switch=$(COLOR) --$(SELECTED_COLOR) $(@AEDIFIX_PROJECT_ARCH_NAME@)) +export NINJA_STATUS = [%f/%t] $(COLOR_ARCH): $(SOME_UNDEFINED_VARIABLE_TO_ADD_A_SPACE) +endif + +## Print this help message. +## +.PHONY: help +help: + @printf "Usage: make [MAKE_OPTIONS] [target] (see 'make --help' for MAKE_OPTIONS)\n" + @printf "" + @$(AWK) ' \ + { \ + if ($$0 ~ /^.PHONY: [a-zA-Z\-\0-9]+$$/) { \ + helpCommand = substr($$0, index($$0, ":") + 2); \ + if (helpMessage) { \ + printf "\033[36m%-20s\033[0m %s\n", helpCommand, helpMessage; \ + helpMessage = ""; \ + } \ + } else if ($$0 ~ /^[a-zA-Z\-\0-9.]+:/) { \ + helpCommand = substr($$0, 0, index($$0, ":")); \ + if (helpMessage) { \ + printf "\033[36m%-20s\033[0m %s\n", helpCommand, helpMessage; \ + helpMessage = ""; \ + } \ + } else if ($$0 ~ /^##/) { \ + if (helpMessage) { \ + helpMessage = helpMessage"\n "substr($$0, 3); \ + } else { \ + helpMessage = substr($$0, 3); \ + } \ + } else { \ + if (helpMessage) { \ + print "\n "helpMessage"\n"; \ + } \ + helpMessage = ""; \ + } \ + }' \ + $(MAKEFILE_LIST) From 517a638e6c8fad118b1987ee1b4de373f43680b9 Mon Sep 17 00:00:00 2001 From: Jacob Faibussowitsch Date: Fri, 25 Jul 2025 11:57:18 -0400 Subject: [PATCH 2/4] fixup! Move more default makefile variables to aedifix --- src/aedifix/templates/variables.mk.in | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/aedifix/templates/variables.mk.in b/src/aedifix/templates/variables.mk.in index 3fcdf72..8d5bf4b 100644 --- a/src/aedifix/templates/variables.mk.in +++ b/src/aedifix/templates/variables.mk.in @@ -1,10 +1,17 @@ # -*- mode: makefile-gmake -*- +# This file was automatically generated by aedifix. Do not manually edit this file, as +# subsequent calls to configure (or reconfigure) will overwrite any changes. +.NOTPARALLEL: + export SHELL ?= /usr/bin/env bash export AWK ?= awk export PYTHON ?= @AEDIFIX_PYTHON_EXECUTABLE@ export CMAKE ?= @CMAKE_COMMAND@ export CMAKE_GENERATOR ?= @CMAKE_GENERATOR@ +# ============================================ +# Translating the -j parallelism flag to cmake +# ifeq (4.2,$(firstword $(sort $(MAKE_VERSION) 4.2))) # Since make 4.2: # @@ -42,12 +49,18 @@ else export CMAKE_BUILD_PARALLEL_LEVEL := $(JOBS) endif +# ================== +# Handling verbosity +# ifeq ($(strip $(V)),1) export VERBOSE ?= 1 else ifeq ($(strip $(V)),0) export VERBOSE ?= 0 endif +# ============================ +# Default and install commands +# AEDIFIX_CMAKE_DIR = $(@AEDIFIX_PROJECT_DIR_NAME@)/$(@AEDIFIX_PROJECT_ARCH_NAME@)/cmake_build export @AEDIFIX_PROJECT_NAME_UPPER@_BUILD_COMMAND ?= $(CMAKE) --build $(AEDIFIX_CMAKE_DIR) @@ -59,16 +72,20 @@ else export @AEDIFIX_PROJECT_NAME_UPPER@_INSTALL_PREFIX_COMMAND = --prefix $(PREFIX) endif +# ========================================================================== +# Make Ninja use a new color per arch directory to help differentiate builds +# ifndef NINJA_STATUS SELECTED_COLOR = $(shell aedifix-select-arch-color $(@AEDIFIX_PROJECT_ARCH_NAME@)) COLOR_ARCH = $(shell $(CMAKE) -E cmake_echo_color --switch=$(COLOR) --$(SELECTED_COLOR) $(@AEDIFIX_PROJECT_ARCH_NAME@)) export NINJA_STATUS = [%f/%t] $(COLOR_ARCH): $(SOME_UNDEFINED_VARIABLE_TO_ADD_A_SPACE) endif -## Print this help message. -## -.PHONY: help -help: +# ============================ +# A useful default help target +# +.PHONY: aedifix-default-help +aedifix-default-help: @printf "Usage: make [MAKE_OPTIONS] [target] (see 'make --help' for MAKE_OPTIONS)\n" @printf "" @$(AWK) ' \ From 6a1c5f2eeeee7d8dd781266d2e3a466af747ac01 Mon Sep 17 00:00:00 2001 From: Jacob Faibussowitsch Date: Fri, 25 Jul 2025 12:00:30 -0400 Subject: [PATCH 3/4] fixup! Move more default makefile variables to aedifix --- src/aedifix/config.py | 2 +- tests/test_config.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/aedifix/config.py b/src/aedifix/config.py index 80d4d5c..d635e68 100644 --- a/src/aedifix/config.py +++ b/src/aedifix/config.py @@ -54,7 +54,7 @@ def __init__( self._project_variables_file = self.project_arch_dir / config_file.name self._default_subst = { "PYTHON_EXECUTABLE": sys.executable, - "PROJECT_NAME": manager.project_name_upper, + "PROJECT_NAME_UPPER": manager.project_name_upper, "PROJECT_DIR_NAME": manager.project_dir_name, "PROJECT_ARCH_NAME": manager.project_arch_name, } diff --git a/tests/test_config.py b/tests/test_config.py index 9b68b6b..1422fd6 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -35,7 +35,12 @@ def test_create(self, manager: DummyManager, tmp_path: Path) -> None: assert ( config.project_variables_file.name == template.with_suffix("").name ) - assert config._default_subst == {"PYTHON_EXECUTABLE": sys.executable} + assert config._default_subst == { + "PYTHON_EXECUTABLE": sys.executable, + "PROJECT_ARCH_NAME": "AEDIFIX_PYTEST_ARCH", + "PROJECT_DIR_NAME": "AEDIFIX_PYTEST_DIR", + "PROJECT_NAME": "DUMMYMAINMODULE", + } @pytest.mark.parametrize( ("base", "expected"), From 2bd2212d26f02916dab41ce6871cb86267297495 Mon Sep 17 00:00:00 2001 From: Jacob Faibussowitsch Date: Fri, 25 Jul 2025 12:00:45 -0400 Subject: [PATCH 4/4] fixup! Move more default makefile variables to aedifix --- tests/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_config.py b/tests/test_config.py index 1422fd6..366448e 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -39,7 +39,7 @@ def test_create(self, manager: DummyManager, tmp_path: Path) -> None: "PYTHON_EXECUTABLE": sys.executable, "PROJECT_ARCH_NAME": "AEDIFIX_PYTEST_ARCH", "PROJECT_DIR_NAME": "AEDIFIX_PYTEST_DIR", - "PROJECT_NAME": "DUMMYMAINMODULE", + "PROJECT_NAME_UPPER": "DUMMYMAINMODULE", } @pytest.mark.parametrize(