#
# Include all the sub-projects
# Then make install rules to copy exe files into bin
#

SubDir TOP ;

SubInclude TOP garglk ;
SubInclude TOP terps ;
SubInclude TOP tads ;
SubInclude TOP support ;

# If SYSTEM is set, use values for a system wide install
if $(SYSTEM)
{
    BINDIR = /usr/local/libexec/gargoyle ;
    APPDIR = /usr/local/libexec/gargoyle ;
    LIBDIR = /usr/local/lib/gargoyle ;
    DESTDIR = / ;
    EXEMODE = 755 ;
    FILEMODE = 755 ;
}
# Otherwise use _BINDIR, _APPDIR, and _LIBDIR
# to populate BINDIR, APPDIR, and LIBDIR with
# values supplied on the command line (if any)
else
{
    if $(DESTDIR)
    { ITOP = [ FDirName $(DESTDIR) ] ; }
    else
    { ITOP = [ FDirName $(TOP) build dist ] ; }

    BINDIR = [ FPrependRoot $(ITOP) : $(_BINDIR) ] ;
    APPDIR = [ FPrependRoot $(ITOP) : $(_APPDIR) ] ;
    LIBDIR = [ FPrependRoot $(ITOP) : $(_LIBDIR) ] ;
}

for APP in $(APPS)
{
    LinkLibraries $(APP) : libgarglkmain ;
    SharedLinkLibraries $(APP) : libgarglk ;
    InstallBin $(APPDIR) : $(APP)$(SUFEXE) ;
}

if $(OS) = MINGW
{
    SubInclude TOP support ;
    SharedLinkLibraries scare : libz ;
    SharedLinkLibrariesOnSharedLibrary libgarglk :
        libfreetype libjpeg libpng libz ;

    InstallLib $(LIBDIR) : libfreetype$(SUFDLL) ;
    InstallLib $(LIBDIR) : libjpeg$(SUFDLL) ;
    InstallLib $(LIBDIR) : libpng$(SUFDLL) ;
    InstallLib $(LIBDIR) : libz$(SUFDLL) ;
}

InstallBin $(BINDIR) : gargoyle$(SUFEXE) ;
InstallLib $(LIBDIR) : libgarglk$(SUFDLL) ;

if $(OS) = MINGW && $(USESDL)
{
    SharedLinkLibrariesOnSharedLibrary libgarglk : SDL_sound ;
    local _SDL = $(TOP) support sdl-1.2.13 ;
    SEARCH_SOURCE = $(_SDL:J=\\) ;
    InstallLib $(LIBDIR) : SDL_sound.dll ;
    InstallLib $(LIBDIR) : SDL_mixer.dll ;
    InstallLib $(LIBDIR) : SDL.dll ;
    InstallLib $(LIBDIR) : smpeg.dll ;
    InstallLib $(LIBDIR) : libogg-0.dll ;
    InstallLib $(LIBDIR) : libvorbis-0.dll ;
    InstallLib $(LIBDIR) : libvorbisfile-3.dll ;
}

