makefile

Hi,

I need to create a makefile for my project. We need to use options in
such a way that executable files, source files and obj files will be stored
in separate directories. How to route obj files to a specfic directory
(which is not same as diretory in which source code is stored)?

Thanks,
Krupa

“Krupa” <krupah@hotmail.com> wrote in message
news:a1luhh$974$1@inn.qnx.com

Hi,

I need to create a makefile for my project. We need to use options in
such a way that executable files, source files and obj files will be
stored
in separate directories. How to route obj files to a specfic directory
(which is not same as diretory in which source code is stored)?

There are many ways to do this: here is what I do:

First I defined the target as:
$(target): $(addprefix $(objpath)/,$(object)) $(EXTRALIBS) usage

Thanks,
Krupa

“Krupa” <krupah@hotmail.com> wrote in message
news:a1luhh$974$1@inn.qnx.com

Hi,

I need to create a makefile for my project. We need to use options in
such a way that executable files, source files and obj files will be
stored
in separate directories. How to route obj files to a specfic directory
(which is not same as diretory in which source code is stored)?

Sorry for other post I hit a wrong key:

Here is a very strip down version of a Makefile file I sometime use under
QNX4
INCPATH defines location of header files. OBJPATH defines location of
object
files. TARGET is the full path of where to store the executable

I like to have my makefile automaticaly build list of object files from the
sources in the directory, but I wanted to keep things simple here.

Check out use of vpath to tell make where to search for certain files.
Personnaly I have not yet master the use of vpath and have manage
without it :wink:

================================
INCPATH = -Iinclude

TARGET = exec/application
OBJECT = src1.o src2.o src3.o
SRC = src1.c src2.c src3.c

OBJPATH = obj

default:
$(MAKE) $(TARGET)

automatical prefix object files with the path

OBJLIST= $(addprefix $(OBJPATH)/,$(OBJECT1))

$(TARGET): $(OBJLIST)
$(LD) $(LDFLAGS) $(OBJLIST) -o $@

CFLAGS = $(INCPATH) -o$@

$(OBJPATH)/%.o: %.c
$(COMPILE.c) $<