# -----------------------------------------------------------------------
#
# Big fat Jamfile for all the minor terps, so we don't need to
# mess with the original files and directories more than we have to.
#

SubDir TOP terps ;

MAKE_ADVSYS     ?= yes ;
MAKE_AGILITY    ?= yes ;
MAKE_ALAN2      ?= yes ;
MAKE_ALAN3      ?= yes ;
MAKE_BOCFEL     ?= yes ;
MAKE_FROTZ      ?= yes ;
MAKE_GEAS       ?= yes ;
MAKE_GIT        ?= yes ;
MAKE_GLULXE     ?= yes ;
MAKE_HUGO       ?= yes ;
MAKE_JACL       ?= yes ;
MAKE_LEVEL9     ?= yes ;
MAKE_MAGNETIC   ?= yes ;
MAKE_NITFOL     ?= yes ;
MAKE_SCARE      ?= yes ;
MAKE_SCOTT      ?= yes ;

# -----------------------------------------------------------------------
#
# AdvSys 1.2 + ANSI + NewParser + parts of glkize
#

if $(MAKE_ADVSYS) = yes
{
    SubDir TOP terps advsys ;
    ObjDir advsys ;

    SubDirCcFlags -w ;

    Main $(GARGLKPRE)advsys :
        advmsg.c advtrm.c advprs.c advdbs.c advint.c advjunk.c advexe.c
        glkstart.c ;

    APPS += $(GARGLKPRE)advsys ;
}

# -----------------------------------------------------------------------
#
# Agility 1.1.1.1 with Glk
#
# Agility uses some bad voodoo to get filenames back from glk filerefs.
# We have three options:
#   1) use the bad voodoo (only works on unixes)
#   2) don't use glk file prompts (GLK_ANSI_ONLY)
#   3) use garglk extension garglk_fileref_get_name (GARGLK)
#

if $(MAKE_AGILITY) = yes
{
    SubDir TOP terps agility ;
    ObjDir agility ;

    SubDirCcFlags -DGLK ;
    SubDirCcFlags -DGLK_ANSI_ONLY ;

    Main $(GARGLKPRE)agility :
        agtread.c gamedata.c util.c agxfile.c auxfile.c filename.c
        parser.c exec.c runverb.c metacommand.c savegame.c debugcmd.c
        agil.c token.c disassemble.c object.c
        interface.c os_glk.c 
        ;

    APPS += $(GARGLKPRE)agility ;
}

# -----------------------------------------------------------------------
#
# Alan interpreter 2.8.6
#
# Fixed a couple of bugs (needsp needs resetting in a few places).
# Added glk file prompts for gargoyle using garglk_fileref_get_name.
#

if $(MAKE_ALAN2) = yes
{
    SubDir TOP terps alan2 ;
    ObjDir alan2 ;

    SubDirCcFlags -funsigned-char -Wno-parentheses -DGLK -DREVERSED ;

    Main $(GARGLKPRE)alan2 :
        arun.c main.c debug.c args.c exe.c inter.c parse.c rules.c stack.c
        decode.c term.c reverse.c readline.c params.c sysdep.c
        glkstart.c glkio.c alan.version.c
        ;

    APPS += $(GARGLKPRE)alan2 ;
}

# -----------------------------------------------------------------------
#
# Alan interpreter 3 beta 6-git
#

if $(MAKE_ALAN3) = yes
{
    SubDir TOP terps alan3 ;
    ObjDir alan3 ;

    SubDirCcFlags -funsigned-char -DGLK -DHAVE_GARGLK -DBUILD=0 ;

    Main $(GARGLKPRE)alan3 :
        alan.version.c act.c actor.c args.c arun.c attribute.c
        checkentry.c class.c current.c debug.c decode.c
        dictionary.c event.c exe.c fnmatch.c glkio.c glkstart.c instance.c
        inter.c lists.c literal.c main.c memory.c msg.c options.c
        output.c params.c parse.c readline.c reverse.c rules.c
        save.c scan.c score.c set.c stack.c state.c syntax.c
        sysdep.c syserr.c term.c types.c utils.c word.c compatibility.c
        AltInfo.c Container.c Location.c ParameterPosition.c StateStack.c
        ;

    APPS += $(GARGLKPRE)alan3 ;
}

# -----------------------------------------------------------------------
#
# Bocfel 1.0.1
#

if $(MAKE_BOCFEL) = yes
{
    SubDir TOP terps bocfel ;
    ObjDir bocfel ;

    SubDirCcFlags -std=c99 -DZTERP_GLK -DGARGLK ;

    if $(OS) = MINGW
    {
      SubDirCcFlags -DZTERP_WIN32 ;
    }
    else if $(OS) != MACOSX
    {
      SubDirCcFlags -DZTERP_UNIX ;
    }

    Main $(GARGLKPRE)bocfel :
        blorb.c branch.c dict.c glkstart.c iff.c io.c math.c memory.c
        meta.c objects.c osdep.c patches.c process.c random.c screen.c
        sound.c stack.c unicode.c util.c zoom.c zterp.c
        ;

    APPS += $(GARGLKPRE)bocfel ;
}

