# Makefile for xpat 1.2
# (tested with noname i386, Linux 1.0.4, gcc 2.5.8)

VER=1.2

# user configuration:
# 1. game configuration

# specify, if you don't want round cards (else must have Xmu)
ROUND_OPTION = # -DNO_ROUND_CARDS

# specify, if you have a Linux sound driver installed
# valid option are -DSUN_SOUND (digitized) or -DFM_SOUND (FM-Sound, Linux only)
SOUND_OPTION = -DSUN_SOUND

# specify, if you want to load external full-color cardsets
# note: check the location of "xpm.h" in xpm.c. Perhaps insert "X11/"
XPM_OPTION = # -DNO_XPM

# Xmu is needed for round cards, Xpm for full-color cardsets, Xext for -g
ADDLIBS = -L/usr/lib/X11 -lXpm -lXmu -lXext


# 2. directories (defaults should conform to Linux FSSTND)

# Location of the resident (r/o) files. Move them to "local" if you like.
BINDIR = /usr/games/bin
DOCDIR = /usr/doc/xpat
LIBDIR = /usr/games/lib/xpat
MANDIR = /usr/man/man6

# This is the name of the log-file, where solved games are stored:
SCOREFILE = /var/games/xpat.log

# end of user configuration



COMPRESS = gzip

OBJS = events.o windows.o rules.o main.o layout.o buttons.o expose.o \
  hints.o cards.o loadsave.o util.o sound.o gfx.o xpm.o markcard.o arrows.o \
  r_HM.o r_Spider.o
SRCS = events.c windows.c rules.c main.c layout.c buttons.c expose.c \
  hints.c cards.c loadsave.c util.c sound.c  gfx.c xpm.c markcard.c arrows.c \
  r_HM.c r_Spider.c
TEXRELICTS = *.aux *.log *.toc

# define extra warnings for gcc
# should compile with only 2 warnings (Linux 0.99.14x, 4.5.8 lib, XFree 2.0)
# If there are too many warnings, just omit the extra warning flags
#
# The -pedantic option has been omitted since gcc 2.5.0
#
WARNINGS = -Wall -Wtraditional -Wshadow  -Wpointer-arith -Wcast-qual \
      -Wcast-align -Wwrite-strings -Waggregate-return \
      -Wstrict-prototypes -Wmissing-prototypes \
      -Wnested-externs

CC = gcc
# note concerning "-m386": xpat doesn't need to be fast. Better save some disk
# space (386 binaries are smaller)
CFLAGS = -O2 -m386 -ansi  $(WARNINGS) \
    $(ROUND_OPTION) $(SOUND_OPTION) $(XPM_OPTION) \
    -DSCOREFILE=\"$(SCOREFILE)\" -DLIBDIR=\"$(LIBDIR)\"

LDFLAGS = -s -N
LIBS =  $(ADDLIBS) -lX11

xpat: $(OBJS)
	gcc $(LDFLAGS) -o xpat $(OBJS) $(LIBS)

all: xpat manual.ps

clean:
	rm -f core *.o *~ xpat $(TEXRELICTS) *.dvi *.ps

manual.dvi: manual.tex history.tex
	latex manual
	latex manual
	latex manual

manual.ps: manual.dvi
	dvips -f < manual.dvi > manual.ps

distrib: clean
	rm -f ../xpat-$(VER)-*.tar*
	# rm -f core *.o *~ $(TEXRELICTS)
	tar cvf ../xpat-$(VER)-bin.tar $(BINDIR)/xpat $(SCOREFILE) \
	    $(MANDIR)/xpat.6x* $(DOCDIR)
	# rm -f xpat manual.ps manual.dvi
	(cd .. ; tar cvf xpat-$(VER)-src.tar xpat-$(VER) )
	$(COMPRESS) ../xpat-$(VER)-bin.tar
	$(COMPRESS) ../xpat-$(VER)-src.tar
	tar cvf ../xpat-$(VER)-dat.tar $(LIBDIR)/xpmcards1 $(LIBDIR)/*.au \
	    $(LIBDIR)/*.cards
	$(COMPRESS) ../xpat-$(VER)-dat.tar

install: xpat manual.ps
	mkdirhier $(BINDIR) $(MANDIR) $(LIBDIR) $(DOCDIR)
	chmod 755 $(LIBDIR) $(DOCDIR)
	cp xpat $(BINDIR)
	chmod 755 $(BINDIR)/xpat
	cp -p xpat.6x $(MANDIR)
	if [ -r $(MANDIR)/xpat.6x.gz ]; then gzip $(MANDIR)/xpat.6x; fi
	chmod 644 $(MANDIR)/xpat.6x*
	cp -p manual.dvi manual.ps COPYRIGHT.* $(DOCDIR)
	chmod 644 $(DOCDIR)/*
#	cp -p *.au *.cards $(LIBDIR)
#	chmod a+r $(LIBDIR)/*.au $(LIBDIR)/*.cards

gfx.o : gfx.c xpat.h xpatx11.h   rank.bm face.bm suit.bm logo.bm \
        Joker.bm clip7.bm clip4.bm
	$(CC) $(CFLAGS) -c gfx.c

windows.o : windows.c xpat.h xpatx11.h   pat.bm gray1.bm
	$(CC) $(CFLAGS) -c $<

markcard.o : markcard.c xpat.h xpatx11.h  stipple.bm
	$(CC) $(CFLAGS) -c $<

# generic rule for all sources which do not need additional include files:
%.o : %.c xpat.h xpatx11.h
	$(CC) $(CFLAGS) -c $<
