# Simple Project Build System (SPBS) - 
#
# Description :
#    SPBS is a build system for simple projects that
#    exists in a single directory.
#    Such a project might be a library that has a number of
#    source files (in C or C++) which are to be compiled
#    into one library file (.a or .so) for use in other
#    projects.  The project also includes several test programs,
#    example programs and a useful program.
#
#    Modification to the Makefile should be limited to 
#    the PROJECT section and on occasion into the
#    BUILD OPTIONS section to change compiler flags 
#    and the like.
#
#    EXAMPLE:  
#      Files:
#        foo.c / h             Library Source/Header file
#        foohelper01.c / h     Helper Source/Header files
#        datastructure.c / h    Helper Source/Header files
#        test_foo_short.c      C Test Exec 
#        test_foo_med.c        C Test Exec
#        test_foo_long.c       C Test Exec
#        example01.c           C Example Exec 
#        example02.cpp         C++ Example Exec
#        example03.cpp         C++ Example Exec
#        meaningful.cpp        A program that does something useful
#        
#      Lets also assume that the library depends on the math library (libm)
#      and on a library located at /external/lib/libext with header files at
#      /external/include
#        
#      In addition to creating the test, example and meaningful programs
#      a library called libfoo.a will be created
#
#    The PROJECT SECTION should look as follows:
#
#
#    PROJECTNAME = Foo Project
#    CONTACTINFO = contact@fooproject.com
#    TARGETS = meaningful
#    TESTTARGETS = test_foo_short test_foo_med test_foo_long
#    EXAMPLETARGETS = example01 example02 example03
#    LIBTARGET = foo
#    OBJFILES = foo.o foohelper01.o datastructure.o
#    HEADERFILES = foo.h foohelper01.h datastructure.h
#    INCLUDEPATH = -I/external/include
#    LIBS = -L/external/lib -lext -lm
#
#
# OPTIONS:
#   VERBOSE  e.g.  % make VERBOSE=1
#
#
# Update Log :
#    Dec 2004 -  Born 
#
# Author : Marc Zinck (mbz@cmu.edu) Dec 2004



##############################################
#                  PROJECT                   # 
##############################################

PROJECTNAME = wiiLine

CONTACTINFO = E. Gil Jones (egjones@cs.cmu.edu)

TARGETS = wiiLine

TESTTARGETS = 

EXAMPLETARGETS = 

LIBTARGET = 

OBJFILES = 

HEADERFILES = generalInclude.h random_ArrivalTime.h better_ArrivalTime.h

INCLUDEPATH = -I /usr/include -I .

LIBPATH = 

LIBS = -L/usr/lib -lstdc++ -lm

##############################################
#               BUILD OPTIONS                #
##############################################

CXX = g++
CXXFLAGS = -Wall -g

LD = g++
LDFLAGS =

RM = rm
RMFLAGS = -f

AR = ar
ARFLAGS = rvs

ECHO = @echo


#############################################
#              DIRTY DETAILS                #
#############################################

ifdef VERBOSE
	SILENT = 
else
	SILENT = @
endif

.SUFFIXES: .cc .cpp .cxx

.cc.o:
	@echo "Compiling $@"
	$(SILENT) $(CXX) -c $(CXXFLAGS) $(INCLUDEPATH) $<

.cpp.o:
	@echo "Compiling $@"
	$(SILENT) $(CXX) -c $(CXXFLAGS) $(INCLUDEPATH) $<

.cxx.o:
	@echo "Compiling $@"
	$(SILENT) $(CXX) -c $(CXXFLAGS) $(INCLUDEPATH) $<

help: helpheader helpbody helpfooter

ifdef PROJECTNAME
helpheader: force
	@echo ""
	@echo "$(PROJECTNAME) Build System:"
else
helpheader: force
	@echo ""
	@echo "Simple Project Default Build System:"
endif

helpbody: force
	@echo " To get started right away run the following:"
	@echo "  % make depend" 
	@echo "  % make all"


ifdef CONTACTINFO
helpfooter: force
	@echo "Contact: $(CONTACTINFO)"
	@echo ""
else
helpfooter: force
	@echo ""
endif



all: targets tests examples lib

targets: $(TARGETS)

tests: $(TESTTARGETS)

examples: $(EXAMPLETARGETS)

lib: $(LIBTARGET)

depend:
	@echo "Creating Depenancy File"
	$(SILENT) -$(CXX) -M $(CXXFLAGS) $(wildcard *.c) $(wildcard *.cpp) $(wildcard *.cc) $(wildcard *.cxx) > makedepend

lib$(LIBTARGET).a: $(OBJFILES)
	$(ECHO) "---------- Building $@ ----------"
	$(SILENT) $(AR) $(ARFLAGS) $@ $^

$(TARGETS): $(OBJFILES) $(TARGETS).o
	$(ECHO) "---------- Linking $@ ----------"
	$(SILENT) $(LD) $^ $(LDFLAGS) $(LIBS) -o $@

$(TESTTARGETS): $(TESTTARGETS).o $(OBJFILES)
	$(ECHO) "---------- Linking $@ ----------"
	$(SILENT) $(LD) $^ $(LDFLAGS) $(LIBS) -o $@

$(EXAMPLETARGETS): $(EXAMPLETARGETS).o $(OBJFILES)
	$(ECHO) "---------- Linking $@ ----------"
	$(SILENT) $(LD) $^ $(LDFLAGS) $(LIBS) -o $@


distclean: clean
	@echo "Removing targets, example targets and test targets"
	$(SILENT) $(RM) $(RMFLAGS) $(TARGETS) $(EXAMPLETARGETS) $(TESTTARGETS)

clean:
	@echo "Removing dependancy file, object files, temporary files and core"
	$(SILENT) $(RM) $(RMFLAGS) makedepend *.o *~ core

force:

-include makedepend
