# File: Makefile
# Contains: I-X source code maintenance and development makefile
# Author: Jeff Dalton <J.Dalton@ed.ac.uk>
# Created: January 1998
# Updated: Wed Aug 25 15:20:16 2010 by Jeff Dalton
# Copyright: (c) 1998 - 2009, AIAI, University of Edinburgh

# This Makefile can be used to perform various operations on the
# top-level directory of the I-X file tree.

ProjectName = I-X

DistName = ix

Version = 4.6

# Needs gmake... export Version

.SUFFIXES: .xhtml .html .rng .rnc


### Compilation

old-compile:
	javac -Xdepend java/ix/ideel/I_DEEL.java

compile:
	etc/path-javac `find java -name \*.java -print`

jikes-compile:
	etc/path-jikes `find java -name \*.java -print`

new-compile:
	etc/compile-changed-files

jussi-compile:
	etc/path-javac `find java-ide -name \*.java -print`

listofs-compile:
	etc/path-javac `find java-listofs -name \*.java -print`

rdf-compile:
	etc/jena2-javac `find java-rdf -name \*.java -print`

jena2-compile:
	etc/jena2-javac `find java-rdf -name \*.java -print`

owl-s-compile:
	etc/owl-s-javac `find java-owl-s -name \*.java -print`

http-compile:
	etc/http-javac `find java-http -name \*.java -print`

compile-tests:
	etc/compile-all-tests

### Clean .class files

# N.B. Does not clean comms or apps directories

java-clean:
	find java -name \*.class | xargs rm
	find java-ide -name \*.class | xargs rm
	find java-listofs -name \*.class | xargs rm
	find test -name \*.class | xargs rm


### .jar file

# N.B. Additions via "jar u" seem to override (replace?) files already
# there.  /\/

JarFile=ix.jar

dated-jar: ${MAKE} JarFile=../ix-classes-`date +%d%h%y`.jar jar

jar:
	cd java-ide; jar cf ../${JarFile} `find ix -name \*.class -print`
	cd java-listofs; jar uf ../${JarFile} `find ix -name \*.class -print`
	cd java; jar uf ../${JarFile} `find ix -name \*.class -print`
	jar uf ${JarFile} resources

#	cd comms/test/java; \
#		jar uf ../../../${JarFile} `find ix -name \*.class -print`

#	cd comms/grid; jar uf ../../${JarFile} `find ix -name \*.class -print`
#	cd comms/kaos; jar uf ../../${JarFile} `find ix -name \*.class -print`

resources-jar:
	jar cf imports/ix-resources.jar resources

jar-with-rdf:
	${MAKE} jar
	cd java-rdf; jar uf ../${JarFile} `find ix -name \*.class -print`

jar-with-owl-s:
	${MAKE} jar
	cd java-rdf; jar uf ../${JarFile} `find ix -name \*.class -print`
	cd java-owl-s; jar uf ../${JarFile} `find ix -name \*.class -print`

jar-with-aglobe:
	${MAKE} jar
	cd java-aglobe; jar uf ../${JarFile} `find ix -name \*.class -print`

add-http-to-jar:
	cd java-http; jar uf ../${JarFile} `find ix -name \*.class -print`

http-jar:
	${MAKE} JarFile=ix-http.jar jar
	${MAKE} JarFile=ix-http.jar add-http-to-jar

# A small http jar is used with IChatApplets.
# It leaves out I-DE and I-Plan.
# 'jar i' would index it as small-http.jar, so index after any renaming.

small-http-jar:
	cd java-http; jar cf ../small-http.jar `find ix -name \*.class`
	cd java-listofs; jar uf ../small-http.jar `find ix -name \*.class`
	cd java; jar uf ../small-http.jar \
		`find ix -name \*iplan\* -prune \, -name \*.class`
	jar uf small-http.jar resources
	# jar i small-http.jar

source-jar:
	export 
	cd java; jar cf ../ix-src.jar \
		`find ix  \( -name "*.java" -o -name "*.html" \) -print`
	cd java-ide; jar uf ../ix-src.jar \
		`find ix  \( -name "*.java" -o -name "*.html" \) -print`
	cd java-listofs; jar uf ../ix-src.jar \
		`find ix  \( -name "*.java" -o -name "*.html" \) -print`
	cd java-http; jar uf ../ix-src.jar \
		`find ix  \( -name "*.java" -o -name "*.html" \) -print`

