PDA

View Full Version : Makefile - How to get files from dir?



Trinithis
10-24-2007, 07:57 PM
**EDIT**

I finally found an good and extensive tutorial on makefiles, and I was able to accomplish my task.

(The site is http://www.delorie.com/gnu/docs/make/make_toc.html if anyone cares. I still don't know what all the flags do and all, but perhaps when I get down to reading more of the tutorial, I might be able to glean some info from that.)


CC = g++
CFLAGS = -c -Wall
LDFLAGS =
SOURCES := $(wildcard *.h) $(wildcard *.cpp)
EXECUTABLE = Test2
OBJECTS = $(EXECUTABLE).o

$(OBJECTS) : $(SOURCES)


all : $(SOURCES) $(EXECUTABLE)


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

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


******************************
************END EDIT***********
******************************

Here is a makefile that I have:


CC= g++
CFLAGS= -c -Wall
LDFLAGS=
SOURCES= Test2.cpp LinkedList.h
OBJECTS= $(SOURCES:.cpp=.o)
EXECUTABLE= Test2

$(OBJECTS) : $(SOURCES:.h=.cpp) $(SOURCES)

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS) $(SOURCES:.h=.cpp)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@

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


Instead of adding headers to SOURCES every time I make a new class, is there a way for SOURCES to include every .h file inside a certain directory? All files in its subdirectories as well? (Preferrably the dir the makefile file is in.)

PS:
What exactly are .o files?