#!/usr/bin/make -f
#
# makefile for Level9 4.0 --- the Level9 text/graphic adventure interpreter
#
#

# Set this if you are compiling on a little-endian machine (ARM, Intel),
# undefine if running on a big-endian system (PowerPC, Motorola)
LITTLEENDIAN=1


# delimiter in file paths (/ on unix systems, \ on microsoft toys)
FILE_DELIM='/'


# the curses library available on your system
#CURSES_LIB=curses
CURSES_LIB=ncurses


# full-width text justification
JUSTIFY=1

# This will make justified text look nicer in some circumstances, but is
# slower and a bit of a yucky kludge. Don't use it if not justifying
REPRINT_FLUSHED_TEXT=1


# Define this as 1 to get the Emacs-type key bindings
#  Ctrl-A (go to beginning of line)
#  Ctrl-B (back one character)
#  Ctrl-D (delete character at cursor)
#  Ctrl-E (go to end of line)
#  Ctrl-F (forward one character)
#  Ctrl-K (delete to end of line)
EMACS_TYPE_KEYS=1


# this is used for outputting the graphics, unused on tty-only output
#BITMAP_DECODER=1

# whether to perform a full-length file scan for a valid Level9 header
# (should always be used)
FULLSCAN=1

# debbuging options for the Level9 A-Code VM
#L9DEBUG=1
#CODEFOLLOW=1


# maybe your system lacks stricmp()
#NEED_STRICMP_PROTOTYPE=1


#----------------------------------------------------------------------
PRODUCT=level9
PRODVER=4.0
PRODREL=vw1


CC=gcc
CFLAGS=-g -O2 -DFILE_DELIM=\'$(FILE_DELIM)\'
LIBS=-l$(CURSES_LIB)

ifdef LITTLEENDIAN
CFLAGS+=-DLITTLEENDIAN=1
endif
ifdef JUSTIFY
CFLAGS+=-DJUSTIFY=1
endif
ifdef REPRINT_FLUSHED_TEXT
CFLAGS+=-DREPRINT_FLUSHED_TEXT=1
endif
ifdef EMACS_TYPE_KEYS
CFLAGS+=-DEMACS_TYPE_KEYS=1
endif
ifdef BITMAP_DECODER
CFLAGS+=-DBITMAP_DECODER=1
endif
ifdef FULLSCAN
CFLAGS+=-DFULLSCAN=1
endif
ifdef L9DEBUG
CFLAGS+=-DL9DEBUG=1
endif
ifdef CODEFOLLOW
CFLAGS+=-DCODEFOLLOW=1
endif
ifdef NEED_STRICMP_PROTOTYPE
CFLAGS+=-DNEED_STRICMP_PROTOTYPE=1
endif


VMOBJ=level9.o
OBJ_ANSI=$(VMOBJ) generic.o
OBJ_CURSES=$(VMOBJ) unix-curses.o



default: all

all: $(PRODUCT)-dumb $(PRODUCT)-curses
	
#$(PRODUCT)-xglk 

$(PRODUCT)-dumb: $(OBJ_ANSI)
	$(CC) -o $(PRODUCT)-dumb $(OBJ_ANSI)
	ln -s $(PRODUCT)-dumb dlevel9

$(PRODUCT)-curses: $(OBJ_CURSES)
	$(CC) $(LIBS) -o $(PRODUCT)-curses $(OBJ_CURSES)
	ln -s $(PRODUCT)-curses level9

$(PRODUCT)-xglk:
	cd Glk; make; cd ..
	mv Glk/$(PRODUCT)-glk ./$(PRODUCT)-xglk
	ln -s $(PRODUCT)-xglk xlevel9 

clean:
	rm -f $(PRODUCT) $(PRODUCT)-curses *.o

