Makefile problems

OP #1227000
Hi all,

I am trying to build a number of related projects for the LPC2366 & 
LPC2478. They share a common core of code and I want to generate all the 
hex files when this changes. My thought was to have each individual 
project in its own sub-directory of a main project with a master 
makefile which recursively built the sub-projects. The problem is that 
the make target is being ignored. Sorry if this is off topic, but it is 
driving me mad!

My main makefile is:
SUBDIRS = subdirs/*

all clean:
  target="$(patsubst %,%,$@)"; \
  list='$(SUBDIRS)'; for subdir in $$list; do \
    echo "Making $$target in $$subdir"; \
    (cd $$subdir && $(MAKE) $$target) \
  done; \


# Listing of phony targets.
.PHONY : all clean

The problem is when the command $(MAKE) $$target is run the target is 
ignored and the default target is executed.
To test and show the problem I am using 3 subdirs dir1, dir2 & dir3 with 
the following makefile:

all clean:
  make_target="$(patsubst %,%,$@)"; \
  echo "Making $$target";

When I run make clean I get:

target="clean"; \
list='subdirs/*'; for subdir in $list; do \
  echo "Making $target in $subdir"; \
  (cd $subdir && make  $target) \
done; \

Making clean in subdirs/dir1
C:\WinARM\utils\bin\make.exe[1]: Entering directory `c:/Documents and 
Settings/Craig/workspace/Test/subdirs/dir1'
make_target="all"; \
echo "Making $target";
Making
C:\WinARM\utils\bin\make.exe[1]: Leaving directory `c:/Documents and 
Settings/Craig/workspace/Test/subdirs/dir1'
Making clean in subdirs/dir2
C:\WinARM\utils\bin\make.exe[1]: Entering directory `c:/Documents and 
Settings/Craig/workspace/Test/subdirs/dir2'
make_target="all"; \
echo "Making $target";
Making
C:\WinARM\utils\bin\make.exe[1]: Leaving directory `c:/Documents and 
Settings/Craig/workspace/Test/subdirs/dir2'
Making clean in subdirs/dir3
C:\WinARM\utils\bin\make.exe[1]: Entering directory `c:/Documents and 
Settings/Craig/workspace/Test/subdirs/dir3'
make_target="all"; \
echo "Making $target";
Making
C:\WinARM\utils\bin\make.exe[1]: Leaving directory `c:/Documents and 
Settings/Craig/workspace/Test/subdirs/dir3'

Any help would be greatly appreciated.
Guest
$(MAKECMDGOALS):
  list='$(SUBDIRS)'; for subdir in $$list; do \
    echo "Making $(MAKECMDGOALS) in $$subdir"; \
    $(MAKE) -C $$subdir $(MAKECMDGOALS) \
  done; \

Reply

A question of your own? This thread is over 17 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.