Question

Every time I need to touch a nontrivial makefile it takes time to adjust eyes/brain to the syntax. In attempt to make adaptation smoother I am looking for a good coding style (essentially line breaks and indentation that would increase readability without breaking the code). Has anyone come across a good one?

$$(foreach name,$$(BUILDERS_$$(TARGET_TYPE)_ARGS),$$(if $$(filter undefined,$$(origin TARGET_$$(name))),$$(error [$$(TARGET_NAME)] is missing mandatory argument [$$(name)] for the builder [$$(TARGET_TYPE)])))

Something like the below but working

$$(foreach name,$$(BUILDERS_$$(TARGET_TYPE)_ARGS),
    $$(if $$(filter undefined,$$(origin TARGET_$$(name))),
        $$(error [$$(TARGET_NAME)] is missing mandatory argument [$$(name)] for the builder [$$(TARGET_TYPE)])
    )
)
Was it helpful?

Solution

You can break a function most anywhere you want, but you have to add a backslash before the newline.

The one exception is that whitespace before commas is preserved in some sorts of functions, so be careful when constructing filenames, etc. where adding embedded whitespace might cause issues.

Given your example above, it will work as:

$$(foreach name,$$(BUILDERS_$$(TARGET_TYPE)_ARGS),\
    $$(if $$(filter undefined,$$(origin TARGET_$$(name))),\
        $$(error [$$(TARGET_NAME)] is missing mandatory argument [$$(name)] for the builder [$$(TARGET_TYPE)])\
    )\
)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top