# makefile for nc100em

# You need an ANSI C compiler. Change the next line if you want
# to use a compiler other than gcc.
CC=gcc

# 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

# There are various compile-time options. Generally you won't want to
# change the `CFLAGS' line below, but they're described below in case
# you do.
#
# -DTTY_SERIAL enables serial support via the current terminal, in
#  xnc100em and tnc100em. Recommended.
#
# -DSCALE=n sets how many times to scale up the window, 1=normal.
#  SCALE>1 only works in xnc100em, and only on 8-bit displays at the moment.
#  (It's pretty slow, but may be acceptable on faster machines.)
#
# -DUSE_MMAP_FOR_CARD enables use of mmap() for `nc100.card', the
#  the PCMCIA memory card image. The main effect of this is that
#  the emulator starts/stops rather more quickly, and only
#  bits of the card which are accessed are read/written. It also
#  makes zcntools *much* faster, and means you can use zcntools while
#  an emulator is running (if you're careful), despite what it says
#  in the man page. :-) So you probably shouldn't remove it unless
#  you have problems compiling.
#
# -DMITSHM is for the X version. Don't remove it unless you have
#  problems compiling.
#
CFLAGS=-DMITSHM -DUSE_MMAP_FOR_CARD -DSCALE=1 -DTTY_SERIAL -O -Wall \
	-I$(XROOT)/include

# dest for make install
#
PREFIX=/usr/local
BINDIR=$(PREFIX)/bin
MANDIR=$(PREFIX)/man/man1
XBINDIR=$(BINDIR)
# if you want the X version to be installed in the usual X executables
# directory, uncomment this:
#XBINDIR=$(XROOT)/bin

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

# this looks wrong, but *ops.c are actually #include'd by z80.c
NC100EM_OBJS=main.o common.o libdir.o z80.o
TNC100EM_OBJS=txtmain.o common.o libdir.o z80.o
XNC100EM_OBJS=xmain.o common.o libdir.o z80.o

all: nc100em tnc100em xnc100em zcntools

svga: vga

vga: nc100em zcntools

text: tnc100em zcntools

x: xnc100em zcntools

nc100em: $(NC100EM_OBJS)
	$(CC) -o nc100em $(NC100EM_OBJS) -lvga -lvgagl

tnc100em: $(TNC100EM_OBJS)
	$(CC) -o tnc100em $(TNC100EM_OBJS)

xnc100em: $(XNC100EM_OBJS)
	$(CC) -o xnc100em $(XNC100EM_OBJS) -L$(XROOT)/lib -lXext -lX11

zcntools: zcntools.o libdir.o
	$(CC) -o zcntools zcntools.o libdir.o

pdrom.h: pdrom.bin mkpdromhdr
	./mkpdromhdr <pdrom.bin >pdrom.h

# this is omitted from the `all' target as most people won't have
# zmac, and `pdrom.bin' will be effectively portable anyway... :-)
pdrom.bin: pdrom.z
	zmac pdrom.z

install:
	if [ -f nc100em ]; then \
	install -o root -m 4511 -s nc100em $(BINDIR); fi
	if [ -f tnc100em ]; then \
	install -m 511 -s tnc100em $(BINDIR); fi
	if [ -f xnc100em ]; then \
	install -m 511 -s xnc100em $(BINDIR); fi
	install -m 511 -s zcntools $(BINDIR)
	install -m 555 makememcard.sh $(BINDIR)/makememcard
	install -m 444 nc100em.1 makememcard.1 zcntools.1 $(MANDIR)
	ln -sf $(MANDIR)/nc100em.1 $(MANDIR)/xnc100em.1
	ln -sf $(MANDIR)/nc100em.1 $(MANDIR)/tnc100em.1
	for i in cat df format get info ls put ren rm zero; do \
	  ln -sf $(BINDIR)/zcntools $(BINDIR)/zcn$$i; \
	  ln -sf $(MANDIR)/zcntools.1 $(MANDIR)/zcn$$i.1; \
	done

clean:
	$(RM) *.o *~ *.lst nc100em xnc100em tnc100em zcntools
	$(RM) mkpdromhdr pdrom.h


common.o: common.c pdrom.h z80.h libdir.h
txtmain.o: main.c
	$(CC) $(CFLAGS) -DTEXT_VER -c main.c -o txtmain.o


VERS=1.0

tgz: ../nc100em-$(VERS).tar.gz
  
# Based on the example in ESR's Software Release Practice HOWTO.
#
../nc100em-$(VERS).tar.gz: clean
	$(RM) ../nc100em-$(VERS)
	@cd ..;ln -s nc100em nc100em-$(VERS)
	cd ..;tar zchvf nc100em-$(VERS).tar.gz \
			--exclude='*/sav' nc100em-$(VERS)
	@cd ..;$(RM) nc100em-$(VERS)
