Take the 2-minute tour ×

I have a makefile with a target clean:

   $(MAKE) -f <other makefile location> clean

When I call make clean in this makefile, it tells me that in the other makefile there is no rule 'clean-linux'. Specifically here is the output.

make -f /root/ovaldi-5.5.25-src/project/linux/Makefile clean
make[1]: Entering directory '/root/ovaldi-5.5.25-src'
make[2]: Entering directory '/root/ovaldi-5.5.25-src'
make[2]: *** No rule to make target 'clean-linux'. Stop.
make[2]: Leaving directory '/root/ovaldi-5.5.25-src'
make[1]: Leaving directory '/root/ovaldi-5.5.25-src'

Why is it giving it the clean-linux target and not just clean like I specified?

share|improve this question
clean : @if [ $(PLATFORM) = LINUX ]; then \ make clean-linux; \ fi; \ if [ $(PLATFORM) = SUNOS ]; then \ make clean-sunos; \ fi; clean-linux: -rm -rf $(OUTDIR) clean-sunos: -rm -rf $(OUTDIR) It does call clean-linux but that is already specified. –  Matt Aug 18 '09 at 13:56
add comment

2 Answers

When you make (or $(MAKE)), by default you use whatever makefile is there. So here's what I think is happening.

  1. You cd to some location.
  2. You 'make -f Makefile_A clean'.
  3. make runs with Makefile_A, and does '$(MAKE) -f Makefile_B clean'.
  4. make[1] runs with Makefile_B, and does '$(MAKE) clean-linux'.
  5. make[2] runs with whatever makefile is here which might be anything (I suspect it's Makefile_A) but whatever it is it has no rule for clean-linux.

The solution: rewrite your second makefile (the one that has clean-linux) so that clean-linux becomes a prerequisite of clean (if/when you're on a linux system). That way it won't run make[2].

clean: clean-linux

clean: clean-sunos

share|improve this answer
that syntax gives me "missing separator" on the 1st ifeq line –  gcb Mar 20 '12 at 19:56
@gcb, so try some basic troubleshooting. Can you get any ifeq statement to work? If the problem persists, post it as a question with your full makefile and details like which version of Make you're using. –  Beta Mar 20 '12 at 20:18
add comment

Just a guess but maybe the 'clean' target in the second makefile calls 'clean-linux'?

Can you post the clean target of the second makefile?


In light of your posted clean target it seems you're just calling the clean-linux target incorrectly.

Beta has posted the correct way of dealing with your problem in their answer so I'm going to +1 that.

share|improve this answer
It does call it but it is specified. It seems as if target dependencies and calls to make in the second makefile call make on the first makefile. –  Matt Aug 18 '09 at 14:00
add comment

Your Answer


