help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with implicit rule used in various directory compiling


From: Günter Neiß
Subject: Re: Help with implicit rule used in various directory compiling
Date: Wed, 14 Feb 2001 08:14:40 +0100

Nick Ng schrieb:
> 
> Hi there:
> 
> I have some simple questions on how to use GNU make to browse through
> various sub-directory to compile using one and only one implicit rule.
> I have a directory tree in my development env. like:
>         src -
>                 prg1
>                 prg2
>                 prg3
> 
> Where all of source file (C) are stored in 3 different sub-dirs. If I
> defined the implicit rule like:
> 
> %.o : %.c
>         $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
> 
> Can anyone please tell me how to ask make to browse through each of these
> sub-dirs and apply the implicit rule on it. I understood a PHONY target can
> be a good starting point to kick off multiple target build. Any help is
> appreciated :) :) !
> 
> _______________________________________________
> Help-make mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/help-make

Hi,
 take a look at the attached Makefiles, they Do what You want ;-)

How to use them:
 - Copy the files into your 'src' dir
 - Rename file 'SubdirMake.template' to 'Makefile'
   (if You don't change the include-directive at the very end of that
file your 
    (base)directory SHOULD be named 'src' )
 - complete the line containing 'SubPrjs:=' 
   You may either implicit define the dir's to process or use something
like
   $(shell find .... )

 - if You 'cd' to the 'src'-dir and call 'make' 
   it will recursively go into each defined subdir, processing any
Makefile 
   found there

 - if You realy wan't only the above rule executed in every subdir,
   You may change the line containig '$(MAKE)' (in SubdirMake).
   change  if from 
   @$(MAKE) -s -C $@ PrjStr=$(PrjStr)/$@ $(MakeTargets)
   to
   @$(MAKE) -f ../YourMakefile -s -C $@ PrjStr=$(PrjStr)/$@
$(MakeTargets)
   or to
   @$(MAKE) -f $(firstword $(subst /src/,/src ,$(CURDIR)/))/YourMakefile
-s -C $@ PrjStr=$(PrjStr)/$@ $(MakeTargets)

   Both assume a file 'YourMakefile' residing in the 'src'-dir that
simply 
   defines the rules that shall be applyed.

I hope that solves Your question, if not, don't heastiate to call again.

 greetings
   Guenter Neiss
   Schoenhofer Sales and Engeniering GmbH (SSE)
   address@hidden
###############################################################################
# SubdirMake
#
# This Makefile processes all Makefiles in the SubDirectories defined by:
# 'SubPrjs'
# the special target 'force' may be used to force all makes even if one fails
###############################################################################

###############################################################################
# Check Variables that SHALL be defined before including 'SubdirMake'
###############################################################################

Error:=         $(if $(SubPrjs),,$(error SubdirMake: Variable SubPrjs not 
specified))

###############################################################################
# Check Variables that MAY be defined before including 'SubdirMake'
###############################################################################

###############################################################################
# Make all projects / subdirs
###############################################################################

Goal:=          DoSubPrjs$(subst force,Force,$(filter force,$(MAKECMDGOALS)))

MakeTargets:=   $(filter-out force,$(MAKECMDGOALS))
MakeTargets:=   $(if $(MakeTargets),$(MakeTargets),all)

$(MakeTargets): $(Goal)

.PHONY:         force Show DoSubPrjs DoSubPrjsForce $(SubPrjs)

force:          $(MakeTargets)

Show:
                @echo SubdirMake: SubPrjs: $(SubPrjs)
                @echo SubdirMake: Goal: $(Goal)
                @echo SubdirMake: MakeTargets: $(MakeTargets)

DoSubPrjs:      $(SubPrjs)

DoSubPrjsForce:
                @for dir in $(SubPrjs); do \
                  echo SubdirMake : $(PrjStr)/$$dir ; \
                  $(MAKE) -s -C $$dir PrjStr=$(PrjStr)/$$dir $(MakeTargets) ; \
                done

$(SubPrjs):
                @echo SubdirMake : $(PrjStr)/$@
                @$(MAKE) -s -C $@ PrjStr=$(PrjStr)/$@ $(MakeTargets)

###############################################################################
# Variables that SHALL be defined before including 'SubdirMake'
###############################################################################

SubPrjs:=

# Text that indicates the Basic Prj that was made
ifdef PrjStr
  PrjStr+=      /PrjName
 else
  PrjStr=       PrjName
endif

###############################################################################
# Variables that MAY be defined before including 'SubdirMake'
###############################################################################

###############################################################################
# And now include the Basic-Part
###############################################################################

Error:=         $(if $(findstring /src/,$(CURDIR))/,,$(error Current Dir does 
not contain '/src/'))
include         $(firstword $(subst /src/,/src ,$(CURDIR)/))/SubdirMake

###############################################################################
# Additional Dependencies / Rules
###############################################################################



reply via email to

[Prev in Thread] Current Thread [Next in Thread]