# Makefile for Core Library
# $Id: Makefile,v 1.23 2004/11/08 17:56:04 exact Exp $

#################################################################
#
# Warning: this make file will best work with GNU's gmake
#
#################################################################

#################################################################
#	Core Library Parameters
#################################################################
PACKAGE=core
VERSION=1.7	# official release will have x.y, and intermediate
		# releases will be x.y.z (for z=1,2,etc)
CORE_PATH:=$(shell pwd)
CVSROOT=/home/exact/cvsroot
SUB_DIRS=src ext doc lib progs

# The following is needed to make sure that CC are properly 
#  for installing gmp
include Make.config

#################################################################
#	gmp paths  (Make your choice the last one)
#################################################################
gmp	    := gmp-3.1.1
gmp	    := gmp-4.0.1
gmp	    := gmp-4.1
gmp	    := gmp-4.1.2
gmp	    := gmp-4.1.4

#################################################################
#	Default make target 
#################################################################
# This default is used when you want to change the Core library
#	without changing platform or gmp.

default: core

#################################################################
#	Make everything in one step
#################################################################
# This makes both the gmp and core library

all:  first second third testgmp fourth fifth

#################################################################
#	Core Library Installation Steps
#################################################################

# First Step: configure for gmp
first configure:
	@echo "Configure for GMP..."
	-gzip -cd ${gmp}.tar.gz | tar xvf -
	-cd ${gmp}; ./configure CC=${CC} ${GMP_ABI} --prefix=${GMP_PREFIX} 2>&1 \
		 | tee ${CORE_PATH}/tmp/DIAG_CONFIG 
	@echo "See file tmp/DIAG_CONFIG for screen output"
	@echo ""

# Second Step: build gmp libraries
second gmp:
	@echo "Build GMP Library..."
	-${MAKE} -C ${gmp} 2>&1 | tee ${CORE_PATH}/tmp/DIAG_GMP
	@echo "See file tmp/DIAG_GMP for screen output"
	@echo ""

# Third Step: install gmp libraries and include files
third:
	@echo "Install GMP Library..."
	-${MAKE} -C ${gmp} install 2>&1 \
		| tee ${CORE_PATH}/tmp/DIAG_GMPINSTALL
	@echo "See file tmp/DIAG_GMPINSTALL for screen output"
	@echo ""

# Fourth Step: build Core Library, Extensions and Sample Programs
fourth: core

#################################################################
#	Test gmp
#################################################################

testgmp:
	-${MAKE} -C ${CORE_PATH}/progs/generic testgmp \
			2>&1 | tee ${CORE_PATH}/tmp/DIAG_TESTGMP


#################################################################
#	Basic Core Functions
#################################################################

# This target is also useful when you need to re-compile the Core
#	Library.  Typically, you may need a "debugging version"
#	of CORE (for the debugger to work).  In this case, you set
#	VAR=Debug in Make.config, and type "make core".  This would
#	create the library file "libcoreDebug.a" or "libcoreDebug.so".

core:	corelib corex demo

# Make Core Library
corelib:
	@echo "Build Core Library..."
	-${MAKE} -C src 2>&1 | tee ${CORE_PATH}/tmp/DIAG_CORELIB
	@echo "See file tmp/DIAG_CORELIB for screen output"
	@echo ""

# Make Core Extension Library
corex:
	@echo "Build Core Extension Library..."
	-${MAKE} -C ext 2>&1 | tee ${CORE_PATH}/tmp/DIAG_COREX
	@echo "See file tmp/DIAG_COREX for screen output"
	@echo ""

# Make Sample Core Programs
demo:	corelib corex
	@echo "Build Sample Programs..."
	-${MAKE} -C progs 2>&1 | tee ${CORE_PATH}/tmp/DIAG_BUILD_DEMO
	@echo "See file tmp/DIAG_BUILD_DEMO for screen output"
	@echo ""

# Run Test on Sample Core Programs
fifth test:
	@echo "Testing Sample Programs..."
	-${MAKE} -C progs test 2>&1 | tee ${CORE_PATH}/tmp/DIAG_TEST_DEMO
	@echo "See file tmp/DIAG_TEST_DEMO for screen output"
	@echo ""

# Basic Timing: just time all the tests 
sixth time:
	@echo "Timing Sample Programs..."
	-time ${MAKE} test 2>&1 | tee ${CORE_PATH}/tmp/DIAG_TIME
	@echo "See file tmp/DIAG_TIME for screen output"
	@echo ""


# Run More Test on Sample Core Programs
seventh moretest:
	@echo "More Testing of Sample Programs..."
	-${MAKE} -C progs moretest 2>&1 | tee ${CORE_PATH}/tmp/DIAG_MORETEST_DEMO
	@echo "See file tmp/DIAG_MORETEST_DEMO for screen output"
	@echo ""



#################################################################
#	Check Options
#################################################################

