[lug] How do you setup a recursive make?
Brad Doctor
bdoctor at ps-ax.com
Mon Jul 23 18:25:39 MDT 2001
It is done within Make, but with some shell calls. I've included the full
example, with it's expected output. Also, should you add a sub component
to your tree, you can use the same method as used here, so it will also
recurse.
For this, you need sed as a system utility (Uwin, Cygwin, etc.) and
possibly echo -- not sure how it will behave on windows. Of course, you
need 'test', or have it as a builtin for your shell. Now that I think
about it, this is pretty Unixish, however it should be adaptable.
SUBDIRS = lib server client docs
METHODS = all clean
default-recursive:
@set fnord $(MAKEFLAGS); amf=$$2; \
dot_seen=no; \
target=`echo $@ | sed s/-recursive//`; \
list='$(SUBDIRS)'; for subdir in $$list; do \
echo "Making $$target in $$subdir"; \
if test "$$subdir" = "."; then \
dot_seen=yes; \
local_target="$$target-am"; \
else \
local_target="$$target"; \
fi; \
(cd $$subdir && $(MAKE) $(LOC_MAKEFLAGS) $$local_target) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;;
esac; \
done; \
test:
@set fnord $(MAKEFILAGS); \
mylist='$(METHODS)'; for method in $$mylist; do \
echo "Making $$method"; \
touch $$method; \
done;
---------
make
---------
Making default in lib
make[1]: Entering directory `/export/home/bdoctor/t/lib'
make[1]: `default' is up to date.
make[1]: Leaving directory `/export/home/bdoctor/t/lib'
Making default in server
make[1]: Entering directory `/export/home/bdoctor/t/server'
make[1]: `default' is up to date.
make[1]: Leaving directory `/export/home/bdoctor/t/server'
Making default in client
make[1]: Entering directory `/export/home/bdoctor/t/client'
make[1]: `default' is up to date.
make[1]: Leaving directory `/export/home/bdoctor/t/client'
Making default in docs
make[1]: Entering directory `/export/home/bdoctor/t/docs'
make[1]: Nothing to be done for `default'.
make[1]: Leaving directory `/export/home/bdoctor/t/docs'
---------
make test
---------
Making all
Making clean
---------
-brad
At 04:29 PM 7/23/2001 -0600, Holshouser, David wrote:
>is make sending this scripting to the shell or is it handled within make?
>is this sh syntax specific?
>where do I look for info on for loops?
>
>FYI, using gcc make from Tornado2 on an NT box, so if this is passed through
>to the shell, I'm in trouble.
More information about the LUG
mailing list