help-make
[Top][All Lists]
Advanced

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

Re: how to force make to do a secondary search for source files?


From: Kristof Provost
Subject: Re: how to force make to do a secondary search for source files?
Date: Tue, 29 May 2007 19:58:53 +0200
User-agent: Thunderbird 1.5.0.10 (X11/20070403)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


>> The source of your problem is quite simple. Your
>> rules don't create
>> what they claim to create:
>>
>> %.cpp: %.xrc
>>    wxrc -c -oobj\$@ $<
>>
>>
>> The rule claims that a.xrc will be turned into
>> a.cpp, but it actually
>> produces obj/a.cpp
>>
>>
>> Fix that and your problem will be gone.
>
> Ok, but how can I fix it?
> My last almost successful attempt looks like this:
> -------------
> OBJS=$(objdir)/main.o $(objdir)/icons.o
> SDIR=obj
>
> .INTERMEDIATE: $(objdir)/icons.cpp
>
> vpath %.xrc src
> vpath %.cpp src obj
>
> all: subdirs test
>
> subdirs: $(SDIR)
>
> $(SDIR):
>      mkdir $@
>
> test: $(OBJS)
>     g++ -o$@ $(OBJS)
>
> $(objdir)/%.cpp: %.xrc
>    wxrc -c -o$@ $<
>
> $(objdir)/%.cpp: %.xrc
>    wxrc -c -o$@ $<
>
> -------------
> That do sucessful compilation all the way, exactly
> like I want it to be...
> But there is a lot of "$(objdir)/" in makefile... How
> to get rid of them?
>
>
> George Brink
Do you still have problems with this Makefile? It looks ok.

You can probably clean up a few things like this:

OBJS=main.o icons.o
SDIR=obj

vpath %.xrc src
vpath %.cpp src obj

all: test

test: $(addprefix $(SDIR), $(OBJS))
    g++ -o$@ $^

$(objdir)/%.cpp: %.xrc
   @mkdir -p $(@D)
   wxrc -c -o $@ $<

$(objdir)/%.o: %.cpp
   @mkdir -p $(@D)
   gcc -c -o $@ $<
 

It saves you a few references to objdir, and it simplifies the
creation of your object directory.
It's true that this Makefile will try to create the directory even if
it already exists. Have a look at
http://www.cmcrossroads.com/content/view/6936/268/ for hints on how to
handle this. I usually avoid the fancy rules, a few extra mkdir calls
aren't going to slow you down much and the alternatives aren't as easy
to understand.

Kristof



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGXGncUEZ9DhGwDugRAvePAJ42stAFKYmKauFtbxquVqq1J3Qs3gCeP3XH
8M0tGFWIQhiNfp5UIbz0F0s=
=AQ2O
-----END PGP SIGNATURE-----





reply via email to

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