# This is the Makefile for Jaja. It is part of a Scheme->Java compiler.
# It contains entries showing how to compile or run Jaja.
# Author: <Christian.Queinnec@lip6.fr>
# Documentation: http://www-spi.lip6.fr/~queinnec/WWW/Jaja.html

work : Jaja.jar Jaja.zip 

clean :: 
	-rm Jaja/?*.class 
	-cd Jaja ; rm -f ${JAJA_DOC_HTML}

# Recompile all classes in one go (they're mutually recursive through
# static methods).

recompile.all : cleanSkelAndStub
	javac Jaja/?*.java

# Only recompile classes from the recommended entry points.

recompile : 
	javac Jaja/FromOS.java Jaja/Textual.java Jaja/NullPort.java \
		Jaja/NamedBox.java

output.non.recompiled.classes : 
	@echo Classes that are not compiled:
	@cd Jaja ; for f in *.java ; do\
	f=`basename $$f .java` ;\
	if [ -f $$f.class ] ; then true ;\
	else echo Missing $$f ; fi ; done

# Regenerate documentation.

JAJA_DOC_HTML	=	\
	../../README.Jaja \
	COPYING \
	Jaja/AllNames.html \
	Jaja/Package-Jaja.html \
	Jaja/Jaja.*.html \
	Jaja/packages.html \
	Jaja/tree.html 

rebuild.documentation : Jaja/Package-Jaja.html
Jaja/Package-Jaja.html : Jaja/Id.class
	javadoc -version -author -d Jaja Jaja

# Rebuild a distribution with something like:
#                    make distribution

DISTRIBUTION	=	`date +%y%b%d`

distribution : clean
	-rm Jaja.jar Jaja.zip 
	m ckpt
	cvs update Jaja/Id.java
	touch Jaja/Id.java
	echo Might need cvs update -A
	-cvs -q commit -m '${DISTRIBUTION} distribution' -f Jaja/Id.java
	${MAKE} recompile output.non.recompiled.classes 
	${MAKE} Jaja.jar 
	${MAKE} Jaja.zip

# Pack compiled classes and main page.
# 			Penser a le signer un de ces jours !!!!
# Penser a mettre doc et readme etc.
# *.scm files must be in the same directory/package as the classes that 
# need them.

Jaja.jar : manifest.mf boot1.scm bootm1.scm
	cp boot1.scm bootm1.scm Jaja/
	jar cmvf manifest.mf Jaja.jar \
		../../README.Jaja Jaja/?*.class Jaja/?*.scm
	-rm manifest.mf Jaja/boot*.scm

# NOTE: When an url is present in a manifest file, its content is
# fetched so it can be signed. Therefore don't reference the Jaja.html
# page which will probably change a lot in the future. Don't say for now
# that some classes are beans, this is not yet true.

manifest.mf : Imakefile
	( echo "Manifest-Version: 1.0" ;\
	  echo ;\
	  echo "Main-Class: Jaja/FromOS.class" ;\
	  echo "Name: Jaja/World.class" ;  >/dev/null \
	  echo "Java-Bean: True" ; 	   >/dev/null \
	  echo "Name: Jaja/Listener.class" ;  >/dev/null \
	  echo "Java-Bean: True" ; 	   >/dev/null \
	) > manifest.mf

# Pack everything that is, Java sources, compiled classes and generated
# documentation.  The Jaja.zip may be put into your CLASSPATH variable.

Jaja.zip : rebuild.documentation boot1.scm bootm1.scm
	-rm Jaja.zip
	cp boot1.scm bootm1.scm Jaja/	
	zip -rn ".class:.gif:.zip" Jaja.zip \
		Jaja/?*.java Jaja/?*.class Jaja/?*.scm
	zip -g Jaja.zip Imakefile Jaja.html ${JAJA_DOC_HTML}
	-rm Jaja/boot*.scm

# Compress all Jaja sources into a single listing with a2ps:

