#
# $Id: Makefile-common,v 1.29 2008/12/16 14:19:47 rbornat Exp $
#

GUIDIR=../../java_GUI
ENCODEDIR=../../utf8_encoder
ENGINEDIR=../../camlengine
BUILDRESOURCES=../../CommonBuildResources

##################################################################
#
#       Default (Unix) targets; Windows build overrides these
#
#       ENGINETARGET   -- what the architecture-specific make should try to build
#
ENGINETARGET=jape_engine
#
#       AFTERINSTALL         -- what to do afterwards InstallerKit/install options
#       INSTALLRESOURCES     -- extra resources needed for the installation to work
#       ENCODERESOURCES      -- extra resources for the encoder
#       SPLASH               -- splash-image for the installer
#
#
AFTERINSTALL=-cmdunix "chmod +x %INSTALL%/jape_engine"
INSTALLRESOURCES=$(BUILDRESOURCES)/README-UNIX
ENCODERESOURCES=$(ENCODEDIR)/README_encoder.txt $(ENCODEDIR)/encoder.jar
SPLASH=$(BUILDRESOURCES)/japesplash.png
#
#
##################################################################

all: distribution

#
#       Multiarchitecture/OS engine build is safest if compilations are in separate directories
#
#       1. Different ocaml versions can be used
#       2. Simultaneous compilations are possible
#
#       Technique: synchronize source files in the compile directory, then compile
#       
#
engine:         ; cd $(ENGINEDIR); make $(ENGINETARGET) OS=$(OS)
cleanengine:    ; cd $(ENGINEDIR); make clean OS=$(OS)

#
#       Java is compile-once, run anywhere, so we can make the GUI in one place
#
GUI:            ; (cd $(GUIDIR); ant Jape.jar)
cleanGUI:       ; (cd $(GUIDIR); ant clean)

#
#       ditto the encoder
#
encoder:            ; (cd $(ENCODEDIR); $(MAKE) encoder.jar)
cleanencoder:       ; (cd $(ENCODEDIR); $(MAKE) clean)

#
#       
#
components::    engine GUI

install:        components; \
                  rsync -v -t    $(BUILDRESOURCES)/installjape.sh . ;\
                  sh installjape.sh

clean::          cleanengine cleanGUI cleanencoder

distribution::  ; make encoder; make components; \
                  make jarfile

AT="@"
jarfile:        ; java -jar ../../CommonBuildResources/buildinstaller.jar Install$(OS)jape.jar                                  \
                -app            "Jape"                                                          \
                -splash         $(SPLASH)                                                       \
                -splashside     North                                                           \
                -installdir     Jape                                                            \
                -autoinstall    Jape                                                            \
                -autojar $(GUIDIR)/build/jar/standard/Jape.jar                                  \
                -unixrun        "exec java  -jar %JAR% -engine %INSTALL%/jape_engine \"$$$(AT)\""    \
                -windowsrun     "javaw -jar %JAR% -engine %INSTALL%/jape.exe"                \
                $(AFTERINSTALL)         \
                $(ENCODERESOURCES)      \
                $(INSTALLRESOURCES)     \
                $(ENGINEDIR)/_build$(OS)/$(ENGINETARGET)       \
                ../../examples

