Skip to content

2025#

GNU Make: double-expand

A few days ago I stumbled upon this article late in the evening and it kept me awake the whole night! It describes a cool trick that allows to "double-expand" a macro without using eval. The following is a summary of the main idea, a reflection of why it works and a small extension.

GNU Make: double-colon rules

Consider an integration testing setup where the command to test appears on the first line of a text file, followed by the expected output. I used to run all tests using:

TESTS := test-html test-latex test-semicolon ...

.PHONY: $(TESTS)
$(TESTS): COMMAND = $(shell head -n 1 $(TEST_DIR/$@))
$(TESTS): EXPECTED = ... $(TEST_DIR/$@)
$(TESTS): RESULT = ...
$(TESTS):
    compare $(EXPECTED) with $(RESULT)

but the other day I had the following problem: one of the tests required additional post-processing.