help-make
[Top][All Lists]
Advanced

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

Re: Makefile not correctly rebuilding project


From: Alex Buell
Subject: Re: Makefile not correctly rebuilding project
Date: Tue, 08 Jun 2010 01:01:53 +0100

On Mon, 2010-06-07 at 15:37 +0000, Greg Chicares wrote:
> On 2010-06-07 14:48Z, Alex Buell wrote:
> > 
> > $ gcc -M -ggdb3 assembler/vasm.c 
> > vasm.o: assembler/vasm.c /usr/include/stdio.h /usr/include/features.h \
> [...]
> > Seems it doesn't prefix the vasm.o with the directory name, which might
> > be why the sed regexp broke. Any ideas or workarounds for this one? 
> 
> This works well for me:
>   http://make.paulandlesley.org/rules.html
> "Life is simplest if the targets are built in the current working directory."

OK, so I simplified things and set up some rules, but am hit with a
different problem now. 

I wrote some rules and put them into rules.mk in project root directory:

CC      = gcc
LD      = gcc
SED     = sed

CFLAGS  = -ggdb3
LFLAGS  =

SED = sed

%.d: %.c
        $(CC) -MM $(CFLAGS) $< | $(SED) -e 's/$*.o/& $@/g' > $@

%.o: %.c
        $(CC) $(CFLAGS) -c $^ -o $@

%: %.o
        $(LD) $(LFLAGS) $^ -o $@

Then put a Makefile into each of the source directories, for example in
vasm/, I put the following:

#
# $Header$
#
# $Date$
# $Revision$
# $Author$
#
# Copyright (C) 2010 Alex Buell <address@hidden>
# All Rights Reserved.
#

-include ../rules.mak

PROGRAM = vasm
SOURCES = vasm.c version.c help.c
include $(SOURCES:.c=.d)
OBJECTS = $(SOURCES:.c=.o)

.PHONY: clean
clean:
        rm -f $(OBJECTS) $(SOURCES:.c=.d) $(PROGRAM)

Now it does the dependencies correctly:

$ make
Makefile:16: vasm.d: No such file or directory
Makefile:16: version.d: No such file or directory
Makefile:16: help.d: No such file or directory
gcc -MM -ggdb3 help.c | sed -e 's/help.o/& help.d/g' > help.d
gcc -MM -ggdb3 version.c | sed -e 's/version.o/& version.d/g' >
version.d
gcc -MM -ggdb3 vasm.c | sed -e 's/vasm.o/& vasm.d/g' > vasm.d
gcc -ggdb3 -c vasm.c vasm.h -o vasm.o
gcc: cannot specify -o with -c or -S with multiple files
make: *** [vasm.o] Error 1

That's the problem:
$ more vasm.d
vasm.o vasm.d: vasm.c vasm.h

Hmm, it got both vasm.c and vasm.h, can't be right. Any ideas?
-- 
http://www.munted.org.uk

One very high maintenance cat living here.



reply via email to

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