What's new in GNU Make 3.81

[article]

Make tradition that the target is called all or something similar. It's possible to override this behaviour by setting the .DEFAULT_GOAL variable anywhere in a Makefile. For example, the following Makefile will build all when run, with no goal on the command-line, despite the fact that the first target encountered is called fail: .DEFAULT_GOAL can also be read to determine the current default goal, and if set to blank (.DEFAULT_GOAL :=) GNU Make will automatically pick up the next target it encounters as the default goal.

MAKE_RESTARTS: this is the count of the number of times that GNU Make has restarting while performing Makefile remaking. If GNU Make has not restarted then MAKE_RESTARTS is blank and not 0.

New functions

$(info text...) : $(info) is like the existing $(warning text...) function, but it prints the expanded text... argument to stdout without reporting the Makefile and line number. For example, the following Makefile generates the output Hello, World!:

$(info Hello, World!) all: ; @true

$(lastword LIST) : returns the last word of a GNU Make list. Previously this was possible using existing GNU Make functions by writing $(word $(words LIST),LIST); but $(lastword) is more efficient. If you are using the GNU Make Standard Library there's an function called last which is the same as $(lastword). If you are using GNU Make 3.81 and GMSL 1.0.6 or above last automatically uses the built-in $(lastword) for speed.

$(flavor VAR) : returns the flavor of a variable (either recursive for recursively expanded or simple for simply expanded). For example, the following Makefile prints that REC is recursive and SIM is simple:

REC = foo SIM := foo $(info REC is $(flavor REC)) $(info SIM is $(flavor SIM)) all: ; @true

$(or ...) and $(and ...) : $(or ...) returns a non-blank string if any of its arguments is non-blank (you'll recall that GNU Make's $(if) treats a non-blank string is true and a blank string as false). $(and ...) returns a non-blank string if and only if all its arguments are non-blank. If you are using the GNU Make Standard Library there are and and or functions as part of the library. If you are using GNU Make 3.81 and GMSL 1.0.6 or above then the new built-in functions are not overriden with the GMSL versions for speed and compatibility. This means that Makefiles that use GMSL are fully backwards and forwards-compatible with GNU Make 3.81.

$(abspath ...) and $(realpath ...) : $(abspath ...) returns the absolute path relative to the directory that GNU Make was started in (and taking into account any -C command-line options). The path has all . and .. elements resolved and duplicate /'s removed. For example the following Makefile (at least on my machine) prints /home/jgc/bar when it's placed in /home/jgc:

$(info $(abspath foo/./..//////bar)) all: ; @true

Note that GNU Make does not check that the path exists, it just resolves the path elements to make an absolute path. $(realpath) returns the same result as $(abspath) except that any symbolic links are resolved. For example, if bar is symlinked to over-here then the following Makefile would return /home/jgc/over-here if read from /home/jgc:

$(info $(realpath ../jgc/./bar)) all: ; @true 

About the author

John Graham-Cumming's picture John Graham-Cumming

John Graham-Cumming is Co-Founder at Electric Cloud, Inc . Prior to joining Electric Cloud, John was a Venture Consultant with Accel Partners, VP of Internet Technology at Interwoven, Inc. (IWOV), VP of Engineering at Scriptics Corporation (acquired by Interwoven), and Chief Architect at Optimal Networks, Inc. John holds BA and MA degrees in Mathematics and Computation and a Doctorate in Computer Security from Oxford University. John is the creator of the highly acclaimed open source POPFile project. He also holds two patents in network analysis and has others pending.

AgileConnection is one of the growing communities of the TechWell network.

Featuring fresh, insightful stories, TechWell.com is the place to go for what is happening in software development and delivery.  Join the conversation now!

Upcoming Events

May 04
May 04
May 04
Jun 01