#
# SOLARIS BUGS Makefile 2.0
# 16/09/2003
#
VERSION = `cat .VERSION`
DATE = `cat .DATE`

# Change these value 
INSTALL_PATH = "/opt/bugs-$(VERSION)"

# YOU MUST CHOOSE YOUR COMPILER
# default = cc

# Linux, hpux, etc
#export CC=gcc

# Sunos, Silicon Graphics, etc
#export CC=cc

trap: version 
	@echo Solaris and compatible OS
	@echo
	@echo ---------------------------------------
	@echo Please read README before running make.
	@echo ---------------------------------------
	@echo
	@echo make options are :
	@echo
	@echo all       : compile everything library and apps
	@echo test      : Try to uncrypt the test file, do make all before
	@echo lib       : compile only the BUGS crypt library
	@echo apps      : compile only application programs
	@echo shell	: if you use blogin like as shell
	@echo install   : install apps and library in a path
	@echo uninstall : uninstall apps and library
	@echo "clean     : erase *.o *.h and executable files"
	@echo
	@echo -----------------------------------------------------
	@echo IMPORTANT: If you use blogin as your logon shell, YOU 
	@echo MUST do a \'make shell\'. This is because you can\'t
	@echo compile a file while you are using it...
	@echo ------------------------------------------------------

all: lib apps

apps : appschoice 
	@cd apps/; make
	@echo "Copying binary file in ./bin ..."
	@mv apps/bcrypt ./bin
	@mv apps/bchat ./bin
	@mv apps/bpass ./bin
	@mv apps/blogin ./bin
	@mv apps/bkey ./bin
	@mv apps/bhide ./bin
	@mv apps/bpassdel ./bin
	@mv apps/bmore ./bin
	@mv apps/block ./bin
	@mv apps/bunlock ./bin

test : testchoice
	@./testbcrypt.sh

testfpost : testfpostchoice
	@./testfpos_t.sh

shell : shellchoice
	@cd apps/; make shell
	@mv apps/shell ./bin/blogin

lib:	testfpost libchoice
	@cd lib/unix; make 

install: instchoice all
	@echo "Creating directory $(INSTALL_PATH) ..."
	@mkdir $(INSTALL_PATH) 
	@echo "Copying binaries in $(INSTALL_PATH) ..."
	@cp -f ./bin/* $(INSTALL_PATH)/
	@echo "Copying bugscrypt.a in $(INSTALL_PATH) ..."
	@cp -f ./lib/bugscrypt.a $(INSTALL_PATH)/
	@echo "Copying docs in $(INSTALL_PATH) ..."
	@cp -rf ./doc/* $(INSTALL_PATH)/
	@echo
	@echo ------------------------------------------------------------
	@echo
	@echo "YOU MUST NOW ADD $(INSTALL_PATH) to your PATH : "
	@echo "PATH = PATH:$(INSTALL_PATH)"
	@echo
	@echo "Congratualations! The applications and library have been"
	@echo "successfully installed"
	@echo
	@echo Please note that you are using these applications and
	@echo library at your own risk. Therefore I discharge any
	@echo responsibility if you loose any data or illigaly use this.
	@echo package.
	@echo
	@echo "Now, I hope you will enjoy those applications as much as"
	@echo "I have enjoyed programming them."
	@echo "Sylvain Martinez."
	@echo

uninstall: uninstchoice
	@echo Removing directory $(INSTALL_PATH) ...
	@rm -rf $(INSTALL_PATH)
	@echo
	@echo --------------------------------------------------
	@echo
	@echo BUGS V$(VERSION) HAS BEEN SUCCESSFULLY UNINSTALLED.
	@echo
		
clean: cleanchoice
	@cd lib/unix; make clean; rm Makefile
	@cd apps/; make clean; rm Makefile
	@cp Makefile.orig Makefile

	rm -f ./bin/bcrypt
	rm -f ./bin/bchat
	rm -f ./bin/bpass
	rm -f ./bin/blogin
	rm -f ./bin/bkey
	rm -f ./bin/bhide
	rm -f ./bin/bpassdel
	rm -f ./bin/bmore
	rm -f ./bin/block
	rm -f ./bin/bunlock

appschoice:
	@echo apps flag detected. 
	@echo
	@echo "-------------------"
	@echo "MAKING APPLICATIONS" 
	@echo "-------------------"
	@echo

testchoice:
	@echo test flag detected.
	@echo
	@echo "-------------------------"
	@echo "TESTING BCRYPT ENCRYPTION"
	@echo "-------------------------"
	@echo
	@echo "This is going to test if you can decrypt a standard BUGS file"
	@echo

testfpostchoice:
	@echo test fpos_t flag detected
	@echo
	@echo "-------------------"
	@echo "TESTING FPOS_T TYPE"
	@echo "-------------------"
	@echo

shellchoice:
	@echo shell flag detected.
	@echo
	@echo "------------"
	@echo "MAKING SHELL"
	@echo "------------"
	@echo

libchoice:
	@echo lib flag detected.
	@echo
	@echo "--------------"
	@echo "MAKING LIBRARY"
	@echo "--------------"
	@echo

instchoice:
	@echo install flag detected.
	@echo
	@echo "----------------------"
	@echo "INSTALLATION INITIATED"
	@echo "----------------------"
	@echo
	@echo "you MUST be root to execute this command (use su)"
	@echo
	@echo REMEMBER TO CHANGE THE VALUE OF THE INSTALL PATH in the makefile
	@echo if you want to install this package in a specific place.
	@echo

uninstchoice:
	@echo uninstall flag detected.
	@echo 
	@echo "------------------------"
	@echo "UNINSTALLATION INITIATED"
	@echo "------------------------"
	@echo
	@echo "you MUST be root to execute this command (use su)"
	@echo

cleanchoice:
	@echo clean flag detected.
	@echo
	@echo "------------------"
	@echo "CLEANING INITIATED"
	@echo "------------------"
	@echo
	

version:
	@echo
	@echo "BUGS V$(VERSION), $(DATE),(c) MARTINEZ Sylvain" 
