#
#       Makefile
#
###
#
#  Copyright (c) 1994 - 2007	David Albert Bagley, bagleyd@tux.org
#
#                   All Rights Reserved
#
#  Permission to use, copy, modify, and distribute this software and
#  its documentation for any purpose and without fee is hereby granted,
#  provided that the above copyright notice appear in all copies and
#  that both that copyright notice and this permission notice appear in
#  supporting documentation, and that the name of the author not be
#  used in advertising or publicity pertaining to distribution of the
#  software without specific, written prior permission.
#
#  This program is distributed in the hope that it will be "useful",
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#

# If this fails to build one may have to edit the individual Imakefiles.
# Also install the appropriate .ad file in $HOME or where ever you
# normally  put these preferences.
# To configure, build, and install in /usr/local/bin
#	make configure
#	make         # Motif version built by default
#	make run     # this cycles through all programs
#	make install # if you like them
# Any problems please consult the individual README's and let the author know.
# xdial and xthreed are more or less demos and are not built by default.

#SHELL=/bin/sh

#STUFF=abacus dial threed
STUFF=dial threed
ROTATIONAL=rubik skewb dino pyraminx oct mball
SLIDING=cubes triangles hexagons mlink barrel panex
ALTRIS=tetris tertris hextris welltris

#XT=${STUFF} ${ROTATIONAL} ${SLIDING} ${ALTRIS}
# Swap this next line in and the next line out to build xdial and xthreed
#XT=${STUFF} ${ROTATIONAL} ${SLIDING}
XT=${ROTATIONAL} ${SLIDING}
#XT=${ALTRIS}

#VER=-7.3.1

XLOCK=more
#PRE=xlock
#NAME=xlockmore.
PRE=
NAME=xt.
#NAME=xpuzzles.
#NAME=xabacus.
#NAME=altris.
NAME_TRUNC=`echo ${NAME} | cut -c1-8`.

PROGRAMS=${XT}

# Used by me to zip and write and read from my floppy drive
UNIXDIR=./net
DOSDIR=win

all :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make;\
			cd ..;\
		fi;\
	done

win :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER}/win32 ]; then\
			cd ${PRE}$${i}${VER}/win32;\
			make;\
			cd ../..;\
		fi;\
	done

autoconf :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in distclean;\
			autoconf;\
			rm -rf autom4te.cache;\
			cd ..;\
		fi;\
	done

configure :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in distclean;\
			./configure;\
			cd ..;\
		fi;\
	done

# Use this in conjunction with the next one
configure-x :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in distclean;\
			./configure --without-motif ;\
			cd ..;\
		fi;\
	done

configure-xm :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in distclean;\
			./configure --enable-xm-prefix ;\
			cd ..;\
		fi;\
	done

configure-sound :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in distclean;\
			./configure --without-nas --without-esound --without-nas --enable-def-play="play.sh" ;\
			cd ..;\
		fi;\
	done

xmkmf :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			xmkmf -a;\
			cd ..;\
		fi;\
	done

# add in all extra features
pre-xmkmf :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			cp -p Imakefile Imakefile.orig;\
			sed -e "s/^XCOMM #define/#define/" Imakefile.orig > Imakefile;\
			cd ..;\
		fi;\
	done

post-xmkmf :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			mv Imakefile.orig Imakefile;\
			cd ..;\
		fi;\
	done

lint :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make lint;\
			cd ..;\
		fi;\
	done

lint.w :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER}/win32 ]; then\
			cd ${PRE}$${i}${VER}/win32;\
			make lint;\
			cd ../..;\
		fi;\
	done

indent :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make indent;\
			cd ..;\
		fi;\
	done

indentcheck :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			ls -al *.c *.c~ *.h *.h~;\
			cd ..;\
		fi;\
	done

dbx :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in gdb;\
			cd ..;\
		fi;\
	done

gdb :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in gdb;\
			cd ..;\
		fi;\
	done

run :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in run;\
			cd ..;\
		fi;\
	done

run.scores :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in run.scores;\
			cd ..;\
		fi;\
	done

run.version :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in run.version;\
			cd ..;\
		fi;\
	done

run.w :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER}/win32 ]; then\
			cd ${PRE}$${i}${VER}/win32;\
			make -f Makefile run;\
			cd ../..;\
		fi;\
	done

dist.w :
	mkdir -p $(DOSDIR);\
	for i in *README; do\
		cp $${i} $(DOSDIR)/$${i};\
		cp $${i} $(DOSDIR)/$${i}.old;\
		unix2dos $(DOSDIR)/$${i}.old $(DOSDIR)/$${i};\
		rm $(DOSDIR)/$${i}.old;\
	done;\
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER}/win32 ]; then\
			cd ${PRE}$${i}${VER}/win32;\
			make -f Makefile dist;\
			cd ../..;\
		fi;\
	done

clean :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in clean;\
			cd ..;\
		fi;\
	done

distclean :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in distclean;\
			cd ..;\
		fi;\
	done

clean.all :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in clean.all;\
			cd ..;\
		fi;\
	done

pack :
	rm -rf xt xt.tar.bz2;\
	mkdir net;\
	make bzip2;\
	mv net xt ;\
	tar cvjf xt.tar.bz2 xt;\
	sftp gwyn.tux.org

