public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* dependencies for sources in sub dirs.
@ 2005-11-10  0:17 Tobias Grimm
  2005-11-10 12:42 ` John Love-Jensen
  0 siblings, 1 reply; 3+ messages in thread
From: Tobias Grimm @ 2005-11-10  0:17 UTC (permalink / raw)
  To: gcc-help

Hello!

Using gcc 4.0.2, I have the following problem:

Calling "gcc -MM src/foo.c" results in:

foo.o: src/foo.c src/bar.h

But IMHO that's wrong. The manpage says:

       -MT target
           Change the target of the rule emitted by dependency
generation.  By
           default CPP takes the name of the main input file, including any
           path, deletes any file suffix such as .c, and appends the plat-
           form's usual object suffix.  The result is the target.

"By default CPP takes the name of the main input file, including any
path" !!!

So I would assume to get this:

src/foo.o: src/foo.c src/bar.h

But I don't and so the generated dependencies are useless.

Is this a bug in gcc or the manpage, or am I doing something wrong? How
can I force gcc to include the path in the target? -MT is not an option,
because I have several different subdirectories.

Hope someone knows an answer....

Regards,

Tobias

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: dependencies for sources in sub dirs.
  2005-11-10  0:17 dependencies for sources in sub dirs Tobias Grimm
@ 2005-11-10 12:42 ` John Love-Jensen
  2005-11-10 13:26   ` Tobias Grimm
  0 siblings, 1 reply; 3+ messages in thread
From: John Love-Jensen @ 2005-11-10 12:42 UTC (permalink / raw)
  To: Tobias Grimm, MSX to GCC

Hi Tobias,

Try this experiment:

mkdir src
vi src/Foo.c
(put in something simple:  int foo() { return 3; } )
gcc -c src/Foo.c

Does the Foo.o end up in your current working directory, or in src/Foo.o?

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: dependencies for sources in sub dirs.
  2005-11-10 12:42 ` John Love-Jensen
@ 2005-11-10 13:26   ` Tobias Grimm
  0 siblings, 0 replies; 3+ messages in thread
From: Tobias Grimm @ 2005-11-10 13:26 UTC (permalink / raw)
  To: John Love-Jensen; +Cc: MSX to GCC

John Love-Jensen wrote:
> mkdir src
> vi src/Foo.c
> (put in something simple:  int foo() { return 3; } )
> gcc -c src/Foo.c
>
> Does the Foo.o end up in your current working directory, or in src/Foo.o?
>   

In this case, Foo.o is created in ./ instead of src/. But in my 
makefile, I force output with "-o" to src/Foo.o. (See example below).

As a short-hand solution, I modify the dependencies with Sed to prefix 
the target with the full path of the first dependent source:

sed "s/.*: \([^ ]*\/\).*/\1\0/"

This works,  but I thought there might be a way to instruct gcc to 
create the dependencies right in the first place.

Here's the small example:

src/foo.cc:
    #include "bar.h"

    int main()
    {
        return 0;
    }

src/bar.h:
    // EMPTY

Makefile:
    SRCS  = src/foo.c
    OBJS := $(addsuffix .o,$(basename ${SRCS}))

    %.o: %.cc
            gcc $< -o $@

    .dependencies: Makefile
            @gcc -MM -MG $(SRCS) > $@

    -include .dependencies

    test:$(OBJS)
            gcc $(OBJS) -o $@

    clean:
            @-rm -f $(OBJS) .dependencies test

Tobias

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-11-10 13:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-10  0:17 dependencies for sources in sub dirs Tobias Grimm
2005-11-10 12:42 ` John Love-Jensen
2005-11-10 13:26   ` Tobias Grimm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).