XINCDIR=/usr/include
XLIBDIR=/usr/X11R6/lib
LIBS=	-lm -L$(XLIBDIR) -lX11
CFLAGS=	-DSUPPORT_X11 -DRGB_TXT=\"/var/X11R6/lib/rgb.txt\"
CC=	gcc -O -I$(XINCDIR)
OBJ=	.o
RM=	rm -f
RMDIR=	rm -rf
CP=	cp
BUNDLE=	fractile.c crystile.c writegif.c writebmp.c writex11.c mgetopt.c \
	tile.c tile.h Makefile fractile.mak crystile.mak \
	fractile.man fractile.txt crystile.man crystile.txt \
	COPYING INSTALL MANIFEST README fractile.mac crystile.mac \
	makegif.bat makebmp.bat examples.html
COMMON= tile$(OBJ) writegif$(OBJ) writebmp$(OBJ) writex11$(OBJ) mgetopt$(OBJ)

all: fractile crystile

fractile: fractile$(OBJ) $(COMMON)
	$(CC) fractile$(OBJ) $(COMMON) $(LIBS) -o fractile

crystile: crystile$(OBJ) $(COMMON)
	$(CC) crystile$(OBJ) $(COMMON) $(LIBS) -o crystile

###############################################################################
tilemkrs.shar: tilemkrs
	$(CP) README tilemkrs.shar
	shar tilemkrs >>tilemkrs.shar

tilemkrs.uue: tilemkrs.tgz
	$(CP) README tilemkrs.uue
	uuencode tilemkrs.tgz <tilemkrs.tgz >>tilemkrs.uue

tilemkrs.tgz: tilemkrs
	rm -rf tilemkrs
	mkdir tilemkrs
	cp $(BUNDLE) tilemkrs
	tar cvf - tilemkrs | gzip >tilemkrs.tgz

tilemkrs: $(BUNDLE)
	rm -rf tilemkrs
	mkdir tilemkrs
	cp $(BUNDLE) tilemkrs

###############################################################################
fractile.txt: fractile.man
	nroff -man fractile.man | col -bx >fractile.txt

crystile.txt: crystile.man
	nroff -man crystile.man | col -bx >crystile.txt

###############################################################################
clean: clean$(OBJ)
	$(RM) *.gif
	$(RM) tilemkrs.shar
	$(RM) tilemkrs.tgz
	$(RMDIR) tilemkrs

clean.o clean.obj:
	$(RM) *$(OBJ)

###############################################################################

makegif.bat: fractile.mac crystile.mac
	while read name opts; do\
		echo fractile $$opts $$name;\
	done <fractile.mac >makegif.bat
	while read name opts; do\
		echo crystile $$opts $$name;\
	done <crystile.mac >>makegif.bat

makebmp.bat: fractile.mac crystile.mac
	while read name opts; do\
		echo fractile $$opts $$name.bmp;\
	done <fractile.mac >makebmp.bat
	while read name opts; do\
		echo crystile $$opts $$name.bmp;\
	done <crystile.mac >>makebmp.bat

examples.html: fractile.mac crystile.mac Makefile
	echo '<html>' >examples.html
	echo '<head>' >>examples.html
	echo '<title>Examples of "fractile" and "crystile" usage</title>' >>examples.html
	echo '</head>' >>examples.html
	echo '<body background="wall.gif">' >>examples.html
	echo >>examples.html
	echo 'The following images were created by the <em>fractile</em> and <em>crystile</em>' >>examples.html
	echo 'programs, using the arguments as shown.' >>examples.html
	echo 'Also, the "wall.gif" image is used as the background of this page.' >>examples.html
	echo 'You should run "<tt>makegif.bat</tt>" before viewing this page.' >>examples.html
	echo '(For UNIX, the command is "<tt>sh makegif.bat</tt>".)' >>examples.html
	echo '<hr>'
	while read name opts; do\
		echo;\
		echo '<p><a href="'$$name.gif'"><img src="'$$name.gif'" align=middle alt="'$$name'"></a>';\
		echo fractile $$opts $$name;\
	done <fractile.mac >>examples.html
	echo '<hr>'
	while read name opts; do\
		echo;\
		echo '<p><a href="'$$name.gif'"><img src="'$$name.gif'" align=middle alt="'$$name'"></a>';\
		echo crystile $$opts $$name;\
	done <crystile.mac >>examples.html
	echo >>examples.html
	echo "</body>" >>examples.html
	echo "</html>" >>examples.html

###############################################################################

try: mgetopt.c
	$(CC) -DTRY mgetopt.c -o try
	
