* Recursive Makefile howto
@ 2012-01-27 6:13 Manavendra Nath Manav
2012-01-27 9:02 ` Kristof Provost
2012-01-27 15:58 ` Dave Hylands
0 siblings, 2 replies; 7+ messages in thread
From: Manavendra Nath Manav @ 2012-01-27 6:13 UTC (permalink / raw)
To: kernelnewbies
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
^ permalink raw reply [flat|nested] 7+ messages in thread* Recursive Makefile howto 2012-01-27 6:13 Recursive Makefile howto Manavendra Nath Manav @ 2012-01-27 9:02 ` Kristof Provost 2012-01-27 12:08 ` Manavendra Nath Manav 2012-01-28 11:29 ` Bernd Petrovitsch 2012-01-27 15:58 ` Dave Hylands 1 sibling, 2 replies; 7+ messages in thread From: Kristof Provost @ 2012-01-27 9:02 UTC (permalink / raw) To: kernelnewbies 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Recursive Makefile howto 2012-01-27 9:02 ` Kristof Provost @ 2012-01-27 12:08 ` Manavendra Nath Manav 2012-01-27 12:37 ` Kristof Provost 2012-01-28 11:29 ` Bernd Petrovitsch 1 sibling, 1 reply; 7+ messages in thread From: Manavendra Nath Manav @ 2012-01-27 12:08 UTC (permalink / raw) To: kernelnewbies 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Recursive Makefile howto 2012-01-27 12:08 ` Manavendra Nath Manav @ 2012-01-27 12:37 ` Kristof Provost 0 siblings, 0 replies; 7+ messages in thread From: Kristof Provost @ 2012-01-27 12:37 UTC (permalink / raw) To: kernelnewbies 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Recursive Makefile howto 2012-01-27 9:02 ` Kristof Provost 2012-01-27 12:08 ` Manavendra Nath Manav @ 2012-01-28 11:29 ` Bernd Petrovitsch 1 sibling, 0 replies; 7+ messages in thread From: Bernd Petrovitsch @ 2012-01-28 11:29 UTC (permalink / raw) To: kernelnewbies 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 at petrovitsch.priv.at LUGA : http://www.luga.at ^ permalink raw reply [flat|nested] 7+ messages in thread
* Recursive Makefile howto 2012-01-27 6:13 Recursive Makefile howto Manavendra Nath Manav 2012-01-27 9:02 ` Kristof Provost @ 2012-01-27 15:58 ` Dave Hylands 2012-01-28 9:44 ` Manavendra Nath Manav 1 sibling, 1 reply; 7+ messages in thread From: Dave Hylands @ 2012-01-27 15:58 UTC (permalink / raw) To: kernelnewbies 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Recursive Makefile howto 2012-01-27 15:58 ` Dave Hylands @ 2012-01-28 9:44 ` Manavendra Nath Manav 0 siblings, 0 replies; 7+ messages in thread From: Manavendra Nath Manav @ 2012-01-28 9:44 UTC (permalink / raw) To: kernelnewbies 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-01-28 11:29 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-01-27 6:13 Recursive Makefile howto Manavendra Nath Manav 2012-01-27 9:02 ` Kristof Provost 2012-01-27 12:08 ` Manavendra Nath Manav 2012-01-27 12:37 ` Kristof Provost 2012-01-28 11:29 ` Bernd Petrovitsch 2012-01-27 15:58 ` Dave Hylands 2012-01-28 9:44 ` Manavendra Nath Manav
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.