help-gnu-utils
[Top][All Lists]
Advanced

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

Writing a simple make file?


From: ovesvenssons
Subject: Writing a simple make file?
Date: 16 Aug 2005 05:57:49 -0700
User-agent: G2/0.2

I'm trying to write a simple make file that automatically finds all C++
source files, compiles a corresponding object file and puts it in
directory "build" and then links the resulting binary. But I don't know
how to put the object files in directory "build" - they always end up
in the same directory as the source files.

Here is my make file:

# ============
#  Variables
# ============
PROGRAM = program.bin

CXX = c++

SOURCES = $(shell ls src/*.cpp)
OBJECTS = $(SOURCES:.cpp=.o)

INCS = -Iinclude -Igfx
LIBS = -L/app/glib/1.2.10/lib -L/app/gtk+/1.2.10/lib

# ============
#  Targets
# ============
$(PROGRAM): $(OBJECTS)
        $(CXX) -o $(PROGRAM) $(OBJECTS) $(LIBS)

%.o : %.cpp
        $(CXX) -c $(INCS) -o $@ $<


clean:
        \rm src/*.o $(PROGRAM)


I suppose I have to move the object file at the end of target "%.o" to
the "build" directory, but I don't know how.



reply via email to

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