Jaja.ps :
	a2ps -A Jaja/?*.java -o Jaja.ps

clean ::
	-rm Jaja.ps

# Copy Jaja to Windows95 partition:

TO95	=	/d95/qlispou/
copy.from.perou.to.w95 :
	-chmod -R u+w /d95/qlispou/Jaja*
	cp -rp Jaja* ${TO95}

####################################################### Tests

test.from.shell.0 :
	java Jaja.Textual 
test.from.shell.1 :
	java Jaja.FromOS -textual
test.from.shell.2 :
	java Jaja.Textual -eval '(display'   ' "OK")'
test.from.shell.3 :
	java Jaja.FromOS -textual -- -eval '(display "OK")'

test.from.shell.with.applet :
	java Jaja.FromOS

test.with.appletviewer : 
	-mkdir /tmp/Java
	-ln -s `pwd`/Jaja.jar /tmp/Java/
	-ln -s `pwd`/Jaja.html /tmp/
	cd /tmp ; appletviewer Jaja.html
	-rm -rf /tmp/Java /tmp/Jaja.html

test.with.hotjava :
	-mkdir /tmp/Java
	-ln -s `pwd`/Jaja.jar /tmp/Java/
	-ln -s `pwd`/Jaja.html /tmp/
	cd /tmp ; hotjava file:`pwd`/Jaja.html
	-rm -rf /tmp/Java /tmp/Jaja.html

test.with.netscape :
	-mkdir /tmp/Java
	-cp `pwd`/Jaja.jar /tmp/Java/
	-ln -s `pwd`/Jaja.html /tmp/
	cd /tmp ; netscape file:`pwd`/Jaja.html
	-rm -rf /tmp/Java /tmp/Jaja.html

Jaja/NetWorld.class : Jaja/NetWorld.java
	javac Jaja/NetWorld.java
Jaja/NetEvaluation.class : Jaja/NetEvaluation.java
	javac Jaja/NetEvaluation.java
Jaja/NetWorld_Skel.class : Jaja/NetWorld.class Jaja/NetEvaluation.class
	@echo rmic -keepgenerated -d . Jaja.NetWorld
	rmic -d . Jaja.NetWorld Jaja.NetEvaluation
clean :: cleanSkelAndStub
cleanSkelAndStub :
	-rm Jaja/NetWorld_*.java Jaja/NetWorld_*.class
	-rm Jaja/NetEvaluation_*.java Jaja/NetEvaluation_*.class
test.rmi : Jaja/NetWorld_Skel.class 
	java Jaja.NetWorld "w1" & (sleep 50; kill $$!) & sleep 5
	java Jaja.FromOS -world "rmi:///Jaja/w1"

# Takes a snapshot of the Jaja window

jaja-window.eps :
	xwpick -format eps jaja-window.eps
jaja-window.gif :
	xwpick -format gif jaja-window.gif

####################################################### Development

tags : TAGS
TAGS : Imakefile
	etags Jaja/?*.java

############################################################# Bootstrap
# Copied from ~/Cours/dessGLA/Imakefile. These antecedent files should
# be removed when the current directory is OK.

# Read mkboot.scm to understand what happens. I first used bigloo but
# bigloo is case insensitive and prints in uppercases. I now use elk
# but dot within symbols are preceded by a backslash which is to be
# removed (ie a.b is displayed as a\.b). All these symbols seem to have
# been removed now.

natScheme.escm boot1.escm bootm1.escm compiler.escm : \
		mkboot.scm \
		../../../DEA/natScheme.scm \
		../../Macros/clexpand.scm \
		../../Macros/clmacros.scm \
		../../Library/libscm1.scm
	cat mkboot.scm | elk -h 20000

# boot1.scm is the non-primitive predefined library of usual Scheme functions
# such as cadr, reverse, ... This is to complement level 0 of Jaja.

