#
# Makefile for cthugha-L
#
# usage:
#   make		create all the executables,
#                       documentation and translation tables
#   make src            create only the executables
#   make doc		create only the documentation (info and ps file)
#   make tab		create the tab-programs, and some
#			translation tables for 320x200.
#   make install	bring files to the right directories (run as root)
#   make uninstall	to delete the installed files
#   make clean		to remove junk
#   make dist-clean     delete everything generated (except INSTALL)
#
# You should not need to change anything in this file.
# Set your preferences in the file 'configure'.
#

ifeq (configure, $(wildcard configure))
	include configure
endif

all: .first_time src doc tab
	@echo
	@echo
	@echo It seems that everything worked fine.
	@echo You can now try out cthugha
	@echo

.PHONY: src
src: 
	$(MAKE) -C src

.PHONY: cthugha xcthugha cthugha-server
cthugha:
	$(MAKE) -C src ../cthugha
xcthugha:
	$(MAKE) -C src ../xcthugha
cthugha-server:
	$(MAKE) -C src ../cthugha-server


.PHONY: doc
doc: 
	$(MAKE) -C documentation

.first_time:
	touch .first_time
	@echo
	@echo "It seems we start right from the bottom."
	@echo "So it takes some times to compile everything - you can go now"
	@echo "and drink a cup of coffee..."
	@echo


#
# create the default translation files for some buffer-sizes
#
.PHONY: tab
tab: 
	$(MAKE) -C extra


#
# the distribution name
#
VERSION = 1.1a
DIST_NAME = cthugha-L-${VERSION}

#
# copy files to right places, ignore errors
#
.PHONY: install
install:
ifeq ($(USE_SVGA),1)
	-${INSTALL} -o root -m 4755 cthugha	${INST_BIN}
endif
ifeq ($(USE_XWIN),1)
	-${INSTALL} -o root -m 4755 xcthugha	${INST_BIN}
endif
ifeq ($(USE_SERVER),1)
	-${INSTALL} -m 0755 cthugha-server	${INST_BIN}
endif
ifeq ($(USE_NSPMOD),1)
	-${INSTALL} -m 0755 cth-nspmod		${INST_LIB}
endif
ifeq ($(USE_AMP),1)
	-${INSTALL} -m 0755 cth-amp		${INST_LIB}
endif
	-${INSTALL} -m 0755 tabheader		${INST_BIN}
	-${INSTALL} -m 0755 tabinfo		${INST_BIN}
	-${MAKE} -C documentation install
	-${MAKE} -C extra install

#
# remove files from installation places
#
.PHONY: uninstall
uninstall:
	-rm -rf  ${INST_LIB}/map/*.map*		\
		 ${INST_LIB}/pcx/*.pcx*		\
		 ${INST_LIB}/tab/*.tab*		\
		 ${INST_LIB}/tab/cmd_*		\
		 ${INST_LIB}/tab/*.cmd*		\
		 ${INST_LIB}/cth-amp		\
		 ${INST_LIB}/cth-nspmod		\
		 ${INST_BIN}/cthugha		\
		 ${INST_BIN}/xcthugha		\
		 ${INST_BIN}/cthugha-server	\
		 ${INST_BIN}/tabheader		\
		 ${INST_BIN}/tabinfo		\
		 ${INST_INFO}/cthugha.info	\
		 ${INST_MAN}/cthugha.1

#
# remove some junk
#
.PHONY: clean
clean:
	${MAKE} -C src clean
	${MAKE} -C documentation clean
	${MAKE} -C extra clean
	-rm -f *~ .first_time

.PHONY: dist-clean
dist-clean:
	${MAKE} -C src dist-clean
	${MAKE} -C documentation dist-clean
	${MAKE} -C extra dist-clean
	-rm -f cthugha xcthugha cthugha-server tabheader tabinfo	\
		.first_time  .emacs.desktop cth-amp cth-nspmod

#
# create archives for distribution
#
dist: sdistrib bdistrib edistrib

sdistrib:
	${MAKE} -C .. sdistrib_int -f ${shell pwd}/Makefile

bdistrib:
	${MAKE} -C .. bdistrib_int -f ${shell pwd}/Makefile

edistrib:
	${MAKE} -C .. edistrib_int -f ${shell pwd}/Makefile

sdistrib_int:
	${MAKE} -C ${DIST_NAME} dist-clean
	tar -czf ${DIST_NAME}.src.tgz				\
		${DIST_NAME}/[^e]*				\
		${DIST_NAME}/extra/*.c				\
		${DIST_NAME}/extra/mktab.sh			\
		${DIST_NAME}/extra/cthugha.ini*			\
		${DIST_NAME}/extra/Makefile			\
		${DIST_NAME}/extra/tab/*.cmd
	tar tvzf ${DIST_NAME}.src.tgz

bdistrib_int:
	${MAKE} -C ${DIST_NAME}
	${MAKE} -C ${DIST_NAME}/src clean
	${MAKE} -C ${DIST_NAME}/documentation clean
	tar -czf ${DIST_NAME}.bin.tgz				\
		${DIST_NAME}/[^e]*				\
		${DIST_NAME}/extra/*.c				\
		${DIST_NAME}/extra/mktab.sh			\
		${DIST_NAME}/extra/cthugha.ini*			\
		${DIST_NAME}/extra/Makefile			\
		${DIST_NAME}/extra/tab/*
	tar tvzf ${DIST_NAME}.bin.tgz

edistrib_int:
	${MAKE} -C ${DIST_NAME} tab
	tar -czf ${DIST_NAME}.xtr.tgz				\
		${DIST_NAME}/extra				\
		${DIST_NAME}/src/cthugha.h			\
		${DIST_NAME}/src/cth_buffer.h			\
		${DIST_NAME}/src/imath.c			\
		${DIST_NAME}/src/imath.h
	tar tvzf ${DIST_NAME}.xtr.tgz



