
#################################################################
# CMfinder
# top level Makefile: installation, documentation
#################################################################
#    This copyrighted source code is freely distributed 
#    under the terms of the GNU General Public License. See
#    the files COPYRIGHT and LICENSE for details.
#################################################################

# On most Unices, you can build the package without modifying anything 
#   by just typing "./configure; make".
#
# You may want to modify the following make variables:
#   BINDIR  - where the executables will be installed by a 'make install'
#   MANDIR  - where the man pages will be installed by a 'make install'
#   CC      - which compiler to use
#   CFLAGS  - compiler flags to use
# where you want things installed
# Sort of uses GNU coding standards. ${prefix} might be /usr/local.
# ${exec_prefix} gives you some flexibility for installing architecture
# dependent files (e.g. the programs): an example ${exec_prefix} might be
# /nfs/share/irix64/
#
prefix      = ~/tool/
exec_prefix = ${prefix}
BINDIR      = ${exec_prefix}/bin
MANDIR      = ${prefix}/man

# how to install the man pages; 
# cp is generally fine, unless you preformat your pages.
#
INSTMAN   = cp
MANSUFFIX = 1

# your compiler and compiler flags
#
CC     = gcc
CFLAGS = -g -O2
#CFLAGS = -g -DDEBUG

#######
## You should not need to modify below this line.
## Some of it is concerned with maintenance of the development version
## and building the release (indeed, several commands will only work in 
## St. Louis)
#######
SHELL       = /bin/sh
BASENAME    = "CMfinder"
PACKAGE     = "CMfinder"
RELEASE     = "0.2.2"
RELCODE     = "CMfinder_0.2.2"
RELEASEDATE = "Oct 2010"
COPYRIGHT   = "Copyright \(C\) 2006 University of Washington, Seattle"
LICENSELINE = "Freely distributed under the GNU General Public License \(GPL\)"
LICENSETAG  = gnu
COMPRESS    = gzip


# all: if we don't have precompiled binaries, compiles all packages, 
#      and moves the supported executables into binaries/ subdirectory.
#
all: version.h
	(cd squid; make CC="$(CC)" CFLAGS="$(CFLAGS)"; make module);\
	(cd easel; make CC="$(CC)" CFLAGS="$(CFLAGS)"; make module);\
	(cd infernal; make CC="$(CC)" CFLAGS="$(CFLAGS)"; make module);\
	(cd vienna; make CC="$(CC)" CFLAGS="$(CFLAGS)"; make module);\
	(cd cmfinder;   make CC="$(CC)" CFLAGS="$(CFLAGS)" install);
	(cd pscore/squid;   make CC="$(CC)" CFLAGS="$(CFLAGS)"; make module);\
	(cd pscore/easel;   make CC="$(CC)" CFLAGS="$(CFLAGS)"; make module);\
	(cd pscore/infernal;   make CC="$(CC)" CFLAGS="$(CFLAGS)"; make module);\
	(cd pscore/vienna;   make CC="$(CC)" CFLAGS="$(CFLAGS)"; make module);\
	(cd pscore/cmfinder;   make CC="$(CC)" CFLAGS="$(CFLAGS)" install);\
	(cd pscore;   make CC="$(CC)" CFLAGS="$(CFLAGS)" install);\

version.h:
	@echo "Creating version.h..."
	@echo "/* version.h -- automatically generated by a Makefile. DO NOT EDIT. */" > version.h
	@echo "#define PACKAGE     \"$(PACKAGE)\""     >> version.h
	@echo "#define RELEASE     \"$(RELEASE)\""     >> version.h
	@echo "#define RELEASEDATE \"$(RELEASEDATE)\"" >> version.h
	@echo "#define COPYRIGHT   \"$(COPYRIGHT)\""   >> version.h
	@echo "#define LICENSE     \"$(LICENSELINE)\"" >> version.h
	@mv version.h cmfinder/

