Reputation: 3601
I have part of a GNU-make makefile (gcc v4.1.2) that is not working as I would expected. I have a four libraries in sub diretiories that I want to recursively build if make
is ran in the base /build directory
/prj
|--/build
| |--makefile
| |--/Tables.lib
| | |--makefile
| |--/General.lib
| | |--makefile (etc..)
|--/lib
|--/src
Brief code for /prj/build/makefile:
LIB_DIR = /prj/lib
LIBRARY := libcomposition_adjustment.a libtables.a libgeneral.a libbiblio.a
DIRS := Tables.lib Composition_adjustment.lib General.lib Biblio.lib
all: $(LIBRARY)
#all: $(LIB_DIR)/libcomposition_adjustment.a # this line works
%.a : $(LIB_DIR)/%.a
$(LIB_DIR)/libtables.a:
cd Tables.lib; $(MAKE)
$(LIB_DIR)/libcomposition_adjustment.a:
cd Composition_adjustment.lib; $(MAKE)
$(LIB_DIR)/libgeneral.a:
cd General.lib; $(MAKE)
$(LIB_DIR)/libbiblio.a: libgeneral.a
cd Biblio.lib; $(MAKE)
It says that "No rule to make target 'libcomposition_adjustment.a', needed by 'all'. stop". But I thought the line %.a : $(LIB_DIR)/%.a
would handle that. I am making this pattern rule incorrectly?
If i try the second all:
line that is commented out, it works as expected.
Upvotes: 0
Views: 306
Reputation: 99084
The problem is here:
%.a : $(LIB_DIR)/%.a
This is a pattern rule with no commands, which Make does not interpret as an independent rule at all. There's more than one way to fix this; the simplest is probably to give it a do-nothing command:
%.a : $(LIB_DIR)/%.a
@:
but a better way is to do without the questionable rule altogether:
LIB_DIR = /prj/lib
LIBRARY := libcomposition_adjustment.a libtables.a libgeneral.a libbiblio.a
LIBRARY := $(addprefix $(LIB_DIR)/,$(LIBRARY))
all: $(LIBRARY)
$(LIB_DIR)/libtables.a:
cd Tables.lib; $(MAKE)
$(LIB_DIR)/libcomposition_adjustment.a:
cd Composition_adjustment.lib; $(MAKE)
$(LIB_DIR)/libgeneral.a:
cd General.lib; $(MAKE)
$(LIB_DIR)/libbiblio.a: $(LIB_DIR)/libgeneral.a
cd Biblio.lib; $(MAKE)
Upvotes: 3