#
# Makefile for cthugha-L
#
# usage:
#   make		create all the executables and
#                       documentation (should be done as root)
#   make src            create only the executables
#   make doc		create only the documentation (info and ps file)
#   make tab		create the default tab-files (in directory extra/tab)
#   make tab160x100     create tab-files for 160x100
#   make tab320x300     create tab-files for 320x300
#   make tab-install    copy generated tab-files to correct place
#   make install	bring files to the right directories (run as root)
#   make uninstall	to delete the installed files
#   make clean		to remove junk
#
# 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 
	@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 xcthugha-saver
cthugha:
	make -C src ../cthugha
xcthugha:
	make -C src ../xcthugha
cthugha-server:
	make -C src ../cthugha-server
xcthugha-saver:
	make -C src ../xcthugha-saver


.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: 
	(cd extra; sh mktab.sh)

.PHONY: tab160x100
tab160x100:
	(cd extra; sh mktab.sh 160 100)

.PHONY: tab320x300
tab320x300: 
	(cd extra; sh mktab.sh 320 300)

tab-install: 
	${INSTALL} -d ${INST_LIB}/tab
	${INSTALL} -m 0644 extra/tab/*	${INST_LIB}/tab

#
# the current Version and distribution name
#
VERSION = 0.8
DIST_NAME = cthugha-L-${VERSION}

#
# copy files to right places
#
install: 
	${INSTALL} -d ${INST_LIB}map
	${INSTALL} -d ${INST_LIB}pcx
	${INSTALL} -d ${INST_LIB}tab
	${INSTALL} -m 0755 cthugha		${INST_BIN}
	${INSTALL} -m 0755 xcthugha		${INST_BIN}
	${INSTALL} -m 0755 cthugha-server	${INST_BIN}
	${INSTALL} -m 0755 xcthugha-saver   	${INST_BIN}
	${INSTALL} -m 0755 tabheader		${INST_BIN}
	${INSTALL} -m 0755 tabinfo		${INST_BIN}
	(cd documentation; make install)
	${INSTALL} -m 0644 extra/cthugha.ini    ${INST_LIB}
	${INSTALL} -m 0644 extra/Cthugha.ad	${INST_AD}/Cthugha
	${INSTALL} -m 0644 extra/Cthugha-saver.ad  ${INST_AD}/Cthugha-saver
	(${INSTALL} -m 0644 extra/map/*		${INST_LIB}/map;echo -n)
	(${INSTALL} -m 0644 extra/pcx/*		${INST_LIB}/pcx;echo -n)
	(${INSTALL} -m 0644 extra/tab/*		${INST_LIB}/tab;echo -n)

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

#
# remove some junk
#
clean:
	make -C src clean
	make -C documentation clean
	rm -f cthugha xcthugha cthugha-server xcthugha-saver \
	      tabheader tabinfo extra/tab/* *~ extra/*~ *~ .first_time

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

# source only distribution
sdistrib:
	make -C .. sdistrib_int -f ${shell pwd}/Makefile

# binary & source only distribution
bdistrib:
	make -C .. bdistrib_int -f ${shell pwd}/Makefile

# extra files
edistrib:
	make -C .. edistrib_int -f ${shell pwd}/Makefile
 
# source only distribution
sdistrib_int:
	make -C ${DIST_NAME} 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/*.ad
	tar tvzf ${DIST_NAME}.src.tgz

# binary  distribution
bdistrib_int:
	make -C ${DIST_NAME}
	make -C ${DIST_NAME}/src clean
	make -C ${DIST_NAME}/documentation dejunk
	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/*.ad
	tar tvzf ${DIST_NAME}.bin.tgz

# extra files
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
	tar tvzf ${DIST_NAME}.xtr.tgz
 


