# makefile for z81/z81txt/xz81

# uncomment this to get a white-on-black version, which
#  may not strain your eyes so much :-)
# (only applies to z81txt for now)
#WOBDEF=-DWHITE_ON_BLACK

# these two only apply to xz81:
#
# -DSCALE=n sets how many times to scale up the window, 1=normal.
#  I wouldn't bother with it, it's far too slow. Also, it only works on
#  8-bit displays at the moment.
# -DMITSHM should always be enabled unless you have problems compiling
#  with it on (xz81's rather slow without it).
SCALEDEF=-DSCALE=1 -DMITSHM

# set this if compiling xz81; it should point to where X is installed.
# If you don't know where it is, try `/usr/X11', that's a common
# culprit. This is where it is on my Linux box:
XROOT=/usr/X11R6

# dest for make install
PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
MANDIR=$(PREFIX)/man/man1
LIBDIR=$(PREFIX)/lib

# you shouldn't need to edit the rest
#-----------------------------------------------------------------

# this looks wrong, but *ops.c are actually #include'd by z80.c
Z81_OBJS=main.o z80.o
Z81TXT_OBJS=txtmain.o z80.o
XZ81_OBJS=xmain.o z80.o

CFLAGS=-I. -I$(XROOT)/include -O $(WOBDEF) $(SCALEDEF) -DLIBDIR=\"$(LIBDIR)\"

all: z81 z81txt xz81

z81: $(Z81_OBJS)
	$(CC) -o z81 $(Z81_OBJS) -lvgagl -lvga librawkey.a

z81txt: $(Z81TXT_OBJS)
	$(CC) -o z81txt $(Z81TXT_OBJS) librawkey.a

xz81: $(XZ81_OBJS)
	$(CC) -o xz81 $(XZ81_OBJS) -L$(XROOT)/lib -lXext -lX11

# note that even z81txt must be setuid root, as it must write
# /dev/vcsa0. Don't worry, it throws away root privs immediately after
# the open().

install:
	if [ -f z81 ]; then install -o root -m 4511 -s z81 $(BINDIR); fi
	if [ -f z81txt ]; then install -o root -m 4511 -s z81txt $(BINDIR); fi
	if [ -f xz81 ]; then install -m 511 -s xz81 $(BINDIR); fi
	install -m 444 zx81.rom zx81kybd.pgm $(LIBDIR)
	install -m 444 z81.1 $(MANDIR)
	ln -sf $(MANDIR)/z81.1 $(MANDIR)/z81txt.1
	ln -sf $(MANDIR)/z81.1 $(MANDIR)/xz81.1

clean:
	$(RM) *.o *~

