help-make
[Top][All Lists]
Advanced

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

Problem with a directory name in a rule


From: Vincent De Groote
Subject: Problem with a directory name in a rule
Date: Fri, 22 Oct 2010 00:16:08 +0200

Hello,

I have a problem with a makefile (sic !).  gmake is executed in a build
directory, with several subdirectories.
I want to build a library from several sources, and then build an executable
from a test file and that library.

If I do not try to put the object files in the objects directory, everything
works fine.
When I try to write the objects in the objects directory, gmake ends with
the following error:

make: *** No rule to make target `objects/tester.o', needed by
`bin/tester.exe'.  Stop.

In my mind, the rule

$(OBJECTS_DIR)/%.o : %.c makefile

should do the job.

I've read the documentation about the stems, but I guess there is something
I does not understand.

Can someone help me ?

Thanks for your replies

Vincent De Groote



I'm using the following Makefile:

BIN_DIR=bin
LIBRARY_DIR=library
INCLUDE_DIR=include
OBJECTS_DIR=objects
SOURCES_DIR=../sources

-include $(OBJECTS_DIR)/*.dep

VPATH     = $(SOURCES_DIR)

LIBRARY_SOURCES = function.c


.PHONY: all
all:: subdirs $(BIN_DIR)/tester.exe


$(OBJECTS_DIR)/%.o : %.c makefile
        gcc -c  $(GCC_OPTIONS) -MM -MT ${OBJECTS_DIR}/$(notdir
$(basename $<)).o -MF ${OBJECTS_DIR}/$(notdir $(basename $<)).dep
${SOURCES_DIR}/$<
        gcc $(GCC_OPTIONS)  -o $@ -c $<


$(LIBRARY_DIR)/functions.a: $(addprefix ${OBJECTS_DIR}/,$(notdir
$(LIBRARY_SOURCES:.c=.o)))
        ar -cru $@ $^

$(BIN_DIR)/tester.exe: $(OBJECTS_DIR)/tester.o $(LIBRARY_DIR)/functions.a
        gcc -o $@ $^



.PHONY: subdirs
subdirs:
        mkdir -p $(BIN_DIR) $(LIBRARY_DIR) $(INCLUDE_DIR) $(OBJECTS_DIR)


reply via email to

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