opt options check:
	@echo "YOUR CURRENT CORE ENVIRONMENT VARIABLES ARE: "
	@echo "  PLATFORM:	" ${PLATFORM}
	@echo "  LINKAGE:	" ${LINKAGE}
	@echo "  VAR(iant):	" ${VAR}
	@echo "  GMP_PREFIX:	" ${GMP_PREFIX}
	@echo "  PACKAGE:	" ${PACKAGE}
	@echo "  VERSION:	" ${VERSION}
	@echo "  CORE_PATH:	" ${CORE_PATH}
	@echo "  AR(chiver):	" ${AR}
	@echo "  CC(compiler):	" ${CC}
	@echo "  CXX(compiler): " ${CXX}
	@echo "  CXXFLAGS:	" ${CXXFLAGS}
	@echo "  CORE_CXXFLAGS	" ${CORE_CXXFLAGS}
	@echo "  LDFLAGS:	" ${LDFLAGS}
	@echo "  CORE_LDFLAGS:	" ${CORE_LDFLAGS}
	@echo "  EXETYPE:	" ${EXETYPE}
	@echo "  OS:		" ${OS}

allopt alloptions:
	@echo "YOUR CURRENT CORE ENVIRONMENT VARIABLES ARE: "
	@echo "    (possible alternatives are listed in parenthesis)"
	@echo ""
	@echo "  PLATFORM:	" ${PLATFORM} "		(cyg,gnu,sun,mingw,sgi)"
	@echo "  LINKAGE:	" ${LINKAGE}  "	(static,shared)"
	@echo "  VAR(iant):	" ${VAR}      "		(\"\",Debug,NoOpt)"
	@echo "  GMP_PREFIX:	" ${GMP_PREFIX} "		(..your choice..)"
	@echo "  PACKAGE:	" ${PACKAGE} 
	@echo "  VERSION:	" ${VERSION}
	@echo "  CORE_PATH:	" ${CORE_PATH}
	@echo "  AR(chiver):	" ${AR}
	@echo "  CC(compiler):	" ${CC}
	@echo "  CXX(compiler): " ${CXX}
	@echo "  CXXFLAGS:	" ${CXXFLAGS}  "	(..compiler flags..)"
	@echo "  CORE_CXXFLAGS	" ${CORE_CXXFLAGS}
	@echo "  LDFLAGS:	" ${LDFLAGS}   "		(..load flags..)"
	@echo "  CORE_LDFLAGS:	" ${CORE_LDFLAGS}
	@echo "  EXETYPE:	" ${EXETYPE}   "		(\"\",.exe)"
	@echo "  OS:		" ${OS}        "	(automatic)"

#################################################################
#	Cleaning Up files 
#################################################################

# clean_garbage: Remove all temp files
#
clean_garbage:
	find . -name "*.exe.stackdump" -print | xargs -i \rm -rf {}
	find . -name ii_files -print | xargs -i \rm -rf {}
	find . -name SunWS_cache -print | xargs -i \rm -rf {}
	find . -name "*\~" -print | xargs -i \rm -f {}
	find . -name "typescript" -print | xargs -i \rm -f {}

# clean: Remove object files
# This is used if you want to compile a different version of the
#	Core Library (but on the same platform)
#
clean:
	@list='$(SUB_DIRS)'; for dir in $$list; do \
	  if test -d "$$dir"; then ${MAKE} -C "$$dir" clean; fi; \
	done

# cleangmp: Clean the gmp directory only
# NOTE: to recover from this step, you need to do "make second" to
#	recompile gmp.  This is not cheap.
#
cleangmp:
	-@${MAKE} -C ${gmp} clean

# veryclean: Remove executables as well as object files.
# This is done when you need to rebuild everything (e.g., you need 
#	to recompile the library for a new platform)
# "veryclean" subsumes "clean" (although this is somewhat implicit)
#	but does not subsume "cleangmp" (which is expensive!)
# NOTE: after this step, you need to rebuild the Core Library from
#	step "make third" and subsequent.
#
veryclean:  
	@list='$(SUB_DIRS)'; for dir in $$list; do \
	  if test -d "$$dir"; then ${MAKE} -C "$$dir" veryclean; fi; \
	done
	-@test -z "${CORE_PATH}/tmp/DIAG_*" || rm -f ${CORE_PATH}/tmp/DIAG_*

# superclean: clean everything
#
superclean: veryclean cleangmp
	-@rm -rf ${CORE_PATH}/gmp

		
#################################################################
#	Making Core Distributions
#################################################################
# commit all current changes to CVS
cvs commit:
	cvs commit

# Make CVS-based distributions (base distribution and full distribution)
base:
	(cd ..; cvs -d ${CVSROOT} co corelib; \
	 tar cFFvf - corelib | \
	 	gzip -9 > ${PACKAGE}_v${VERSION}.tgz )

# Make CVS-based incremental distributions (gmp distribution and doc distribution)
full:
	(cd ..; cvs -d ${CVSROOT} co corelib; \
	 cp ${gmp}.tar.gz corelib; \
	 tar cFFvf - corelib | \
	 	gzip -9 > ${PACKAGE}_v${VERSION}.full.tgz )


#################################################################
# END OF CORE Makefile
#################################################################
