Recursive Makefile Stop On Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta makefile recipe for target failed Discuss the workings and policies of this site About Us Learn more
Makefile Error 1
about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack make error codes Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping
Makefile Exit On Error
each other. Join them; it only takes a minute: Sign up Make failure in subdirectory make not stopping build up vote 6 down vote favorite 1 I have a setup where make is going through a bunch of subdirectories and making inside those directories. I would like it to stop the build on a failure immediately. The makefile error 2 code snippet below illustrates this. Can someone point me in the right direction on how the makefile should be set up or some documentation about building from a top level down through subdirectories? SUBDIRS = \ test1 \ test2 all clean check : @for dir in $(SUBDIRS); do \ if [ -d $$dir ]; then (cd $$dir; $(MAKE) $@) fi \ done makefile gnu-make multiple-makefiles share|improve this question asked Mar 17 '10 at 15:07 Stephen Burke 423619 1 The solution is given in info make: gnu.org/software/make/manual/make.html#Phony-Targets –dma_k Jun 22 '10 at 18:18 add a comment| 2 Answers 2 active oldest votes up vote 7 down vote accepted I am in the (apparent) minority that disagrees with "Recursive Make Considered Harmful". I've written recursive Make systems for large, messy code bases, and they work quite nicely. Here's how to do it: all: $(SUBDIRS) $(SUBDIRS): force @ $(MAKE) -s -C $@ .PHONY: force force :; (I've added the -s to make things quieter.) EDIT: To pass a target down to the submak
in the recipe is executed in a new shell; after the last line is finished, the rule is finished. If there is an
Gnu Make Error 2
error (the exit status is nonzero), make gives up on the
Recipe Commences Before First Target
current rule, and perhaps on all rules. Sometimes the failure of a certain recipe line does not indicate commands commence before first target a problem. For example, you may use the mkdir command to ensure that a directory exists. If the directory already exists, mkdir will report an error, but you probably http://stackoverflow.com/questions/2463356/make-failure-in-subdirectory-make-not-stopping-build want make to continue regardless. To ignore errors in a recipe line, write a ‘-’ at the beginning of the line’s text (after the initial tab). The ‘-’ is discarded before the line is passed to the shell for execution. For example, clean: -rm -f *.o This causes make to continue even if rm is unable to remove https://www.gnu.org/s/make/manual/html_node/Errors.html a file. When you run make with the ‘-i’ or ‘--ignore-errors’ flag, errors are ignored in all recipes of all rules. A rule in the makefile for the special target .IGNORE has the same effect, if there are no prerequisites. These ways of ignoring errors are obsolete because ‘-’ is more flexible. When errors are to be ignored, because of either a ‘-’ or the ‘-i’ flag, make treats an error return just like success, except that it prints out a message that tells you the status code the shell exited with, and says that the error has been ignored. When an error happens that make has not been told to ignore, it implies that the current target cannot be correctly remade, and neither can any other that depends on it either directly or indirectly. No further recipes will be executed for these targets, since their preconditions have not been achieved. Normally make gives up immediately in this circumstance, returning a nonzero status. However, if the ‘-k’ or ‘--keep-going’ flag is specifi
runs the make in all the subdirectories, potentially with dependencies so that things are built in the correct order. This should work for "make", "make http://lackof.org/taggart/hacking/make-example/ install", "make clean", etc. The make manual has a good description of this (in the "Phony targets" section of all places. It says Another example of the usefulness of phony targets http://www.opussoftware.com/manual/appendices/B1.htm is in conjunction with recursive invocations of make (for more information, see Recursive Use of make). In this case the makefile will often contain a variable which lists a number of on error subdirectories to be built. One way to handle this is with one rule whose command is a shell loop over the subdirectories, like this: SUBDIRS = foo bar baz subdirs: for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir; \ done There are a few problems with this method, however. First, any error detected in a submake is not noted by this before first target rule, so it will continue to build the rest of the directories even when one fails. This can be overcome by adding shell commands to note the error and exit, but then it will do so even if make is invoked with the -k option, which is unfortunate. Second, and perhaps more importantly, you cannot take advantage of make's ability to build targets in parallel (see Parallel Execution), since there is only one rule. By declaring the subdirectories as phony targets (you must do this as the subdirectory obviously always exists; otherwise it won't be built) you can remove these problems: SUBDIRS = foo bar baz .PHONY: subdirs $(SUBDIRS) subdirs: $(SUBDIRS) $(SUBDIRS): $(MAKE) -C $@ foo: baz Here we've also declared that the foo subdirectory cannot be built until after the baz subdirectory is complete; this kind of relationship declaration is particularly important when attempting parallel builds. The point about not using loops and instead making the subdirs themselves targets seems like a good idea and works for our "make" case. Well what about "make install"? We're already using the subdir names as ta
if you are doing a recursive make, by Make itself. The exit status can also be accessed in the .AFTER special target with the MAKESTATUS macro. For example: .AFTER : %if $(MAKESTATUS) == 3 %echo Make: The final shell line exited with status: $(status) %endif The exit values and their meanings are: Exit status Meaning 0 Normal exit with no errors. 1 General purpose error if no other explicit error is known. 2 There was an error in the makefile. 3 A shell line had a non-zero status. 4 Make ran out of memory. 5 The program specified on the shell line was not executable. 6 The shell line was longer than the command processor allowed. 7 The program specified on the shell line could not be found. 8 There was not enough memory to execute the shell line. 9 The shell line produced a device error. 10 The program specified on the shell line became resident. 11 The shell line produced an unknown error. 15 There was a problem with the memory miser. 16 The user hit CTRL+C or CTRL+BREAK.. Home ProductInfo Orders Downloads AboutUs ContactUs Opus Software, Inc. 1032 Irving Street, Suite 439 San Francisco, CA 94122 USA Phone: 415-485-9703 Fax: 415-485-9704 Email:biz@opussoftware.com