tar :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in tar;\
			cd ..;\
		fi;\
	done

compress :
	cp -p ${NAME}Makefile ${UNIXDIR}/${NAME}Makefile;\
	cp -p *.README ${UNIXDIR};\
	cp -p *.lsm ${UNIXDIR};\
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in compress;\
			cd ..;\
		fi;\
	done

gzip :
	cp -p ${NAME}Makefile ${UNIXDIR}/${NAME}Makefile;\
	cp -p *.README ${UNIXDIR};\
	cp -p *.lsm ${UNIXDIR};\
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in gzip;\
			cd ..;\
			mv ${PRE}$${i}${VER}.tar.gz ${UNIXDIR};\
		fi;\
	done

bzip2 :
	cp -p ${NAME}Makefile ${UNIXDIR}/${NAME}Makefile;\
	cp -p *.README ${UNIXDIR};\
	cp -p *.lsm ${UNIXDIR};\
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in bzip2;\
			cd ..;\
			mv ${PRE}$${i}${VER}.tar.bz2 ${UNIXDIR};\
		fi;\
	done

untar :
	for i in ${PROGRAMS}; do\
		tar xvf ${PRE}$${i}${VER}.tar;\
		rm -f ${PRE}$${i}${VER}.tar;\
	done

uncompress :
	for i in ${PROGRAMS}; do\
		if [ -r ${PRE}$${i}${VER}.tar ]; then\
			echo "${PRE}$${i}${VER}.tar in the way";\
		elif [ -r ${PRE}$${i}${VER}.tar.Z ]; then\
			uncompress ${PRE}$${i}${VER}.tar.Z;\
			tar xvf ${PRE}$${i}${VER}.tar;\
			rm -f ${PRE}$${i}${VER}.tar;\
		else echo "no ${PRE}$${i}${VER}.tar.Z";\
		fi;\
	done

gunzip :
	for i in ${PROGRAMS}; do\
		if [ -r ${PRE}$${i}${VER}.tar ]; then\
			echo "${PRE}$${i}${VER}.tar in the way";\
		elif [ -r ${PRE}$${i}${VER}.tar.gz ]; then\
			rm -f ${PRE}$${i}${VER}.tar;\
			gunzip ${PRE}$${i}${VER}.tar.gz;\
			tar xvf ${PRE}$${i}${VER}.tar;\
			rm -f ${PRE}$${i}${VER}.tar;\
		else echo "no ${PRE}$${i}${VER}.tar.gz";\
		fi;\
	done

bunzip2 :
	for i in ${PROGRAMS}; do\
		if [ -r ${PRE}$${i}${VER}.tar ]; then\
			echo "${PRE}$${i}${VER}.tar in the way";\
		elif [ -r ${PRE}$${i}${VER}.tar.bz2 ]; then\
			bunzip2 ${PRE}$${i}${VER}.tar.bz2;\
			tar xvf ${PRE}$${i}${VER}.tar;\
			rm -f ${PRE}$${i}${VER}.tar;\
		else echo "no ${PRE}$${i}${VER}.tar.bz2";\
		fi;\
	done

read :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			more README;\
			cd ..;\
		fi;\
	done

man :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in man;\
			cd ..;\
		fi;\
	done

dist.man :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in dist.man;\
			cd ..;\
		fi;\
	done

html :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in html;\
			cd ..;\
		fi;\
	done

hlp :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make -f Makefile.in hlp;\
			cd ..;\
		fi;\
	done

#print :

small :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make small;\
			cd ..;\
		fi;\
	done

small.w :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER}/win32 ]; then\
			cd ${PRE}$${i}${VER}/win32;\
			make small;\
			cd ../..;\
		fi;\
	done

install :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make install;\
			cd ..;\
		fi;\
	done

install.w :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER}/win32 ]; then\
			cd ${PRE}$${i}${VER}/win32;\
			make install;\
			cd ../..;\
		fi;\
	done

uninstall :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make uninstall;\
			cd ..;\
		fi;\
	done

install-games :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make install-games;\
			cd ..;\
		fi;\
	done

uninstall-games :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make uninstall-games;\
			cd ..;\
		fi;\
	done

install-png :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make install-png;\
			cd ..;\
		fi;\
	done

uninstall-png :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make uninstall-png;\
			cd ..;\
		fi;\
	done

install-xpm :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make install-xpm;\
			cd ..;\
		fi;\
	done

uninstall-xpm :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make uninstall-xpm;\
			cd ..;\
		fi;\
	done

install-xpm-home :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make install-xpm-home;\
			cd ..;\
		fi;\
	done

uninstall-xpm-home :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make uninstall-xpm-home;\
			cd ..;\
		fi;\
	done

vi :
	for i in ${PROGRAMS}; do\
		vi ${PRE}$${i}${VER}/?`echo $${i} | cut -c2-`.c;\
	done

icon :
	for i in ${PROGRAMS}; do\
		if [ -d ${PRE}$${i}${VER} ]; then\
			cd ${PRE}$${i}${VER};\
			make icon;\
			cd ..;\
		fi;\
	done
