Search code examples
unixmakefilegnu-makebsd

Should the longer synonyms for local variables be used in a Makefile?


In make (I am using OpenBSD’s implementation, but I suppose the question is relevant for GNU make as well), we have the following so called local variables

@    The name of the target
%    The name of the archive member (for library rules)
!    The name of the archive file (for library rules)
?    The list of prerequisites for this target that were deemed out of date
<    The name of the prerequisite from which this target is to be built (for inference rules)
*    The file prefix of the file, containing only the file portion, no suffix or preceding directory components

(roughly from make(1) on OpenBSD)

These local variables have synonyms: for exampe, .IMPSRC for < or .TARGET for @. The manual in FreeBSD says these longer versions are preferred. OpenBSD’s man page mentions no such thing, but says these longer names are an extension.

Is it better to use to longer names? Which is better for compatibility? Are both POSIX?


Solution

  • Those variables are called automatic variables in GNU make and internal variables in the POSIX standard.

    The long names for these are purely BSD make inventions, they do not exist in any other version of make (such as GNU make) and they are not mentioned in the POSIX standard for make.

    It's up to you whether you want to use them, but they are completely non-portable. Of course you could always define them yourself if you wanted to implement a compatibility layer.