Appendix B. The Outer Limits
As you’ve seen, GNU
make can do some pretty incredible things, but I haven’t
seen very much that really pushes the limits of make 3.80
with its eval construct. In this exercise, we’ll see if
we can stretch it further than usual.
Data Structures
One of the limitations of make
that occasionally chaffs when writing complex makefiles is make’s lack of data
structures. In a very limited way, you can simulate a data structure by defining
variables with embedded periods (or even -> if you can stand it):
file.path = /foo/bar file.type = unix file.host = oscar
If pressed, you can even “pass” this file structure
to a function by using computed variables:
define remote-file
$(if $(filter unix,$($1.type)), \
/net/$($1.host)/$($1.path), \
//$($1.host)/$($1.path))
endefNevertheless, this seems an unsatisfying solution for several reasons:
You cannot easily allocate a instance of this “structure.” Creating a new instance involves selecting a new variable name and assigning each element. This also means these pseudo-instances are not guaranteed to have the same fields (called slots).
The structure exists only in the user’s mind, and as a set of different make variables, rather than as a unified entity with its own name. And because the structure has no name, it is difficult to create a reference (or pointer) to a structure, so passing them as arguments or storing one in a variable is clumsy.
There is no safe way to access a slot of the structure. Any typographical error in ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access