# -----------------------------------------------------------------------
#
# Frotz 2.50 / glk port
#

if $(MAKE_FROTZ) = yes
{
    SubDir TOP terps frotz ;
    ObjDir frotz ;

    Main $(GARGLKPRE)frotz :
        buffer.c err.c fastmem.c files.c
        input.c main.c math.c object.c process.c quetzal.c random.c
        redirect.c sound.c stream.c table.c text.c variable.c
        glkscreen.c glkmisc.c
        ;

    APPS += $(GARGLKPRE)frotz ;
}

# -----------------------------------------------------------------------
#
# Geas 0.4
#

if $(MAKE_GEAS) = yes
{
    SubDir TOP terps geas ;
    ObjDir geas ;

    SubDirCcFlags -DUSE_INLINE ;

    if $(OS) = MACOSX
    {
        SubDirCcFlags $(MAINARCH) $(ALTARCH) ;
        LINKFLAGS = -headerpad_max_install_names $(MAINARCH) $(ALTARCH) ;
    }

    SUBDIRC++FLAGS = $(SUBDIRCCFLAGS) ;

    Main $(GARGLKPRE)geas :
        geasfile.cc geas-runner.cc geas-state.cc
        geas-util.cc geasglk.cc geasglkterm.c
        istring.cc readfile.cc
        ;

    LINK on $(GARGLKPRE)geas$(SUFEXE) = $(CXX) ;

    APPS += $(GARGLKPRE)geas ;
}

# -----------------------------------------------------------------------
#
# Git 1.3.5
#
# Reworked startup code to redirect errors to Glk windows.
#

if $(MAKE_GIT) = yes
{
    SubDir TOP terps git ;
    ObjDir git ;

    SubDirCcFlags -DUSE_INLINE -DUSE_OWN_POWF ;

    Main $(GARGLKPRE)git :
        git.c memory.c compiler.c opcodes.c operands.c
        peephole.c terp.c glkop.c search.c git_unix.c
        savefile.c saveundo.c gestalt.c heap.c accel.c
        ;

    APPS += $(GARGLKPRE)git ;
}

# -----------------------------------------------------------------------
#
# Glulxe 0.5.4
#

if $(MAKE_GLULXE) = yes
{
    SubDir TOP terps glulxe ;
    ObjDir glulxe ;

    SubDirCcFlags -DFLOAT_COMPILE_SAFER_POWF ;

    if $(OS) != MINGW { SubDirCcFlags -DOS_UNIX ; }

    Main $(GARGLKPRE)glulxe :
        main.c files.c vm.c exec.c funcs.c operand.c string.c glkop.c
        heap.c serial.c search.c gestalt.c osdepend.c unixstrt.c
        accel.c profile.c float.c
        ;

    APPS += $(GARGLKPRE)glulxe ;
}

# -----------------------------------------------------------------------
#
# Hugo 3.3.0
#
# Include hemedia.c from heglk.c for sound/graphics support.
# Added set_base_file so it can find resource files.
#

if $(MAKE_HUGO) = yes
{
    SubDir TOP terps hugo ;
    ObjDir hugo ;

    SubDirHdrs $(SUBDIR) source ;
    SubDirHdrs $(SUBDIR) heglk ;

    SubDirCcFlags
        -DGLK
        -DCOMPILE_V25
        -DNO_KEYPRESS_CURSOR
        "-DHUGO_INLINE=\"static inline\""
        ;

    SEARCH_SOURCE =
        [ FDirName $(SUBDIR) source ]
        [ FDirName $(SUBDIR) heglk ] ;

    Main $(GARGLKPRE)hugo :
        he.c heexpr.c hemisc.c heobject.c heparse.c heres.c herun.c heset.c 
        stringfn.c heglk.c heglkunix.c
        ;

    APPS += $(GARGLKPRE)hugo ;
}

# -----------------------------------------------------------------------
#
# JACL 2.9.0 for JACL games
#

if $(MAKE_JACL) = yes
{
    SubDir TOP terps jacl ;
    ObjDir jacl ;

    SubDirCcFlags -DGLK -DGARGLK ;

    Main $(GARGLKPRE)jacl :
        jacl.c glk_startup.c findroute.c interpreter.c loader.c 
        glk_saver.c logging.c parser.c display.c utils.c jpp.c 
        resolvers.c errors.c encapsulate.c libcsv.c
        ;

    APPS += $(GARGLKPRE)jacl ;
}

# -----------------------------------------------------------------------
#
# Level9 5.1
#
# Disabled the status bar that just contained a static version string.
# Added graphics support.
#

