help-make
[Top][All Lists]
Advanced

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

Re: My first makefile. Please help.


From: Paul D. Smith
Subject: Re: My first makefile. Please help.
Date: Wed, 18 Dec 2002 17:41:37 -0500

%% Andrea Riciputi <address@hidden> writes:

  ar> I've a C source code divided among several files in a single
  ar> directory (~/Project), I'd like to put all the object files in a
  ar> different sub-directory (let say ~/Project/obj). I've tried
  ar> something like this:

  ar> CCompiler = cc
  ar> CFLAGS = -g -O2 -Wno-long-double -I/sw/include
  ar> LDFLAGS = -L/sw/lib -lgsl -lm

  ar> CurrentDir = ~/Project
  ar> SourceDir = $(CurrentDir)
  ar> ObjectDir = $(CurrentDir)/obj

So, SourceDir is the string "~/Project" and ObjectDir is the string
"~/Project/obj" (sans quotes of course).

  ar> AllFiles = $(wildcard *)

I agree with the other comments, using wildcard like this is not, IMO, a
robust and reliable way to construct makefiles.

Have your users list the files they want to build explicitly in the
makefile.  It doesn't take much time, esp. considering how rare it is
(considering the whole life of a project) to create a new file.  And
it's much safer (what if someone makes a little .c file just to test
something?)

  ar> ObjectFiles = $(patsubst %.c,$(ObjectDir)/%.o,$(SourceFiles))

After this, ObjectFiles contains strings like "~/Project/obj/foo.o",
etc.

  ar> $(ObjectDir)%.o: $(SourceDir)%.c

OK, so this line expands to:

  ~/Project/obj%.o: ~/Project%.c

which seems suspicious to me.  Try adding in the slashes and see if that
works better:

 $(ObjectDir)/%.o: $(SourceDir)/%.c

You might also try using the explicit variable $(HOME) rather than
relying on tilde expansion, just to see if that helps.

  ar> I've tried several other methods (including vpath %.o /obj) but it 
  ar> seems that none of them work. How can I get what I want?

VPATH won't help you; that's not what it's for.  See my site below for
some tips on how (and how not) to use VPATH.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist



reply via email to

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