boot1.scm : boot1.escm Imakefile
	( echo ";;; Automatically generated, don't touch!" ;\
	  echo ";;; This is the predefined unessential Scheme library." ;\
	  cat < boot1.escm ;\
	  echo ";;; end of boot1.scm" ) > boot1.scm

# bootm1.scm is a decent macroexpander to be defined at level 1 of Jaja.
# You need boot1.scm to run bootm1.scm.  Level 2 of Jaja is left as it
# is (no expansion at all, but you may still load bootm1.scm into it
# using the eval-in-expansion-world special form).

bootm1.scm : bootm1.escm Imakefile
	( echo ";;; Automatically generated, don't touch!" ;\
	  echo ";;; This is a macroexpander for Scheme predefined syntaxes." ;\
	  cat < bootm1.escm ;\
	  echo ";;; end of bootm1.scm" ) > bootm1.scm

# Test a little

test.interactively : boot1.scm bootm1.scm
	( echo "\
(load \"boot1.scm\") \
(set! call/cc call/ep) \
(eval-in-expansion-world \
  (begin (load \"boot1.scm\") \
         (load \"bootm1.scm\") ) ) \
	" ; tee ) | java Jaja.Textual

clean ::
	-rm boot*scm

# Works now! (until continuations are used out of their dynamic extent).
# Very slow (on lispou Pentium133: 259.500u 1.820s 4:32.88 95.7%).
# On perou (Pentium450: 72s)

test1.with.tester : boot1.scm bootm1.scm
	echo "\
(load \"boot1.scm\") \
(set! call/cc call/ep)  \
(eval-in-expansion-world  \
  (begin (load \"boot1.scm\")  \
         (load \"bootm1.scm\") ) ) \
(load \"../../Others/tester.scm\") \
(set! tester-take-only-one-continuation #t)  \
(set! tester-call/cc call/ep)  \
(define t #t)  \
(define f #f)  \
(define nil '())  \
(suite-test \"../../../DEA/scheme.tst\"   \
  \"?? \" \"== \" #t   \
  (lambda (read check err)   \
    (lambda ()   \
      (check (monitor (lambda (c e) (err e))  \
               (eval (read)) )) ) )  \
  equal? )            " | java Jaja.Textual

test2.with.tester : boot1.scm bootm1.scm
	echo "\
(load \"boot1.scm\") \
(set! call/cc call/ep)  \
(eval-in-expansion-world  \
  (begin (load \"boot1.scm\")  \
         (load \"bootm1.scm\") ) ) \
(load \"../../Others/tester.scm\") \
(set! tester-take-only-one-continuation #t)  \
(set! tester-call/cc call/ep)  \
(define t #t)  \
(define f #f)  \
(define nil '())  \
(suite-test \"../../Test/monitor.tst\"   \
  \"?? \" \"== \" #t   \
  (lambda (read check err)   \
    (lambda ()   \
      (check (monitor (lambda (c e) (err e))  \
               (eval (read)) )) ) )  \
  equal? )             " | java Jaja.Textual

# mkboot.scm also expands the natScheme naive evaluator. So we may
# directly test this interpreted eval function. Caution: this is slow.
# Of course, continuations being inherited from Jaja, their use is
# restricted to their dynamic extent.

natScheme.scm : natScheme.escm Imakefile
	( echo ";;; Automatically generated, don't touch!" ;\
	  echo ";;; This is a naive Scheme evaluator." ;\
	  sed -e s/\\\\\././g < natScheme.escm ;\
	  echo ";;; end of natScheme.scm" ) > natScheme.scm

test.natScheme : natScheme.scm
	echo "\
(load \"boot1.scm\") \
(eval-in-expansion-world \
  (begin (load \"boot1.scm\") \
         (load \"bootm1.scm\") ) ) \
(define call/cc call/ep) \
(load \"../../Others/tester.scm\") \
(set! tester-take-only-one-continuation #t)  \
(set! tester-call/cc call/ep)  \
(load \"natScheme.scm\") \
(define (test-natscheme) \
  (suite-test \"../../../DEA/scheme.tst\" \
    \"NatScheme? \" \"NatScheme= \" \
     #t \
     (lambda (read check error) \
       (set! wrong error) \
       (lambda () \
          (check (evaluate (read) env.global) ) ) ) \
     equal? ) ) \
(test-natscheme) 	" | java Jaja.Textual

