Results 1 to 1 of 1

Thread: Makefile - How to get files from dir?

  1. #1
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default Makefile - How to get files from dir?

    **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.)
    Code:
    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:
    Code:
    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?
    Last edited by Trinithis; 10-25-2007 at 06:38 AM.
    Trinithis

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •