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


# 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
RANLIB  = ranlib $@
#RANLIB = 

# Useful paths
PROJ_DIR        = ..

# 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)

# LDFLAGS contains all linker flags, which is mostly just paths to libraries.
LDFLAGS		= 

# These are the libraries linked to the program.  example: -lm
LIBS		= 

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

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

# Groups of source files
COLLISION_SOURCES = bounds.c collision.c dist.c matrix.c nbody.c 

# Groups of header files
COLLISION_HEADERS = $(COLLISION_SOURCES:.c=.h) collision_types.h options.h

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

# Groups of object files
COLLISION_OBJECTS  = $(COLLISION_SOURCES:.c=.o)

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

#All header files
ALL_HEADERS     = $(COLLISION_HEADERS)

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

#All executables
EXECUTABLES     =

#The compiled library
LIB = libcollide.a

LIB_DIR = $(PROJ_DIR)/lib
PUBLIC_INCLUDES = $(COLLISION_HEADERS)
INCLUDE_DIR = $(PROJ_DIR)/include

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

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


$(LIB): $(COLLISION_OBJECTS)
	/bin/rm -f $@
	ar ruv $@ $(COLLISION_OBJECTS)
	$(RANLIB)

# All programs in this directory.
all: $(LIB)


.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 *~ *% $(LIB)


# Strip and move the executables to the /bin directory.
install:
	/bin/cp $(LIB) $(LIB_DIR)
	/bin/cp $(PUBLIC_INCLUDES) $(INCLUDE_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.