# Gathering the compiler into a single file. This is necessary since the
# compiler can only compile a single file.  NOTE: The compiler uses
# monitor and uninitialized-let.  Gambit knows how to handle properly
# \n inside strings (but remove #" introduced by Bigloo). Don't fold
# uppercases into lowercases, there are too much format strings to
# preserve (but uses -:s option of Gambit to preserve case
# insensitivity) or use Elk but substitute \. into a single dot.

compiler.escm : javacomp.scm javaenv.scm javagen.scm
compiler.scm : compiler.escm Imakefile
	( echo ";;; Automatically generated, don't touch!" ;\
	  cat compiler.escm ;\
	  echo ";;; end of compiler.scm" ) > compiler.scm

# Try the compiler on a very small file.

FILE_SCM	=	/tmp/single.scm

test.compiler.with.gambit : compiler.scm 
	[ -f ${FILE_SCM} ] || cp ../../Tmp/single.scm ${FILE_SCM}
	echo "\
(include \"../../Gambit/macgam.scm\") \
(include \"../../Gambit/rtgam.scm\") \
(define-icslas-macro (uninitialized-let vars . body) \
  \`(let ,(map (lambda (v) (list v ''())) vars) . ,body) ) \
(define-icslas-macro (monitor handler . body) \
  \`(do-monitor ,handler (lambda () . ,body)) ) \
(include \"../../Bind/monitor.scm\") \
(define target \"/tmp\") \
(define (call-internal-compiler string) string) \
\"     Loading compiler.scm \" \
(load \"compiler.scm\") \
\"     Compiler loaded. \" \
(compiler-main '(\"-v\" \"-nofile\" \"-nojavac\" \"${FILE_SCM}\")) \
	" | gsi -:s

# Compile and generate a file

compile.file.with.gambit : compiler.scm 
	echo "\
(include \"../../Gambit/macgam.scm\") \
(include \"../../Gambit/rtgam.scm\") \
(define-icslas-macro (uninitialized-let vars . body) \
  \`(let ,(map (lambda (v) (list v ''())) vars) . ,body) ) \
(define-icslas-macro (monitor handler . body) \
  \`(do-monitor ,handler (lambda () . ,body)) ) \
(include \"../../Bind/monitor.scm\") \
(define target \"/tmp\") \
(define (call-internal-compiler string) string) \
\"     Loading compiler.scm \" \
(load \"compiler.scm\") \
\"     Compiler loaded. \" \
(compiler-main '(\"-v\" \"-nojavac\" \"${FILE_SCM}\")) \
	" | gsi -:s

# Exercice the compiler on itself. This produces the compiler.java file.
# monitor is actually wrongly compiled. FUTURE
# uninitialized-let is not compiled (treated as a function)
# there are more than 10 parameters somewhere (due to the previous fault).

compile.compiler.with.gambit : compiler.java
compiler.java : compiler.scm 
	echo "\
(include \"../../Gambit/macgam.scm\") \
(include \"../../Gambit/rtgam.scm\") \
(define-icslas-macro (uninitialized-let vars . body) \
  \`(let ,(map (lambda (v) (list v ''())) vars) . ,body) ) \
(define-icslas-macro (monitor handler . body) \
  \`(do-monitor ,handler (lambda () . ,body)) ) \
(include \"../../Bind/monitor.scm\") \
(define target \"/tmp\") \
(define (call-internal-compiler string) string) \
(load \"compiler.scm\") \
(compiler-main '(\"-v\" \"-nojavac\" \"compiler.scm\")) \
	" | gsi -:s
	ls -l compiler.scm compiler.java