source-tar:
	${TAR} -cvp -f source.tar    IX-Copyright.txt
	${TAR} -rvp -C java          --exclude=\*.class --exclude=\*\~ \
					-f source.tar .
	${TAR} -rvp -C java-ide      --exclude=\*.class --exclude=\*\~ \
					-f source.tar .
	${TAR} -rvp -C java-listofs  --exclude=\*.class --exclude=\*\~ \
					-f source.tar .
	${TAR} -rvp -C java-http     --exclude=\*.class --exclude=\*\~ \
					-f source.tar .

util-jar:
	cd java; jar cf ../ix-util.jar `find ix/util -name \*.class -print`

# Here are some ways to make jar files with interesting manifests.

Manifest=tmp/jar-manifest

manifest-jar:
	rm -f ${Manifest}
	echo "Main-Class: ix.ip2.Ip2" > ${Manifest}
	echo "Class-Path:" imports/*.jar >> ${Manifest}
	${MAKE} jar
	jar umf ${Manifest} ${JarFile}
	# jar i ${JarFile}

minimal-classpath-jar:
	rm -f ${Manifest}
	echo "Main-Class: ix.ip2.Ip2" > ${Manifest}
	echo "Class-Path:" imports/jdom.jar >> ${Manifest}
	${MAKE} JarFile=minimal-ix.jar jar
	jar umf ${Manifest} minimal-ix.jar

classpath-jar:
	rm -f ${Manifest}
	echo "Main-Class: ix.ip2.Ip2" > ${Manifest}
	echo "Class-Path:" imports/*.jar >> ${Manifest}
	# ${MAKE} jar-with-rdf -- instead do:
	${MAKE} jar
	${MAKE} add-http-to-jar
	jar umf ${Manifest} ${JarFile}

classpath-jar-with-owl-s:
	rm -f ${Manifest}
	echo "Main-Class: ix.ip2.Ip2" > ${Manifest}
	echo "Class-Path:" imports/*.jar >> ${Manifest}
	${MAKE} jar-with-owl-s
	${MAKE} add-http-to-jar
	jar umf ${Manifest} ${JarFile}

# launcher.jar builds a jar file containing only the launcher

launcher.jar: java/ix/util/AgentLauncher.java
	rm -f ${Manifest}
	echo "Main-Class: ix.util.AgentLauncher" > ${Manifest}
	cd java; jar cvf ../launcher.jar ix/util/AgentLauncher*.class
	jar umf ${Manifest} launcher.jar

# launcher-ix-jar builds a jar-with-owl-s but makes the launcher
# be the main-program class.

launcher-ix-jar:
	rm -f ${Manifest}
	echo "Main-Class: ix.util.AgentLauncher" > ${Manifest}
	${MAKE} jar-with-owl-s
	${MAKE} add-http-to-jar
	jar umf ${Manifest} ${JarFile}

launcher-rdf-jar:
	rm -f ${Manifest}
	echo "Main-Class: ix.util.AgentLauncher" > ${Manifest}
	${MAKE} jar-with-rdf
	${MAKE} add-http-to-jar
	jar umf ${Manifest} ${JarFile}

ide-jar:
	rm -f ${Manifest}
	echo "Main-Class: ix.test.ShowIDE" > ${Manifest}
	echo "Class-Path:" ix.jar imports/*.jar imports/jena2/*.jar >> ${Manifest}
	cd java; jar cf ../ide.jar ix/test/ShowIDE*.class
	jar umf ${Manifest} ide.jar

jena2-jar:
	rm -f ${Manifest}
	echo "Main-Class: ix.ip2.Ip2" > ${Manifest}
	echo "Class-Path:" imports/jena2/*.jar imports/*.jar \
		>> ${Manifest}
	${MAKE} jar
	cd java-rdf; jar uf ../${JarFile} `find ix -name \*.class -print`
	jar umf ${Manifest} ${JarFile}

owl-s-jar: imports/owl-s/all-imports.jar
	rm -f ${Manifest}
	echo "Main-Class: ix.ip2.Ip2" > ${Manifest}
	echo "Class-Path:" imports/owl-s/all-imports.jar imports/*.jar \
		>> ${Manifest}
	${MAKE} jar
	cd java-owl-s; jar uf ../${JarFile} `find ix -name \*.class -print`
	jar umf ${Manifest} ${JarFile}

imports/owl-s/all-imports.jar:
	rm -f /tmp/imports-manifest
	rm -f imports/owl-s/all-imports.jar
	cd imports/owl-s; \
	    echo "Class-Path:" *.jar \
		>> /tmp/imports-manifest
	jar cmf /tmp/imports-manifest imports/owl-s/all-imports.jar

# imports/all-imports.jar is an alternative to the all-imports.jar
# that's down in imports/owl-s.  The idea is that we can include
# the Jena 2 imports or the OWL-S API ones as desired, just by
# changing which file is imports/all-imports.jar.

imports/all-imports.jar:
	rm -f /tmp/imports-manifest
	rm -f imports/all-imports.jar
	cd imports; \
	    echo "Class-Path:" jena2/*.jar \
		>> /tmp/imports-manifest
	jar cmf /tmp/imports-manifest imports/all-imports.jar

etc/all-imports-for-owl-s.jar:
	rm -f /tmp/imports-manifest
	rm -f etc/all-imports-for-owl-s.jar
	cd imports; \
	    echo "Class-Path:" owl-s/*.jar \
		>> /tmp/imports-manifest
	jar cmf /tmp/imports-manifest etc/all-imports-for-owl-s.jar

# For a Jabber jar, see also apps/ip2-jar

jabber-jar: jabber-comms.jar
	rm -f ${Manifest}
	echo "Main-Class: ix.ip2.Ip2" > ${Manifest}
# 	echo "Class-Path:" imports/*.jar \
# 		comms/jabber/imports/*.jar \
# 		jabber-comms.jar \
# 		>> ${Manifest}
	# /\/: Could use comms/jabber/java instead ofjabber-comms.jar,
	# but it wouldn't "chain".
	echo "Class-Path:" comms/jabber/imports/*.jar \
		jabber-comms.jar \
		>> ${Manifest}
	${MAKE} jar
	jar umf ${Manifest} ${JarFile}

JabberJarFile = /tmp/jabber-comms.jar

jabber-comms.jar:
	cd comms/jabber/java; \
		jar cf ${JabberJarFile} \
			 `find ix -name \*.class -print`
	mv -i ${JabberJarFile} .


# For an applet, ix.jar seems to have to be in the same dir as the import jars.
# We also add an index (jar -i).

applet-jar:
	rm -f ${Manifest}
	echo "Main-Class: ix.ip2.Ip2" > ${Manifest}
	(cd etc/applet-test; \
	 echo "Class-Path:" `find -s . -name \*.jar -not -name ix.jar` \
		| sed "s:./::g" \
		>> ../../${Manifest})
	# echo "Sealed: true" >> ${Manifest}
	${MAKE} jar
	jar umf ${Manifest} ${JarFile}
	mv ${JarFile} etc/applet-test
	(cd etc/applet-test; jar i ${JarFile})

### Tags for Emacs

tags:
	etags `find java -name \*.java -print`

### Javadoc documentation

public-javadoc:
	${MAKE} javadoc-clean
	etc/path-javadoc -public -d doc/javadoc \
		-use `etc/find-all-doc-packages`

protected-javadoc:
	${MAKE} javadoc-clean
	etc/path-javadoc -protected -d doc/javadoc \
		-use `etc/find-all-doc-packages`

full-javadoc:
	${MAKE} javadoc-clean
	etc/path-javadoc -package -d doc/javadoc \
		-use `etc/find-all-doc-packages`

javadoc-clean:
	-rm -r doc/javadoc/*


### Cleaning

clean-tilde-files:
	find . -print | grep "~" | xargs rm


### XHTML documentation and syntax descriptsions

# Since .html and .rnc files are the only ones we generate from
# other files, it will work simply to list them as what doc/xml-syntax
# requires (so long as we request the initial versions of the .html
# and .rnc files by hand).

doc/xml-syntax: doc/xml-syntax/*.html doc/syntax/*.rnc

.xhtml.html:
	etc/saxon $*.xhtml tmp/xhtml-to-html.xslt > $*.html

.rng.rnc:
	etc/saxon $*.rng etc/RngToRnc-1_4/RngToRncText.xsl > $*.rnc

.rng.html:
	etc/saxon $*.rng etc/RngToRnc-1_4/RngToRncHtml.xsl > $*.html


### Release date
#
# Defines Release.date and Release.version in a new ix/Release.java.
#
# %h works for the month with both SunOS 4.1.3 and FreeBSD.
#

RDateFile = java/ix/Release.java

rdate:
	rm -f ${RDateFile}
	echo 'package ix;'  > ${RDateFile}
	echo               >> ${RDateFile}
	echo '/** ${ProjectName} ${Version}' `date +%d-%h-%y` '*/' \
	     >> ${RDateFile}
	echo 'public class Release {' \
	     >> ${RDateFile}
	echo '  public static String version = "${Version}";' \
	     >> ${RDateFile}
	echo '  public static String date    = "'`date +%d-%h-%y`'";' \
	     >> ${RDateFile}
	echo '  public static String time    = "'`date +%H:%M`'";' \
	     >> ${RDateFile}
	echo '}' \
	     >> ${RDateFile}