if $(MAKE_LEVEL9) = yes
{
    SubDir TOP terps level9 ;
    ObjDir level9 ;

    SubDirCcFlags
        -DBITMAP_DECODER
        -DNEED_STRICMP_PROTOTYPE
        -Dstricmp=gln_strcasecmp
        -Dstrnicmp=gln_strncasecmp 
        ;

    SEARCH_SOURCE = $(SUBDIR)
        [ FDirName $(SUBDIR) Glk ] ;

    Main $(GARGLKPRE)level9 : bitmap.c level9.c glk.c ;

    APPS += $(GARGLKPRE)level9 ;
}

# -----------------------------------------------------------------------
#
# Magnetic 2.3
#
# Disable layered drawing, because that is slower than drawing
# all the pixels with fill_rect -- the opposite of Xglk.
#
# Delay opening the status window, because for games that don't use it
# magnetic shows a static version string only. I don't like that.
#
# Made shaded border around pictures if-defable.
#

if $(MAKE_MAGNETIC) = yes
{
    SubDir TOP terps magnetic ;
    ObjDir magnetic ;

    SubDirHdrs $(SUBDIR) Generic ;

    SEARCH_SOURCE =
        [ FDirName $(SUBDIR) Generic ]
        [ FDirName $(SUBDIR) Glk ] ;

    # SubDirCcFlags -DNOBORDER ;

    Main $(GARGLKPRE)magnetic : emu.c glk.c ;

    APPS += $(GARGLKPRE)magnetic ;
}

# -----------------------------------------------------------------------
#
# Nitfol 0.5 + lots of patches
#
# Define the stuff you want:
#
# DEBUGGING   Compile in the debugger.  See DEBUG for details
# SMART_TOKENISER Tries to correct typos.
# TWOS16SHORT Try to speed up some operations if 'short' is a 16 bit two's
#             complement number on your system.  Note that this might slow down
#             Pentium IIs.
# FAST_SIGNED If you're on something which does signed math much faster than
#             unsigned, define this
# FAST        Normally, nitfol does lots of tests to make sure values are in
#             range, both to alert games of unportable actions and to prevent
#             nitfol from crashing.  Defining this removes those tests, so will
#             speed up the game a bit.  Completely legal games should run
#             exactly the same with or without this flag, so if you have a
#             slow computer and you know all the games you will be running are
#             completely legal, define this.
# USE_INLINE  If your C compiler uses the keyword 'inline' to inline functions
# NO_LIBC     Cause nitfol to use its own functions rather than your libc
# NO_TICK     If you don't need glk_tick, define this (minor speed improvement)
# _GNU_SOURCE Use GNU functions (currently just canonicalize_file_name)
# _BSD_SOURCE Use BSD functions (just realpath)
# _XOPEN_SOURCE (also lets nitfol use realpath)

if $(MAKE_NITFOL) = yes
{
    SubDir TOP terps nitfol ;
    ObjDir nitfol ;

    SubDirCcFlags -DSMART_TOKENISER -DDEBUGGING -DFAST -DUSE_INLINE -DNO_TICK ;

    Main $(GARGLKPRE)nitfol : 
        automap.c solve.c infix.c copying.c debug.c inform.c quetzal.c
        undo.c op_call.c decode.c errmesg.c globals.c iff.c init.c 
        io.c z_io.c op_jmp.c op_math.c op_save.c op_table.c op_v6.c oplist.c
        stack.c zscii.c tokenise.c struct.c objects.c portfunc.c hash.c
        sound.c graphics.c blorb.c main.c startunix.c 
        ;

    APPS += $(GARGLKPRE)nitfol ;
}

# -----------------------------------------------------------------------
#
# SCARE 1.3.10 for Adrift games
#

if $(MAKE_SCARE) = yes
{
    SubDir TOP terps scare ;
    ObjDir scare ;

    if $(OS) = MINGW
    {
        SubDirHdrs $(TOP) support zlib ;
    }

    Main $(GARGLKPRE)scare :
        sctafpar.c sctaffil.c scprops.c scvars.c scexpr.c scprintf.c
        scinterf.c scparser.c sclibrar.c scrunner.c scevents.c scnpcs.c
        scobjcts.c sctasks.c screstrs.c scgamest.c scserial.c
        scresour.c scutils.c scdebug.c sclocale.c scmemos.c os_glk.c
        ;

    if $(OS) = MINGW
    {
        SharedLinkLibraries $(GARGLKPRE)scare : zlib1.dll ;
    }

    APPS += $(GARGLKPRE)scare ;
}

# -----------------------------------------------------------------------
#
# ScottFree 1.14 for Scott Adams games
#

if $(MAKE_SCOTT) = yes
{
    SubDir TOP terps scott ;
    ObjDir scott ;

    SubDirCcFlags -std=c99 ;

    Main $(GARGLKPRE)scott : scott.c bsd.c ;

    APPS += $(GARGLKPRE)scott ;
}

