https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120103
Bug ID: 120103 Summary: Generation of Make Dependencies for C++ Modules Product: gcc Version: 15.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: preprocessor Assignee: unassigned at gcc dot gnu.org Reporter: joergboe at snafu dot de Target Milestone: --- When using the options -M, -MM, -MD.. the compiler outputs a rule suitable for make describing the dependencies of the main source file. Problem #1: Importing units object files shall depend on CMI-files of imported modules. ----------- Currently (gcc 15.1.1) generates a PHONY target for each module interface unit in the form: <module name>.c++-module: <module cmi file> .PHONY: <module name>.c++-module And every importing unit depends on this PHONY target of the module interface unit like: <importing unit>.o: <module name>.c++-module This leads to the importing source file being recompiled with every call to Make, even if neither the source nor the module interface unit has been changed. The GNU-Make manual https://www.gnu.org/software/make/manual/make.html#Phony-Targets says: 'A phony target should not be a prerequisite of a real target file; if it is, its recipe will be run every time make considers that file.' Solution: 1. For Module Interface Units gcc shall emit a variable in the form: CXX_MOD_CMI_<module name> = <cmi file> which contains the CMI-file name. 2. For each importing unit a rule should be generated like: <importing unit> : $$(CXX_MOD_CMI_<modul name>) 3. The Makefile section which imports the dependencies should enable Secondary-Expansion (.SECONDEXPANSION:) This way, make recognizes the importing unit object file depends on the CMI-files of imported modules without a path through PHONY targets. Problem #2: CMI-files shall depend on the Module interface unit. ----------- Currently gcc generates a for each Module Interface Unit an Order Only Prerequisite for the CMI-file like: <module cmi file>:| <module interface unit>.o But this rule does not trigger a re-build of importing unit object files, which is wrong. Solution: 1. For Module Interface Units gcc shall emit a variable in the form: CXX_SRC_CMI_<source file name> = <cmi file> which contains the CMI-file name. 2. This variable should be referenced in a production rule with 2 Grouped Targets for the Module Interface Unit like: <unit object file> <module cmi file> &: <unit source file> <unit dep file> ... Problem #3: Housekeeping ----------- The compiler should emit some more list variables (like CXX_IMPORTS): CXX_CMI_FILES += <cmi file> to avoid deletion of system header CMI files in cache direcy. CXX_MODULE_INTERFACE_UNITS += <interface unit source> to distinguish Module Interface units from other compilation units