### Tarfile construction for backup etc
#
# Many of the make targets in this part of the Makefile are chiefly
# for "internal" use by the Makefile itself.  External targets are:
# 
#   file-backup
#   release-parts
#
# Some targets that construct tarfiles determine what files to include
# by an inverse method: construct a list of files to _exclude_ and then
# include everything else.  The "exclude" file is for use with the
# GNU tar "X" option.
#
# This approach may seem bizarre, but it worked on the machines where
# I needed it to work, when a number of more obvious things didn't, and
# it's easier and more reliable than maintaining by hand a list of all
# files to include.  The most likely failure is to get some extra
# files, which is better than leaving some out.

TarFile = failed_to_set_TarFile

Exclude = /tmp/ix-exclude

TAR = env COPY_EXTENDED_ATTRIBUTES_DISABLE=true tar

file-backup:
	${MAKE} TarFile=../${DistName}-`date +%d%h%y`.tar.gz nice-backup
	echo `date` file backup on `hostname` >> transfer-log

nice-backup:
	${MAKE} Exclude=${Exclude} exclude
	${TAR} -zcvX ${Exclude} -f ${TarFile} .

# make Archive=whatever new-files-backup

new-files-backup:
	${MAKE} Exclude=${Exclude} exclude
	${TAR} -zcvX ${Exclude} \
		-f ../${DistName}-delta-`date +%d%h%y`.tar.gz \
		`find . -newer ${Archive} \
			-not -type d -not -name \*.class \
			-not -path \*/javadoc/\*`

