##
#	version: $Id: Makefile,v 5.47 1994/10/05 00:59:22 hitman Exp $ 
#	updates: All updates are handled by RCS 
# 	Author: The Hitman 1994	
#

# System Dependent configurations and Installation information
include sys_config

## Development -----------------------------------------
UPDAT_OPT = $(DEFINES) -E -M
# RCS Related items ------------------------------------
COFLAGS = -q

## Other Information -----------------------------------
PROG = bbs_script
VERSION = version.h
PROGS = bbs_script menu_edit

OBJS_MENU_EDIT = \
	menu_edit.o \
	dis_version.o \
	menu_data_filename.o \
	menu_text_filename.o

OBJS_BBS_SCRIPT = \
	bbs_script.o \
	dis_version.o \
	check_speed.o \
	set_up_env.o \
	is_bbs_running.o \
	dis_screen.o \
	pause.o \
	menu_data_filename.o \
	header_filename.o \
	header_rnd_filename.o \
	help_filename.o \
	dis_filename.o \
	my_random.o

OBJS_READ_MENU = \
	read_menu_main.o \
	menu_data_filename.o


HEADER = \
	bbs_director.h \
	menu_info.h \
	$(VERSION)

all: $(VERSION) depends $(PROGS)

#--------------------------------------
bbs_script: $(VERSION) $(OBJS_BBS_SCRIPT)
	$(CC) $(FIN_OPT) $(OBJS_BBS_SCRIPT) $(LIB) -o bbs_script

#--------------------------------------
menu_edit: $(VERSION) $(OBJS_MENU_EDIT)
	$(CC) $(FIN_OPT) $(OBJS_MENU_EDIT) $(LIB) -o menu_edit

#--------------------------------------
read_menu: $(VERSION) $(OBJS_READ_MENU)
	$(CC) $(FIN_OPT) $(OBJS_READ_MENU) $(LIB) -o read_menu

help: help/help.txt help/lockout.txt
	@echo "Making help screen..."
	@groff help/help.txt > screen/help.screen
	@echo "Making lockout screen..."
	@groff help/lockout.txt > screen/lockout.screen
	@head -15 screen/lockout.screen > temp ; mv temp  screen/lockout.screen

#--------------------------------------
#	Version information
#		This gets compiled into your programs.  This is some what
#		system dependend, but basic commands are used.
#
$(VERSION): ver
	@echo "Updating $(VERSION)..."
	@echo "/* DO NOT EDIT, USE: make $(VERSION) */" > $(VERSION) 
	@echo "/* file: version.h */" >> $(VERSION)
	@echo "/* purpose: inform user of version */" >> $(VERSION)
	@echo "#define CCVER		\"`$(CCVER)`\"" >> $(VERSION) 
	@echo "#define PROGRAM		\"$(PROG)\"" >> $(VERSION)
	@echo "#define OSVER		\"`uname -sr`\"" >> $(VERSION)
	@echo "#define COPYRIGHT	\"1993-94 GNU General Software License\"" >> $(VERSION)
	@echo "#define VER			\"`cat ver`, b$(BASELINE)\"" >> $(VERSION) 
	@echo "#define COMPBY		\"`whoami`\"" >> $(VERSION)
	@echo "/* End-Of-$(VERSION) */" >> $(VERSION)

# Install the program and go from there.
install: install_database $(PROGS)
	@if [ -d $(DIR) ]; then \
		echo "$(DIR): Exists..." ; \
	else \
		echo "$(DIR): Making..." ; \
		mkdir -p $(DIR) ; \
	fi
	@for DIRECT in `awk -F: '{ print $$1 }' install_database` ; \
	do \
		if [ -d $(DIR)/$$DIRECT ]; then \
			echo -n "$(DIR)/$$DIRECT: Exists..." ; \
		else \
			echo -n "$(DIR)/$$DIRECT: Making..." ; \
			mkdir $(DIR)/$$DIRECT ; \
		fi ; \
		echo "Updating Data Files..." ; \
		sh -c " cd $$DIRECT ; \
		cp -Rf `grep $$DIRECT install_database | awk -F: '{ print $$2 }'` \
			$(DIR)/$$DIRECT/ " ; \
	done
	@echo -n "Coping the Programs..."
	@for FILE in `ls $(PROGS) *.dat` ; \
	do \
		if [ -f $$FILE ]; then \
				if [ -f $(DIR)/$$FILE ]; then \
					echo -n "(replaced) " ; \
					rm -f $(DIR)/$$FILE ; \
					cp -f $$FILE $(DIR)/ ; \
				else \
					echo -n "(new) " ; \
					cp -f $$FILE $(DIR)/ ; \
				fi ; \
			echo -n "$$FILE, " ; \
		fi ; \
	done
	@echo "...DONE!"
	@echo "Setting Up Permissions..."
	@sh -c "cd $(DIR) ; \
		chmod 444 *.dat ; \
		chmod 555 $(PROGS) ; \
		chmod 555 utils/*"
	@echo "Install Complete -------------------"

clean:
	@rm -rf *.o core *.out $(PROGS) *.*~ version.h

#--------------------------------------
#       Updates the end of this makefile, user still has to clean out the
#               older version of the update.
#
depends: $(HEADER)
	@echo "Updateing the dependents..."
	@rm -rf .depends
	@for FILE in `ls RCS/*.c* | awk -F, '{print $$1}' | awk -F/ '{print $$2}'` ; \
	do \
		if test -f $$FILE ; \
		then \
			$(CC) $(UPDAT_OPT) $$FILE >> .depends ; \
		else \
			co $$FILE ; \
			$(CC) $(UPDAT_OPT) $$FILE >> .depends ; \
			rm $$FILE ; \
		fi ; \
	done

#--------End of Documentation----------
include .depends
