[Top][All Lists]

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

My first makefile. Please help.

From: Andrea Riciputi
Subject: My first makefile. Please help.
Date: Wed, 18 Dec 2002 16:32:46 +0100

I'm quite new to make and I'm trying to build my own makefile. I've already read the make manual and searched the web for some tutorials without success. I hope someone of you could help me. I'm sorry because surely this is a well known topic, but I've not found any hint about it on the net.

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

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

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

AllFiles = $(wildcard *)
HeaderFiles = $(filter %.h, $(AllFiles))
SourceFiles = $(filter %.c, $(AllFiles)))

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

MyProject: $(ObjectFiles)
        $(CCompiler) $(CFLAGS) $(LDFLAGS) $(ObjectFiles) -o $@

$(ObjectDir)%.o: $(SourceDir)%.c
        $(CCompiler) $(CFLAGS) -c $< -o $@

But it doesn't work. All what I get is the following error message:

make: *** No rule to make target `obj/CArrays.o', needed by `NewGal'. Stop.

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

Thanks in advance,

Andrea Riciputi        <mailto:address@hidden>

"Science is like sex: sometimes something useful comes out,
but that is not the reason we are doing it" -- (Richard Feynman)

reply via email to

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