exclude:
	rm -f ${Exclude}
	echo ./transfer-log > ${Exclude}
	echo ./tmp/javac-timestamp >> ${Exclude}
	echo ./doc/javadoc >> ${Exclude}
	echo ./imports >> ${Exclude}
	# echo ./logs >> ${Exclude}
	find . -type d -name logs -print >> ${Exclude}
	find . -type d -name \*-logs -print >> ${Exclude}
	echo ./test-results >> ${Exclude}
	echo ./old-test-results >> ${Exclude}
	echo ./older-test-results >> ${Exclude}
	echo ./etc/applet-test/logs >> ${Exclude}
	echo ./webapps >> ${Exclude}
	# exclude some of the larger apps
	echo ./apps/idemo-iroom >> ${Exclude}
	echo ./apps/addon >> ${Exclude}
	# echo ./resources/map >> ${Exclude}
	echo ./TAGS >> ${Exclude}
	echo ./core >> ${Exclude}
	${MAKE} Exclude=${Exclude} exclude-objects
	${MAKE} Exclude=${Exclude} tar-exclude
	${MAKE} Exclude=${Exclude} tex-exclude
	# Emacs backup files can make it too large for one floppy.
	find . -name "*~" -print >> ${Exclude}
	# Now exclude executable non-directories that are > 20K bytes.
	# The idea is that these will not be shell scripts.
	# find . -type f -perm -u+x -size +20 -print \
	#    | sed "s:^./::" >> ${Exclude}
	find . -type f -perm -100 -size +20 -print >> ${Exclude}

exclude-objects:
	find . \( -name "*.o" \
                  -o -name "*.class" -o -name "*.javaimport" \) \
	   -print >> ${Exclude}

tar-exclude:
	find . \( -name "*.tar" -o -name "*.jar" \) -print \
	   >> ${Exclude}

tex-exclude:
	find doc \( -name "*.dvi" -o -name "*.aux" -o -name "*.log" \) -print \
	   >> ${Exclude}

### Release parts
#
# Here we make a tar file that contains the parts of this directory tree
# that belong in a release.
#
# N.B. Since we don't say "./whatever" in the ReleaseFiles, only "whatever",
# we have to take the "./" off the file names we put in the exclude file.
#

ReleaseFiles = Makefile \
	java java-ide java-listofs java-http java-rdf java-owl-s \
	resources \
	scripts/unix \
	doc \
	etc \
	gen \
	test apps/test comms/test \
	test-domains expected-test-results

# Removed from files:
#	apps/postix \

release-parts:
	rm -f ${Exclude}
	find . -name "*~" -print | sed "s:^./::" >> ${Exclude}
	echo etc/applet-test >> ${Exclude}
	tar -zcX ${Exclude} \
		-f ../for-${DistName}-${Version}-`date +%d%h%y`.tar.gz \
		${ReleaseFiles}

### Release archives

# In the main release directory:
#   make -f development/Makefile release-archives

release-archives:
	cd ..; ${MAKE} \
		Version=${Version} \
		-f ${DistName}-${Version}/development/etc/release-makefile all

# End