# on lispou: > 24'

# Test compiler on a file with jaja

test.compiler.with.jaja : compiler.scm 
	[ -f ${FILE_SCM} ] || cp ../../Tmp/single.scm ${FILE_SCM}
	echo "\
(load \"boot1.scm\") \
(eval-in-expansion-world \
  (begin (load \"boot1.scm\") \
         (load \"bootm1.scm\") ) ) \
(define call/cc call/ep) \
(define TARGET \"/tmp\") \
(define (call-internal-compiler string) string) \
\"     Loading compiler.scm \" \
(load \"compiler.scm\") \
\"     Compiler loaded. \" \
(compiler-main '(\"-v\" \"-nofile\" \"-nojavac\" \"${FILE_SCM}\")) \
	" | java Jaja.Textual

# Let's try now to compile the compiler with Jaja.

compile.compiler.with.jaja : compiler.scm
	echo "\
(load \"boot1.scm\") \
(eval-in-expansion-world \
  (begin (load \"boot1.scm\") \
         (load \"bootm1.scm\") ) ) \
(define call/cc call/ep) \
(define TARGET \"/tmp\") \
(define (call-internal-compiler string) string) \
(load \"compiler.scm\") \
(compiler-main '(\"-v\" \"compiler.scm\")) \
	" | java Jaja.Textual

# 

########################################################### Archive
# Update SchemeRT to awt 1.1. In fact only SchemeApplet.java is impacted.
update.awt :
	cd SchemeRT ; for f in *.java ; do echo ; echo Updating $$f ... ; \
   sed -f ${JDKDIR}/docs/guide/awt/updateAWT $$f > NEW.$$f ; \
   diff $$f NEW.$$f ; done

######################################### Turning Jaja into jaja
# Do it once only. Change all names Scheme* into *
# as well as SchemeRT into Jaja.

converting.to.jaja :
	-mkdir Jaja
	for f in SchemeRT/?*.java ; do \
		perl Archive/turntojaja.prl $$f ; done
	mv Jaja/.java Jaja/Jaja.java
	mv Jaja/String.java Jaja/MutableString.java
	mv Jaja/Applet.java Jaja/JajaListener.java

################################# SchemeRT for Polytechnique
# Attention, X (on hp stations) seems to be using an old java 1.0 compiler.
# Regenerate an old version with:
#     cvs update -D '25 dec 96' -d SchemeRT
# Don't forget to change:

JAVA_REVISION	=	1.1

HIDDEN_FILES =	\
	Scheme*Applet.java		\
	Scheme*Box.java			\
	Scheme*Environment.java		\
	SchemeEscape.java		\
	SchemeEscapeObject.java		\
	SchemeEval.java			\
	SchemeEvaluation.java		\
	SchemeExitObject.java		\
	SchemeId.java			\
	SchemeInterpretedProcedure.java	\
	SchemeInterpreter.java		\
	SchemeInvokation.java		\
	SchemeLoad.java			\
	SchemeSpecialOperator*.java

build.x.library :
	-mkdir SchemePureRT
	cd SchemeRT ; LANG="" ; export LANG ; for f in *.java ; do \
	    if { ls ${HIDDEN_FILES} | grep $$f } >/dev/null ; \
	    then echo skipping $$f. ; else echo '	Handling' $$f ... ; \
	    perl ${HOME}/icslas/Commands/pureschemert.prl < $$f \
		> ../SchemePureRT/$$f ; fi ; done
compile.x.library : build.x.library
	javac -deprecation SchemePureRT/?*.java
document.x.library : compile.x.library
	javadoc SchemePureRT && mv *.html SchemePureRT
zip.x.library : document.x.library
	zip SchemePureRT${JAVA_REVISION}.zip SchemePureRT/?*
clean.all ::
	-rm -rf SchemePureRT SchemePureRT*.zip

# end of Imakefile
