Improve the rerun logic for the config target

Merged
DR
5d ago
+182-61

Running make previously always triggered the config and the bootstrap targets to execute because the value of TRANSLATION_DEFS differed on every run, causing the auto-generated config file to be updated and the bootstrap target to run through an indirect dependency.

The proposed changes primarily rewrite the Makefile logic to enable the build system to check the configuration switches (ARCH/DYNLINK/BINDING) and to determine whether a reconfiguration or a rebuild should be performed.

Now, the aforementioned variables are stored in the build session file (BINDING is stored only when dynamic linking is enabled) after the config target is triggered. For the next make run, the build system will verify whether any of these variables has changed and whether the rerun requirements are met.


Test cases:

# Case 1: the first build is performed directly.
$ make
Configurations: (arm, static linking)
...
Warning: discarding const qualifier in cast

# Case 2: directly running "make" again -> No action.
$ make
Keep configurations

# Case 3: Switch from static linking to dynamic linking.
$ make DYNLINK=1
Configurations: (arm, dynamic linking, lazy binding)
  CC    out/src/main.o
...

# Case 4: Switch from lazy binding to immediate binding.
$ make BINDING=now
Configurations: (arm, dynamic linking, immediate binding)
...

# Case 5: Switch from arm to x64 (an architecture switch).
#         Note that dynamic linking and immediate binding are kept.
$ make ARCH=x64
Configurations: (x64, dynamic linking, immediate binding)
...

Summary by cubic

Rerunning make no longer always reconfigures and rebuilds the bootstrap target. The build system now records ARCH, DYNLINK, and BINDING in a build session file and only reconfigures when one of these switches, printing Keep configurations otherwise. Passing BINDING with static linking now aborts the build instead of silently ignoring it.

  • Reworks the Makefile conditionals so the config target writes the generated config file and session file only when NEED_RECONFIGURE is set.
  • Defaults BINDING to undefined and sets it to lazy only when DYNLINK=1.
  • Updates the README with the new configuration switch behavior and error cases.