# Generic Inform project makefile
# by D. Jacob Wildstrom

# This makefile should be suited to most projects you might ever want
# to handle using Inform. 'make' or 'make rel' will make a final
# version of your program (using abbreviations, disabling
# debugging). 'make dev' will make a debugging-and-development
# version. 'make clean' does what it normally does.

# In order to use the abbreviation-handling powers of this makefile,
# your source code should at some point contain the line
#   Include ">abbreviations";
# You can change that sourcefile's name below.

# This is the path to your inform binary below. One of the following
# will generally be right.

INFORM = /mit/wild_dj/bin/inform-6.21
# INFORM = /usr/bin/inform-6.21
# INFORM = /usr/local/bin/inform-6.21

# If you need a path setting other than the default, indicate it
# here. You must use ICL notation, so preface any path indication with
# "+".
INFORM-PATHS = 

# You can give the abbreviations file any name you want, but there's
# rarely a need to change it from the default.
ABBREV-FILE = abbreviations.inf

# This is the name of the source file which you want compiled by Inform.
SOURCE-FILE = main.inf

# Any additional dependencies for the compile should go here.
AUX-SOURCES = screenmodel.inf configs.inf hongkong.inf ports.inf atsea.inf fight.inf

# This is the name of the transcript output for compilation using the
# -r switch.
TRANSCRIPT-FILE = transcript.txt

# If you have any other parameters you want to pass to ICL, such as
# $huge, put them here.
ICL-PARAMS = 

# This is the version of the z-machine to which you're
# compiling. Generally it's going to want to be 5, and occasionally
# 8. You will rarely want a different setting.
ZVERSION = 5

# These are respectively the switches and output filename for
# development versions of the z-code.
DEV-PARAMS = -DSXrv$(ZVERSION)
DEV-TARGET = dev-version.z$(ZVERSION)

# These are respectively the switches and output filename for final
# versions of the z-code.
REL-PARAMS = -~Srefsv$(ZVERSION)
REL-TARGET = release-version.z$(ZVERSION)

# These are respectively the switches and output filename for
# abbreviation-determination. Note that the output filename is
# completely arbitrary, since we don't actually care about the z-code
# resulting from an optimization pass.
OPT-PARAMS = -~Suv$(ZVERSION)
OPT-TARGET = .maketemp.optimize.z$(ZVERSION)

# Depending whether you want to actually create and use abbreviations
# or not, uncomment one of the lines below.

# Warning: use-abbreviations has a lot of issues, none of them my
# fault. In games with a lot of text, it's slow, and in games with
# very little text, or text which closely matches inform builtin text,
# it throws a segfault -- this is because text hardwired into Inform
# is in consts, but the -e switch isn't smart enough to not try to
# modify them anyways. Use with caution.

# ABBREVIATIONS-SWITCH = use-abbreviations
ABBREVIATIONS-SWITCH = dont-use-abbreviations

ICL-TRANSCRIPT-CMD = +transcript_name=$(TRANSCRIPT-FILE)

.PHONY: clean use-abbreviations dont-use-abbreviations

release rel final: $(REL-TARGET)

dev develop development test: $(DEV-TARGET)

opt optimize optimization abbreviate abbreviation: $(ABBREV-FILE)

$(REL-TARGET): $(ABBREV-FILE) $(SOURCE-FILE) $(AUX-SOURCES)
	$(INFORM) $(ICL-PARAMS) $(ICL-TRANSCRIPT-CMD) $(REL-PARAMS)\
	$(SOURCE-FILE) $(REL-TARGET)

$(DEV-TARGET): $(SOURCE-FILE) $(AUX-SOURCES)
	$(INFORM) $(ICL-PARAMS) $(ICL-TRANSCRIPT-CMD) $(DEV-PARAMS)\
	$(SOURCE-FILE) $(DEV-TARGET)

$(ABBREV-FILE): $(SOURCE-FILE) $(AUX-SOURCES)
	$(MAKE) $(ABBREVIATIONS-SWITCH)

use-abbreviations: $(SOURCE-FILE) $(AUX-SOURCES)
	$(INFORM) $(ICL-PARAMS) $(ICL-TRANSCRIPT-CMD) $(OPT-PARAMS)\
	$(SOURCE-FILE) $(OPT-TARGET) | grep Abbreviate > $(ABBREV-FILE)
	rm $(OPT-TARGET)

dont-use-abbreviations:
	touch $(ABBREV-FILE)


clean:
	rm -f *~ *.z5 $(TRANSCRIPT-FILE) $(ABBREV-FILE)
# This is, I know, a hack. It basically insures that $(ABBREV-FILE)
# exists, so that 'make dev' doesn't lose, but also insures that it's
# old enough that it'll want updating for the files which have it as
# dependencies.
	touch -t 197001010000.00 $(ABBREV-FILE)
