# ================================================================
# The top level makefile.
# ================================================================
PERL = perl

# ================================================================
# Help
# ================================================================
help:
	@echo ""
	@echo "CCDOC Makefile Help"
	@echo ""
	@echo "Available targets:"
	@echo ""
	@echo "    all      Build the program and run the tests."
	@echo ""
	@echo "    backup   Backup the source to a taz file."
	@echo ""
	@echo "    bld      Build the program only."
	@echo ""
	@echo "    clean    Clean up for a specific architecture."
	@echo ""
	@echo "    cleanall Clean up for all architectures."
	@echo ""
	@echo "    depend   Generate the include dependencies."
	@echo "             in mkdepend.mk which is included by"
	@echo "             mktargs.mk."
	@echo ""
	@echo "    doc      Generate the ccdoc documentation."
	@echo ""
	@echo "    help     Help message."
	@echo ""
	@echo "    insert   Insert the help and copyright info into"
	@echo "             the source code."
	@echo ""
	@echo "    insert_help"
	@echo "             Insert the help info into the source code."
	@echo "             from help.txt."
	@echo ""
	@echo "    insert_copyright"
	@echo "             Insert the copyright and license info into the" 
	@echo "             source code from copyright.txt."
	@echo ""
	@echo "    release"
	@echo "    rel      Create the release in ../release directory"
	@echo "             and create the tar ball ../release/tarball.taz."
	@echo ""
	@echo "    release_info"
	@echo "    relinfo  Update the release information in the"
	@echo "             source files."
	@echo ""
	@echo "    test     Test the program (build if necessary)."
	@echo ""
	@echo "Available makefile files:"
	@echo ""
	@echo "    mkdbg_gcc.mk     Debug, GNU g++ compiler."
	@echo "    mkopt_gcc.mk     Optimized, GNU g++ compiler."
	@echo "    mkdbg_msvc.mk    Debug, MS Visual C++ compiler."
	@echo "    mkopt_msvc.mk    Optimized, MS Visual C++ compiler."
	@echo "    mkdbg_sun.mk     Debug, Solaris CC compiler."
	@echo "    mkopt_sun.mk     Optimized, Solaris CC compiler."
	@echo ""
	@echo "Sample usages:"
	@echo ""
	@echo "    % make -f mkopt_gcc.mk all"
	@echo "    % make -f mkopt_gcc.mk test"
	@echo "    % make -f mkopt_gcc.mk doc"
	@echo ""
	@echo "Notes:"
	@echo ""
	@echo "    To make a purify or quantify version of the program,"
	@echo "    set the LINK_PREFIX to the appropriate value as shown"
	@echo "    in the example below:"
	@echo ""
	@echo "        % setenv LINK_PREFIX purify"
	@echo "        % make -f mkdbg_sun.mk all"
	@echo ""
	@echo "    The Makefile file handles the vanilla targets. The"
	@echo "    mkdepend.mk file has the dependencies. The mktargs.mk"
	@echo "    file contains the complex targets."
	@echo ""
	@echo "    The other mk<dbg>_* and mk<opt>_* files define the"
	@echo "    personality of the compiler and the linker. They also"
	@echo "    where output (binary) directory."
	@echo ""

# ================================================================
# All
# ================================================================
all:
	@echo ""
	@echo "WARNING: You did not specify a personality so make"
	@echo "         does not know which compiler to use. Try"
	@echo "         something like this:"
	@echo ""
	@echo "         % make -f mkopt_gcc $@"
	@echo ""
	@echo "         To get more information about how to use"
	@echo "         this make system type:"
	@echo ""
	@echo "         % make help"
	@echo ""

# ================================================================
# Bld
# ================================================================
bld:
	@echo ""
	@echo "WARNING: You did not specify a personality so make"
	@echo "         does not know which compiler to use. Try"
	@echo "         something like this:"
	@echo ""
	@echo "         % make -f mkopt_gcc $@"
	@echo ""
	@echo "         To get more information about how to use"
	@echo "         this make system type:"
	@echo ""
	@echo "         % make help"
	@echo ""

# ================================================================
# Backup
# ================================================================
backup:
	@rm -f *~ *.pdb ../*/*~
	@rm -f ../backup*
	@cd .. ; tar cf backup.tar doc src test utils
	@cd .. ; gzip --best -c backup.tar > backup.taz
	@rm -f ../backup.tar
	@ls -l ../backup.taz

# ================================================================
# Clean up
# ================================================================
clean:
	@echo ""
	@echo "WARNING: The clean target must be run with a -f mk... file."
	@echo ""

# ================================================================
# Clean up everything
# ================================================================
cleanall:
	@echo ""
	@echo "WARNING: The cleanall target must be run with a -f mk... file."
	@echo ""

# ================================================================
# Doc
# ================================================================
doc:
	@echo ""
	@echo "WARNING: You did not specify a personality so make"
	@echo "         does not know which compiler to use. Try"
	@echo "         something like this:"
	@echo ""
	@echo "         % make -f mkopt_gcc $@"
	@echo ""
	@echo "         To get more information about how to use"
	@echo "         this make system type:"
	@echo ""
	@echo "         % make help"
	@echo ""

# ================================================================
# Dependencies
# ================================================================
depend:
	${PERL} ../utils/makedepend.pl *.cc > mkdepend.mk

# ================================================================
# Insert the copyrights and help text into the source code.
# ================================================================
insert: insert_help insert_copyright

# ================================================================
# Insert the help text into the system. It is organized this
# way so that the help text is easy to modify and export.
# ================================================================
insert_help: ../utils/insert.pl help.txt help.cc
	@echo "================================================"
	@echo "Inserting help text."
	${PERL} ../utils/insert.pl -s -i help.txt -b @help_begin -e @help_end help.cc
	${PERL} ../utils/fix_help.pl
	${PERL} ../utils/make_help_html.pl

# ================================================================
# Insert the copyright text into the system. It is organized this
# way so that the copyright text is easy to modify and export.
# ================================================================
insert_copyright: ../utils/insert.pl copyright.txt
	@echo "================================================"
	@echo "Inserting copyright text."
	${PERL} ../utils/insert.pl -c -i copyright.txt -b @copyright_begin -e @copyright_end *.cc *.h

# ================================================================
# Test
# ================================================================
test:
	@echo ""
	@echo "WARNING: You did not specify a personality so make"
	@echo "         does not know which compiler to use. Try"
	@echo "         something like this:"
	@echo ""
	@echo "         % make -f mkopt_gcc $@"
	@echo ""
	@echo "         To get more information about how to use"
	@echo "         this make system type:"
	@echo ""
	@echo "         % make help"
	@echo ""

# ================================================================
# Release
# ================================================================
rel:  release

release : ../utils/makerelease.pl
	@${PERL} ../utils/makerelease.pl 

relinfo : release_info

release_info : ../utils/set_release_info.pl
	@${PERL} ../utils/set_release_info.pl 
