Hi All, I have developed a Makefile which recursively builds the code spread across multiple directories, each having it's own Makefile. build_all: targetA \ targetB \ target C Now, the problem is that even when the Makefile of targetA fails, the master Makefile continues building with targetB and targetC. I can also see the make errors being printed on console. I want the make to stop immediately at the first error encountered in any target Makefile. How to do this? -- Manavendra Nath Manav
On 2012-01-27 11:43:10 (+0530), Manavendra Nath Manav <mnm.kernel@gmail.com> wrote:
I have developed a Makefile which recursively builds the code spread across multiple directories, each having it's own Makefile.
build_all: targetA \ targetB \ target C
Now, the problem is that even when the Makefile of targetA fails, the master Makefile continues building with targetB and targetC. I can also see the make errors being printed on console. I want the make to stop immediately at the first error encountered in any target Makefile. How to do this?
It would be a lot easier to help you if you'd post the relevant bits of your Makefile. Dusting off my crystal ball, I see in the mists that your makefile looks something like this: build: for d in $(DIRS) ; \ do \ $(MAKE) -C $$d $@ ; \ done The problem here is that make considers the whole for loop as one and doesn't get the exit status of each sub-make, but only of the last one. Try something like this instead: build: for d in $(DIRS) ; \ do \ $(MAKE) -C $$d $@ || exit $? ; \ done Regards, Kristof
On Fri, Jan 27, 2012 at 2:32 PM, Kristof Provost <kristof@sigsegv.be> wrote:
On 2012-01-27 11:43:10 (+0530), Manavendra Nath Manav <mnm.kernel@gmail.com> wrote:
I have developed a Makefile which recursively builds the code spread across multiple directories, each having it's own Makefile.
build_all: targetA \ targetB \ target C
Now, the problem is that even when the Makefile of targetA fails, the master Makefile continues building with targetB and targetC. I can also see the make errors being printed on console. I want the make to stop immediately at the first error encountered in any target Makefile. How to do this?
It would be a lot easier to help you if you'd post the relevant bits of your Makefile.
Dusting off my crystal ball, I see in the mists that your makefile looks something like this:
build: for d in $(DIRS) ; \ do \ $(MAKE) -C $$d $@ ; \ done
The problem here is that make considers the whole for loop as one and doesn't get the exit status of each sub-make, but only of the last one.
Try something like this instead:
build: for d in $(DIRS) ; \ do \ $(MAKE) -C $$d $@ || exit $? ; \ done
Regards, Kristof
Hi Kristof, Your crystal ball insight was fairly accurate. The syntax "$(MAKE) -C $$d $@ || exit $? ;" is both new and helpful to me. For more clarity, the format of my Makefile is like this: my_exec: Build_sqllib \ Create_obj_dir \ objs/server/foo.o \ objs/server/bar.c $(LINK) -o my_exec \ objs/server/foo.o \ objs/server/bar.c Build_sqllib: cd src/sqllib; \ rm -rf LIBS/*; \ make; \ rm -f $(CURDIR)/sqllib.a; \ cp -fv LIBS/sqllib.a $(CURDIR)/lib/sqllib.a;\ cd $(CURDIR); Create_obj_dir: mkdir -p objs/server \ objs/html \ objs/log \ objs/cipher \ objs/curse \ objs/crypto \ objs/protocol objs/server/foo.o: \ src/server/foo.c $(LINK) -c \ -o objs/server/foo.o \ src/server/foo.c Now, I am getting error in the make part of "Build_sqllib" but the makefile continues to next line. I guess, I need to add "|| exit" also with this make command. Kristof, can you pls also explain me the meanings of $$d, $@, and $? as used in Makefiles. -- Manavendra Nath Manav
On 2012-01-27 17:38:11 (+0530), Manavendra Nath Manav <mnm.kernel@gmail.com> wrote:
Now, I am getting error in the make part of "Build_sqllib" but the makefile continues to next line. I guess, I need to add "|| exit" also with this make command. Kristof, can you pls also explain me the meanings of $$d, $@, and $? as used in Makefiles.
$$d is not a make variable, but a shell variable. The double '$' is an escape sequence. In fact, $? should be $$?, because we want the shell to interpret it. I suspect it gets replaced by an empty string, and in that case exit returns the exit status from the previous command. We can just remove $$? in other words. $@ is a make variable, an automatic variable. It always contains the file name of the target. Regards, Kristof
On Fre, 2012-01-27 at 10:02 +0100, Kristof Provost wrote: [...]
Try something like this instead:
build: for d in $(DIRS) ; \ do \ $(MAKE) -C $$d $@ || exit $? ; \ done
Or build: set -e; for d in $(DIRS); \ do \ $(MAKE) -C $$d $@; \ done Read bash' manual page for what "set -e" does. Bernd -- Bernd Petrovitsch Email : bernd@petrovitsch.priv.at LUGA : http://www.luga.at
Hi Manavendra, On Thu, Jan 26, 2012 at 10:13 PM, Manavendra Nath Manav <mnm.kernel@gmail.com> wrote:
Hi All,
I have developed a Makefile which recursively builds the code spread across multiple directories, each having it's own Makefile.
You may want to reconsider your approach: http://aegis.sourceforge.net/auug97.pdf http://evbergen.home.xs4all.nl/nonrecursive-make.html -- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com
On Fri, Jan 27, 2012 at 9:28 PM, Dave Hylands <dhylands@gmail.com> wrote:
Hi Manavendra,
On Thu, Jan 26, 2012 at 10:13 PM, Manavendra Nath Manav <mnm.kernel@gmail.com> wrote:
Hi All,
I have developed a Makefile which recursively builds the code spread across multiple directories, each having it's own Makefile.
You may want to reconsider your approach: http://aegis.sourceforge.net/auug97.pdf http://evbergen.home.xs4all.nl/nonrecursive-make.html
-- Dave Hylands Shuswap, BC, Canada http://www.davehylands.com
Thanks Dave, I went through both the links provided by you and the make process is pretty much clear to me now. The following two points I would want elaborate from the paper: 1. As a rule of thumb: always use immediate evaluation assignment unless you knowingly want deferred evaluation. 2. You will get more accurate builds of your project if you use whole-project make rather than recursive make. -- Manavendra Nath Manav
participants (4)
-
Bernd Petrovitsch -
Dave Hylands -
Kristof Provost -
Manavendra Nath Manav