############;-*-fundamental-*-###############################################
# 
# Top Level Makefile for I_COLLIDE
#
# 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 -------------------------------#



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

# Always remake everything if make is called from this top-level directory
#   -- guarantees everything made for the same architecture, etc.
all: 
	cd libLP; $(MAKE) clean; $(MAKE); $(MAKE) install
	cd libcollide; $(MAKE) clean; $(MAKE); $(MAKE) install
	cd libquat; $(MAKE) clean; $(MAKE); $(MAKE) install
	cd nbody; $(MAKE) clean; $(MAKE)


.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.
