Connecting Tech Pros Worldwide Forums | Help | Site Map

makefile

Juhan Voolaid
Guest
 
Posts: n/a
#1: Aug 14 '05
Hello

I need help with my makefile, so that when I compile my project the
source code files would be separated from the object (*.o) files.

So if I have: main.cpp and classes.cpp - the filestructure should be
like that:
project_dir/
source_dir/
main.cpp
classes.cpp
makefile
main.o
classes.o
.program_exec

My current makefile is quite good as it compiles only the source, that
is edited. Problem is that all the files are in same directory. I'd like
that the makefile should do the same thing, only with this add on that
it keeps the source files from other compiled files separeted.
#########################
# makefile #
#########################
CC=g++
CFLAGS=-c -Wall
LDFLAGS=
SOURCES=main.cpp classes.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=program_exec

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@

..cpp.o:
$(CC) $(CFLAGS) $< -o $@

makfile:

Ian
Guest
 
Posts: n/a
#2: Aug 14 '05

re: makefile


Juhan Voolaid wrote:[color=blue]
> Hello
>
> I need help with my makefile, so that when I compile my project the
> source code files would be separated from the object (*.o) files.
>[/color]
OT here, try comp.unix.programmer.

Ian
Gianni Mariani
Guest
 
Posts: n/a
#3: Aug 14 '05

re: makefile


Juhan Voolaid wrote:[color=blue]
> Hello
>
> I need help with my makefile, so that when I compile my project the
> source code files would be separated from the object (*.o) files.[/color]

As mentioned - this is OT here.

However, take a look at MakeXS. http://www.makexs.com (shameless plug).
It can do this if you need to. MakeXS is just a GNU Makefile but
rather extreme.
[color=blue]
>
> So if I have: main.cpp and classes.cpp - the filestructure should be
> like that:
> project_dir/
> source_dir/
> main.cpp
> classes.cpp
> makefile
> main.o
> classes.o
> .program_exec
>
> My current makefile is quite good as it compiles only the source, that
> is edited. Problem is that all the files are in same directory. I'd like
> that the makefile should do the same thing, only with this add on that
> it keeps the source files from other compiled files separeted.
> #########################
> # makefile #
> #########################
> CC=g++
> CFLAGS=-c -Wall
> LDFLAGS=
> SOURCES=main.cpp classes.cpp
> OBJECTS=$(SOURCES:.cpp=.o)
> EXECUTABLE=program_exec
>
> all: $(SOURCES) $(EXECUTABLE)
>
> $(EXECUTABLE): $(OBJECTS)
> $(CC) $(LDFLAGS) $(OBJECTS) -o $@
>
> .cpp.o:
> $(CC) $(CFLAGS) $< -o $@
>
> makfile:[/color]
Closed Thread