# dist: build a new distribution directory 
# Not finished
dist:
	# Delete old versions of the same release
	#
	@if test -d ${BASENAME}-$(RELEASE);        then rm -rf ${BASENAME}-$(RELEASE);        fi
	@if test -e ${BASENAME}-$(RELEASE).tar;    then rm -f  ${BASENAME}-$(RELEASE).tar;    fi
	@if test -e ${BASENAME}-$(RELEASE).tar.Z;  then rm -f  ${BASENAME}-$(RELEASE).tar.Z;  fi
	@if test -e ${BASENAME}-$(RELEASE).tar.gz; then rm -f  ${BASENAME}-$(RELEASE).tar.gz; fi
	# 
	# CVS tag and extract. -c: make sure we committed;
	#                      -F: allow more than one "make dist" per rel
	# prep: must have done "cvs commit", and CVSROOT must be set
	# We also need the squid library, so tag and export it too.
	#
	cvs tag -F $(RELCODE)
	cvs export -r $(RELCODE) -d ${BASENAME}-${RELEASE} ${BASENAME}
	cvs rtag -F ${RELCODE} squid
	(cd ${BASENAME}-${RELEASE}/; cvs export -r ${RELCODE} -d squid squid)
	# 
	# We won't include the ssdk, but we need it temporarily,
	# for rmanprocess.pl (when making the user guide); we also 
	# need to put a copy of sqc in testsuite. 
	#
	cp ssdk/sqc ${BASENAME}-${RELEASE}/testsuite/
	mkdir ${BASENAME}-${RELEASE}/ssdk
	cp ssdk/rmanprocess.pl ${BASENAME}-${RELEASE}/ssdk/
	# 
	# Make the configure scripts from configure.in's
	#
	(cd ${BASENAME}-${RELEASE};       autoconf)
	(cd ${BASENAME}-${RELEASE}/squid; autoconf)
	#
	# We'll need a basic squid Makefile for some steps; later
	# we'll delete it.
	#
	(cd ${BASENAME}-${RELEASE}/squid; ./configure)
	#
	# Attach license stamps on all files that need 'em
	# (e.g. replace LICENSE keyword everywhere)
	#
	find ${BASENAME}-${RELEASE} -type f -exec ssdk/sedition-pp LICENSE Licenses/$(LICENSETAG) {} \;
	# 
	# All other keyword replacements are in the documentation.
	#
	find ${BASENAME}-${RELEASE}/documentation -type f -exec ssdk/sedition RELEASE ${RELEASE} RELEASEDATE ${RELEASEDATE} PACKAGE ${PACKAGE} COPYRIGHT ${COPYRIGHT} LICENSELINE ${LICENSELINE} {} \;
	#
	# Make the User's Guide, and copy to top level. (We'll
	# destroy the userguide source soon.)
	#
	(cd ${BASENAME}-${RELEASE}/documentation/userguide; make pdf)
	cp ${BASENAME}-${RELEASE}/documentation/userguide/main.pdf  ${BASENAME}-${RELEASE}/Userguide.pdf
	# 
	# Finish the man pages off, adding necessary boilerplate.
	# Must be done *after* the user guide is created, since the user guide
	# steals and uses the pre-boilerplate man pages.
	#
	for prog in $(PROGS); do\
	   cat ${BASENAME}-${RELEASE}/documentation/manpages/boilerplate.trailer >> ${BASENAME}-${RELEASE}/documentation/manpages/$$prog.man;\
	done
	-rm -f ${BASENAME}-${RELEASE}/documentation/manpages/boilerplate.trailer
	#
	# Remove CVS-controlled files/directories that don't belong in the
	# distro
	#
	-rm -rf ${BASENAME}-${RELEASE}/Licenses
	-rm -rf ${BASENAME}-${RELEASE}/00CHECKLIST
	-rm -rf ${BASENAME}-${RELEASE}/configure.in
	-rm -rf ${BASENAME}-${RELEASE}/Bugs
	-rm -rf ${BASENAME}-${RELEASE}/Manuscripts
	-rm -rf ${BASENAME}-${RELEASE}/ssdk
	-rm -rf ${BASENAME}-${RELEASE}/documentation/userguide
	(cd ${BASENAME}-${RELEASE}/squid; make implode; make distclean)
	#
	# Set file permissions.
	#
	find ${BASENAME}-${RELEASE} -type f -exec chmod +r {} \;
	chmod +x ${BASENAME}-${RELEASE}/testsuite/sqc
	#
	# Packaging commands
	#
	tar cvf ${BASENAME}-${RELEASE}.tar ${BASENAME}-${RELEASE}
	$(COMPRESS) ${BASENAME}-$(RELEASE).tar

# "make ftpdist" installs a new tarball on the FTP site.
# Not finished
#
ftpdist:
	cp -f ${BASENAME}-$(RELEASE).tar.gz ${FTPDIR}/
	rm -f ${FTPDIR}/${BASENAME}.tar.gz 
	(cd ${FTPDIR}; ln -s ${BASENAME}-${RELEASE}.tar.gz ${BASENAME}.tar.gz)




# "make clean" removes almost everything except configuration files
#              and binaries.
clean:
	-rm -f *.o *~ Makefile.bak core TAGS gmon.out
	(cd cmfinder;       make clean)
	(cd infernal;  make clean)
	(cd vienna;  make clean)	
	(cd squid;  make clean)	
	(cd easel;  make clean)	
	(cd pscore;  make clean)	
	(cd pscore/cmfinder;  make clean)	
	(cd pscore/easel;  make clean)	
	(cd pscore/vienna;  make clean)	
	(cd pscore/infernal;  make clean)	
	(cd pscore/squid;  make clean)	

