[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fwd: unable to fix the problem in the attached makefile]
From: |
Paul Smith |
Subject: |
Re: [Fwd: unable to fix the problem in the attached makefile] |
Date: |
Sun, 16 Jan 2011 12:51:54 -0500 |
> > From: Arup Upadhayay <address@hidden>
> > To: address@hidden
> > Subject: unable to fix the problem in the attached makefile
> > Date: Sun, 16 Jan 2011 02:28:02 -0800
> >
> > I have kept my source files under src folder, headers under inc folder and
> > objects under obj folder, my makefile works fine if i remove Copy.c and kep
> > only buddyAlloc.c , otherwise if i add Copy.c i get the error --no rule to
> > make target 'copy.c' needed by 'obj/buddyAlloc.o'.
> > What can be wrong with my makefile..please chk it once.
With a file this size it's simpler to just include it, rather than
attach it (unless your mail client is in the bad habit of reformatting
your mail).
SOURCE= buddyMain.c \
Copy.c \
OBJECTS=$(addprefix $(OBJ_DIR)/,$(SOURCE:.c=.o))
$(OBJECTS):$(SRC_DIR)/$(SOURCE)
$(CC) $(CFLAGS) -I$(INC_DIR) -o $(OBJ_DIR)/$(OBJECTS) -c $<
To see the problem, just expand the rule line here:
$(OBJECTS):$(SRC_DIR)/$(SOURCE)
Becomes:
obj/buddyMain.o obj/Copy.o:src/buddyMain.c Copy.c
because you didn't use $(addprefix ...) in the SRC_DIR setting, it's
just a simple string concatenation. That's why you're seeing the
problem you're seeing.
However even if you fix that, the above rule is not what you want. It
is interpreted by make like this:
obj/buddyMain.o : src/buddyMain.c src/Copy.c
...
obj/Copy.o : src/buddyMain.c src/Copy.c
In other words, each .o depends on both .c's, so whenever EITHER of
the .c files is changed, BOTH .o's will be rebuilt.
You want to use a pattern rule here instead:
obj/%.o : src/%.c
$(CC) $(CFLAGS) -I$(INC_DIR) -o $@ -c $<
--
-------------------------------------------------------------------------------
Paul D. Smith <address@hidden> Find some GNU make tips at:
http://www.gnu.org http://make.mad-scientist.net
"Please remain calm...I may be mad, but I am a professional." --Mad Scientist