Matt
Matt

Reputation: 1901

Makefile calling other makefile with target, gives wrong target

I have a makefile with a target clean:

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?

Upvotes: 1

Views: 8895

Answers (2)

Glen
Glen

Reputation: 22310

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?

Edit:

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.

Upvotes: 2

Beta
Beta

Reputation: 99164

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].

ifeq ($(PLATFORM), LINUX)
clean: clean-linux
endif

ifeq ($(PLATFORM), SUNOS)
clean: clean-sunos
endif

clean:;

Upvotes: 2

Related Questions