#
# $Id: Makefile-common,v 1.26 2005/07/29 14:14:30 rbornat Exp $
#

GUIDIR=../../java_GUI
ENCODEDIR=../../utf8_encoder
ENGINEDIR=../../camlengine
RESOURCES=../CommonBuildResources
BUILDRESOURCES=../../CommonBuildResources
COMPILEDIR=./tmp
SOURCES=-I ../../../ocamlengine
SERVERSCRIPT=exec java -jar japeserver.jar

##################################################################
#
#       Default (Unix) targets; Windows build overrides these
#
#       ENGINETARGET   -- what the architecture-specific make should try to build
#       BUILTENGINE    -- what the architecture-specific make builds
#                         (these are only different for the Windows cross-Make)
#       DEPLOYEDENGINE -- name of the binary that gets deployed
#                         (should not be "jape" if we want to use a "jape" script)
#
ENGINETARGET=jape_engine
BUILTENGINE=jape_engine
DEPLOYEDENGINE=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
APP=jape
#
#
##################################################################

all:   ; $(MAKE) components 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:         ; rsync -v -t --exclude="*.cm*" \
                        $(ENGINEDIR)/Makefile   \
                        $(ENGINEDIR)/.depend    \
                        $(ENGINEDIR)/*.ml*  $(COMPILEDIR);\
                  (cd $(COMPILEDIR); make $(ENGINETARGET))
               
cleanengine:    ; rm -f $(COMPILEDIR)/.depend;\
                  rm -f $(COMPILEDIR)/*;\
                  (cd $(COMPILEDIR); rm -f $(BUILTENGINE) $(DEPLOYEDENGINE) $(ENGINETARGET));\
                  make engine

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

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

#
#       
#
components::    engine GUI examples;\
                  rsync -v -t    $(GUIDIR)/Jape.jar .                       ;\
                  rsync -v -t    $(COMPILEDIR)/$(BUILTENGINE) ./$(DEPLOYEDENGINE)

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

clean:          ; rm -rf tmp; rm -f $(BIN)/Jape.jar $(BIN)/*.gif $(BIN)/*.jpg $(BIN)/jape 

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

examples:       ; ln -s ../../examples .


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

