######################################################################
# Genpak package Makefile
# Genpak (C) 2000 January Weiner III
# Read the files LICENSE.TXT and README.TXT
######################################################################
# Change the following to suit your needs

# The directory root of your installation
# If you make a personal installation, change it to your home directory
# Default: /usr
# uncomment the following line to install to the default directories...
TREE=${PREFIX}
# ...or the following line to install into your home directory:
# TREE=$(HOME)

# if you don't have the gd graphic library installed, you have to comment out or
# delete the following line. However, gp_map is such a nice program, so you
# better go to www.boutell.com and download the gd library.
GDPROGRAMS=gp_map

# Directory to install the programs themselves. 
# Default: /usr/local/bin
BINDIR=$(TREE)/bin

# directory to install the manual pages
MANDIR=${MANPREFIX}/man

#directory to install the data directory
DATADIR=$(TREE)/lib

# documentation. 
# If you want to install documents automagically, type:
# make docs
# A catalog will be created: $(DOCDIR)/gp
# It will *not* be uninstalled automagically after a "make uninstall"

DOCDIR=${PREFIX}/share/doc

# Your favourite ANSI compiler and it's flags

######################################################################
# Do not change anything below this line
######################################################################

DEFS=-DDATADIR='"$(DATADIR)/genpak/"'

LIBS=$(LIBOPT) -lm

MANUALS=Genpak.1 gp_acc.1 gp_cusage.1 gp_digest.1 gp_dimer.1 gp_findorf.1 gp_gc.1 gp_getseq.1 gp_matrix.1 gp_mkmtx.1 gp_pattern.1 gp_qs.1 gp_randseq.1 gp_seq2prot.1 gp_slen.1 gp_tm.1 gp_trimer.1 gp_primer.1 gp_adjust.1 gp_cdndev.1

PROGRAMS=gp_acc gp_cusage gp_digest gp_dimer gp_findorf gp_gc gp_getseq gp_matrix gp_mkmtx gp_pars gp_pattern gp_qs gp_randseq gp_scan gp_seq2prot gp_shift gp_slen gp_tm gp_trimer gp_primer gp_adjust gp_cdndev

DATAFILES=ecoli.mtx enzyme.enz myco.cdn sample.seq standard.cdn \
	mporfs.seq

all: 
	cd src ; ${GMAKE} PROGRAMS="$(PROGRAMS)" GDPROGRAMS="$(GDPROGRAMS)" CC=$(CC) \
		LIBS="$(LIBS)" CFLAGS="$(CFLAGS)" ; 
	@echo -e "\nAll programs compiled. \nType 'make install' to install all programs."

clean:
	-rm -f src/core src/*.o core $(PROGRAMS)
	-cd src/ ; rm $(PROGRAMS) core

install: all 
	@if [ ! -O "$(BINDIR)" ] ; then \
	echo "File $(BINDIR) doesn't belong to you!" ;  exit 1 ; fi 
	@cd src ; cp $(PROGRAMS) $(BINDIR)

	@if [ ! -O "$(MANDIR)" ] ; then \
	echo "File $(MANDIR) doesn't belong to you!" ;  exit 1 ; fi 
	@cd man1 ; cp $(MANUALS) $(MANDIR)/man1

	@if [ ! -O "$(DATADIR)" ] ; then \
	echo "File $(DATADIR) doesn't belong to you!" ;  exit 1 ; fi 
	-cd $(DATADIR) ; mkdir genpak ; 
	@cd data ; cp -i $(DATAFILES) $(DATADIR)/genpak

	@echo
	@echo Installation is now complete. Type 
	@echo make docs
	@echo to install documentation in $(DOCDIR). Type
	@echo make uninstall
	@echo to uninstall this software package. Please read the files README.TXT
	@echo and LICENSE.TXT. In case of any problems / bugs / suggestions don\'t
	@echo hesitate to mail january@bioinformatics.org. 
	@echo

filelist:
	@echo Creating file list FILES.TXT
	@for i in $(PROGRAMS) ; do echo "$(BINDIR)/"$$i >> FILES.TXT ; done
	@for i in $(MANUALS) ; do \
		echo "$(MANDIR)/man1/"$$i >> FILES.TXT ; done
	@for i in $(DATAFILES) ; do \
		echo "$(DATADIR)/genpak/"$$i >> FILES.TXT ; done

docs:
	@if [ ! -O "$(TREE)" ] ; \
	then echo "File $(TREE) doesn't belong to you!" ; exit 1 ; fi ; \
	if [ ! -e $(DOCDIR) ] ; \
		then mkdir $(DOCDIR) ; fi ; \
	if [ ! -e $(DOCDIR)/gp ] ; then \
		mkdir $(DOCDIR)/gp ; fi ; \
	cp -r html README.TXT LICENSE.TXT CHANGES.TXT Makefile INSTALL.TXT  \
		$(DOCDIR)/gp ;

uninstall:

	@if [ ! -O "$(BINDIR)" ] ; \
		then echo "Directory $(BINDIR) doesn't belong to you!" ; \
		exit 1 ; fi
	@echo Removing programs...
	@cd $(BINDIR) ; rm -f $(PROGRAMS)

	@if [ ! -O "$(MANDIR)" ] ; \
		then echo "Directory $(MANDIR) doesn't belong to you!" ;  \
		exit 1 ; fi
	
	@echo Removing manuals...
	@cd $(MANDIR)/man1 ; rm -f $(MANUALS) 
	
	@echo Removing previously installed data in directory $(DATADIR)/genpak.
	@echo Are you sure you really want to remove this data? '(yes/no) '
	@read ANSWER ; if [ $ANSWER != "yes" ] ; then \
		echo OK, leaving $(DATADIR)/genpak untouched ; else \
	if [ ! -O "$(DATADIR)" ] ; \
		then echo "Directory $(DATADIR) doesn\'t belong to you!" ; \
	exit 1 ; fi ; \
	cd $(DATADIR)/genpak ; rm -f $(DATAFILES) ; fi
	-cd $(DATADIR) ; rmdir genpak
	@echo
	@echo ---------------------------------------------------------------------
	@echo I\'m sorry you didn\'t like me. Please send an e-mail to 
	@echo january@bioinformatics.org and tell him why, OK? Maybe the next 
	@echo release will suit you more. Cheers!
	@echo ---------------------------------------------------------------------
	@echo
	
