############;-*-fundamental-*-###############################################
# 
# Makefile Jon Cohen and Krish Ponamgi's collision detection library
#
# RCS:	$Version$
#
#############################################################################


# variables for selecting graphics platform
#GRAPHICS_DEFINE  = -DSGI_GRAPHICS
#GRAPHICS_LIBS    = -lGL -lGLU -laux -lX11
#GRAPHICS_SOURCES = sgi.c
#GRAPHICS_HEADERS = sgi.h

GRAPHICS_DEFINE  = -DNO_GRAPHICS
GRAPHICS_LIBS    =
GRAPHICS_SOURCES =
GRAPHICS_HEADERS =





# These are the names of various programs used during "making".
# Pick whichever flavor of C you like with the CC variable.

CC	= gcc
RM	= /bin/rm
CO	= co
YACC    = yacc
LEX     = lex

# Useful paths
PROJ_DIR        = ..
BIN_DIR         = $(PROJ_DIR)/bin

# Name of the makefile
MAKEFILE	= Makefile

# INCLUDE supplies paths to header files.
INCLUDE		= -I. -I$(PROJ_DIR)/include

# optimization flags 
OPTIMIZE	= -O
#OPTIMIZE        = -g

# DBFLAGS contains flags for debugging code
DBFLAGS         =

# CFLAGS is all of the compiler options.  Put any extras here.
CFLAGS		= $(OPTIMIZE) $(INCLUDE) $(DBFLAGS) $(GRAPHICS_DEFINE)

# LDFLAGS contains all linker flags, which is mostly just paths to libraries.
LDFLAGS		= -L$(PROJ_DIR)/lib -L. -L/usr/local/lib -L/usr/lib 

# These are the libraries linked to the program.  example: -lm
LIBS		= -lcollide -lLP -lquat $(GRAPHICS_LIBS) -lm

# Flags used during the header file dependency generating stage.
DEPENDFLAGS	= $(CFLAGS) -Em

#------------------------------ Lists of Files -------------------------------#

# Groups of source files
NBODY_SOURCES = nbody.c

# Groups of header files
NBODY_HEADERS = polytope.h

#Other files (RCS files like lex/yacc that aren't source or header)
OTHER_FILES       =

# Groups of object files
NBODY_OBJECTS  = $(NBODY_SOURCES:.c=.o)
GRAPHICS_OBJECTS  = $(GRAPHICS_SOURCES:.c=.o)
ALL_OBJECTS  = $(NBODY_OBJECTS) $(GRAPHICS_OBJECTS)

#All source files not including generated ones 
ALL_SOURCES     = $(NBODY_SOURCES) $(GRAPHICS_SOURCES)

#All header files
ALL_HEADERS     = $(NBODY_HEADERS) $(GRAPHICS_HEADERS)

#All RCS files
ALL_RCS_FILES	= $(MAKEFILE) $(ALL_SOURCES) $(ALL_HEADERS) $(OTHER_FILES)

#All executables
EXECUTABLES     = nbody

#The compiled library
LIB =

INCLUDE_DIR = $(PROJ_DIR)/include

#--------------------------------- Main Rules --------------------------------#

#IMPORTANT - the object files must come BEFORE the libraries!!!


nbody: $(ALL_OBJECTS)
	/bin/rm -f nbody
	$(CC) $(CFLAGS) -o nbody  $(ALL_OBJECTS) $(LDFLAGS) $(LIBS)

# All programs in this directory.
all: nbody


.c :
	/bin/rm -f $@; $(CC) -o  $@  $< 


#--------------------------------- Handy Rules -------------------------------#

# Run lint on all of the source files.
lint : 
	lint $(LINT_FLAGS) $(ALL_SOURCES)

# Remove any intermediate files.
clean :
	$(RM) -f *.o *~ *% $(EXECUTABLES)


# Strip and move the executables to the /bin directory.
install:
	/bin/cp $(EXECUTABLES) $(BIN_DIR)

# Empty Rule
dummy:


#------------------------------RCS Rules--------------------------------------#

# Check out any new source files from RCS.
# uses RCS make depend rules to know how to check out
co: Makefile dummy
	make `for f in RCS/*,v ; do basename $$f ,v ; done`

	
# Check out copies of every file under RCS.  This does NOT lock them.
co_all: 
	co -u RCS/*

	
# check out a named revision of all RCS files
# use "make co_named NAME=name_to_get"
# dies on the undescriptive line [ "" != "" ] if no name is given
co_named:
	[ "$(NAME)" != "" ]
	co -r$(NAME) RCS/*

	
# give name to current revision of all RCS files
# make with "make named_rev NAME=name_to_give"
# dies on the undescriptive line [ "" != "" ] if no name is given
# does weird perl/touch stuff to not cause global checkout
named_rev:
	[ "$(NAME)" != "" ]
	for f in RCS/* ; do \
	  tim=`perl -e '($$m,$$h,$$d,$$mo,$$y) =' \
		-e '(localtime((stat("$$ARGV[0]"))[8]))[1..5];' \
	      -e 'printf("%02d%02d%02d%02d%02d\n",$$mo+1,$$d,$$h,$$m,$$y);' \
	      $$f`; \
	  rev=`rlog -h $$f | awk '{if ($$1 == "head:") print $$2}'`; \
	  rcs -N$(NAME):$$rev $$f; \
	  chmod +w $$f; touch $$tim $$f; chmod -w $$f; \
	done

#-----------------------------Dependency Rules--------------------------------#

# This one's from the pxpl5 makefiles
# It tacks dependencies for header files and RCS onto the end of the makefile.

depend: Makefile $(ALL_RCS_FILES)
	makedepend -- $(CFLAGS) -- $(ALL_SOURCES)
	-if [ -d RCS ] ; then \
	  echo ; echo '# RCS dependencies' ; echo '.PRECIOUS: \' ; \
	  for f in RCS/*,v ; do \
	    echo `basename $$f ,v` ; \
	  done | awk  '{if (length(line $$1) < 65) \
			  line = line $$1 " "; \
			else {print line,"\\"; line = $$1 " "}} \
		      END {print line}' ; echo ; \
	  for f in RCS/*,v ; do \
	    echo "`basename $$f ,v`: $$f ; \$$(CO) \$$?" ; \
	  done ; \
	fi >> Makefile

# DO NOT DELETE THIS LINE -- make depend depends on it.
