Unix Programming - Makefiles and VPATH

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > February 2007 > Makefiles and VPATH





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Makefiles and VPATH
chaosphoenix@gmail.com

2007-02-12, 7:29 pm

I'm trying to create a make file that can pull source files from
various directories, create objects, and link those objects into a
final executable. Nothing big right? Well, I thought VPATH would
handle all my directory structure woes, but that doesn't seem to be
the case. Can anyone of you give me a better hint on how to use VPATH
and what I am doing wrong? I'll provide an example of how I'm using it
currently below:

....

INCLUDES = mydir/includes
APIINCLUDES = mydir/api/includes
LIBRARY = mydir/lib
SOURCE = mydir/source/project1/app

VPATH = $(INCLUDES) $(APIINCLUDES) $(LIBRARY) $(SOURCE)

OBJECTS = (List of objects goes here)

..PHONY
all : $(OBJECTS)
// EXE compiler code here

..o :
$(CC) -c -o $(@) -D $(BASEDEFINES) $(ARMCPPFLAGS) -I $
(INCLUDEFLAGS) $(patsubst %.o,%.c,$(SOURCE))

I then get errors like "Compile Error: Cannot read <object name>.c
file", which I assume is because it's not finding it in the
directories I listed above.

Giorgos Keramidas

2007-02-12, 7:29 pm

On 12 Feb 2007 12:07:10 -0800, chaosphoenix@gmail.com wrote:
> I'm trying to create a make file that can pull source files from
> various directories, create objects, and link those objects into a
> final executable. Nothing big right? Well, I thought VPATH would
> handle all my directory structure woes, but that doesn't seem to be
> the case. Can anyone of you give me a better hint on how to use VPATH
> and what I am doing wrong? I'll provide an example of how I'm using it
> currently below:
>
> ...
>
> INCLUDES = mydir/includes
> APIINCLUDES = mydir/api/includes
> LIBRARY = mydir/lib
> SOURCE = mydir/source/project1/app
>
> VPATH = $(INCLUDES) $(APIINCLUDES) $(LIBRARY) $(SOURCE)
>
> OBJECTS = (List of objects goes here)
>
> .PHONY
> all : $(OBJECTS)
> // EXE compiler code here
>
> .o :
> $(CC) -c -o $(@) -D $(BASEDEFINES) $(ARMCPPFLAGS) -I $
> (INCLUDEFLAGS) $(patsubst %.o,%.c,$(SOURCE))
>
> I then get errors like "Compile Error: Cannot read <object name>.c
> file", which I assume is because it's not finding it in the
> directories I listed above.


You haven't specified any dependency rules for the SOURCES -> OBJECTS
build, as far as I can see. Why is that?

chaosphoenix@gmail.com

2007-02-12, 7:29 pm

On Feb 12, 3:41 pm, Giorgos Keramidas <keram...@ceid.upatras.gr>
wrote:
> On 12 Feb 2007 12:07:10 -0800, chaosphoe...@gmail.com wrote:
>
>
>
>
>
>
>
>
>
>
>
> You haven't specified any dependency rules for the SOURCES -> OBJECTS
> build, as far as I can see. Why is that?


Yea, that was actually a mistake, that line was out of date. I managed
to fix the problem. I changed everything from absolute paths to
relative paths and fixed a few commands in my compiler options. Seems
to be working alright now.

Thanks for the help anyway.

toby

2007-02-12, 7:29 pm

On Feb 12, 6:07 pm, chaosphoe...@gmail.com wrote:
> I'm trying to create a make file that can pull source files from
> various directories, create objects, and link those objects into a
> final executable. Nothing big right? Well, I thought VPATH would
> handle all my directory structure woes, but that doesn't seem to be
> the case. Can anyone of you give me a better hint on how to use VPATH
> and what I am doing wrong? I'll provide an example of how I'm using it
> currently below:
>
> ...
>
> INCLUDES = mydir/includes
> APIINCLUDES = mydir/api/includes
> LIBRARY = mydir/lib
> SOURCE = mydir/source/project1/app
>
> VPATH = $(INCLUDES) $(APIINCLUDES) $(LIBRARY) $(SOURCE)
>
> OBJECTS = (List of objects goes here)
>
> .PHONY
> all : $(OBJECTS)
> // EXE compiler code here
>
> .o :
> $(CC) -c -o $(@) -D $(BASEDEFINES) $(ARMCPPFLAGS) -I $
> (INCLUDEFLAGS) $(patsubst %.o,%.c,$(SOURCE))


This is all very confused, I'm afraid.

Try this:

INCLUDES = mydir/includes
APIINCLUDES = mydir/api/includes
LIBRARY = mydir/lib

SRCDIR = mydir/source/project1/app
# you'd be better listing source files explicitly IMHO...
# they don't need to be qualified with the directory name.
SRCFILES = file1.c file2.c # whatever
EXE = prog # whatever

# vpath only needs to reference the directory in which
# to search for prereqs (.c's) - not include or lib dirs
VPATH = $(SRCDIR)

# derive object list from source list
OBJECTS = $(patsubst %.c, %.o, $(SRCFILES))

all : $(EXE)

# presumably you want some -lxx options as well
$(EXE) : $(OBJECTS)
$(CC) -o $@ $^ -L$(LIBRARY)

# btw, you need to fix your use of -D and -I
# e.g. BASEDEFINES = -DABC=1 -DDEF=2
# INCLUDEFLAGS = -I$(INCLUDES) -I$(APIINCLUDES)
%.o : %.c
$(CC) -c -o $@ $(BASEDEFINES) $(ARMCPPFLAGS) $(INCLUDEFLAGS) $<





>
> I then get errors like "Compile Error: Cannot read <object name>.c
> file", which I assume is because it's not finding it in the
> directories I listed above.



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com