Description: Modifications of Makefile to make symlinks
 Some files from the nodejs framework are necessary to build jsxgraph
 and its documentation. These modifications create and erase necessary
 symlinks during the build and the clean processes.
Index: jsxgraph/Makefile
===================================================================
--- jsxgraph.orig/Makefile
+++ jsxgraph/Makefile
@@ -1,13 +1,13 @@
 .PHONY: tests test test-server
 
 # build tools
-REQUIREJS=./node_modules/.bin/r.js
-UGLIFYJS=./node_modules/.bin/uglifyjs
-JSDOC2=nodejs ./node_modules/.bin/jsdoc2
+REQUIREJS=./node_modules/bin/r.js
+UGLIFYJS=/usr/bin/uglifyjs
+JSDOC2=java -jar /usr/share/java/jsrun.jar /usr/share/jsdoc-toolkit/app/run.js
 #JSDOC2=nodejs ./node_modules/.bin/jsdoc
 
-LINT=./node_modules/.bin/jslint
-HINT=./node_modules/.bin/jshint
+LINT=./node_modules/jslint/bin/jslint.js
+HINT=./node_modules/jshint/bin/hint
 JSTESTDRIVER=java -jar ./node_modules/jstestdriver/lib/jstestdriver.jar
 INTERN=./node_modules/.bin/intern-client
 
@@ -52,16 +52,28 @@ LINTFLAGS=--bitwise true --white true
 READERSOUT=build/bin/readers/geonext.min.js build/bin/readers/geogebra.min.js build/bin/readers/intergeo.min.js build/bin/readers/sketch.min.js
 
 # rules
-all: core core-min readers docs moodle
+all: symlinks core compressor core-min readers docs movedocs
+
+symlinks:
+	# add symlinks to replace node_modules utilities
+	#################################################
+	# replace almond
+	$(MKDIR) $(MKDIRFLAGS) node_modules/almond
+	ln -s /usr/lib/nodejs/almond/almond.js node_modules/almond/
+	$(MKDIR) $(MKDIRFLAGS) node_modules/requirejs/bin
+
+movedocs:
+	# change the location of zip files to make their packaging easier
+	mv distrib/*.zip .
 
 core:
 	$(MKDIR) $(MKDIRFLAGS) $(BUILDBIN)
-	$(REQUIREJS) -o $(BUILD)/core.build.json
+	nodejs $(REQUIREJS) -o $(BUILD)/core.build.json
 
 
 core-min:
 	$(MKDIR) $(MKDIRFLAGS) $(BUILDBIN)
-	$(REQUIREJS) -o $(BUILD)/core.build.json optimize=uglify2 out=$(BUILDBIN)/jsxgraphcore-min.js;
+	nodejs $(REQUIREJS) -o $(BUILD)/core.build.json optimize=uglify2 out=$(BUILDBIN)/jsxgraphcore-min.js;
 	{ $(CAT) COPYRIGHT; $(CAT) $(BUILDBIN)/jsxgraphcore-min.js; } > $(BUILDBIN)/jsxgraphcore.min.js
 	$(CP) $(BUILDBIN)/jsxgraphcore.min.js $(OUTPUT)/jsxgraphcore.js
 
@@ -85,11 +97,12 @@ docs: core core-min
 	$(MKDIR) $(MKDIRFLAGS) $(OUTPUT)
 
 	# update template related files
-	$(CP) distrib/jquery.min.js $(JSDOC2TPLSTAT)/jquery.min.js
+	ln -s /usr/share/javascript/jquery/jquery.min.js $(JSDOC2TPLSTAT)/
 	$(CP) $(BUILDBIN)/jsxgraphcore.min.js $(JSDOC2TPLSTAT)/jsxgraphcore.js
 	$(CP) distrib/jsxgraph.css $(JSDOC2TPLSTAT)/jsxgraph.css
 
 	# update the plugin
+	$(MKDIR) $(MKDIRFLAGS) ./node_modules/jsdoc2/app/plugins
 	$(CP) $(JSDOC2PLG)/*.js ./node_modules/jsdoc2/app/plugins/
 
 	# run node-jsdoc2
@@ -104,22 +117,11 @@ docs: core core-min
 	# Test
 	$(CD) $(OUTPUT) && $(UNZIP) -o docs.zip
 
-moodle: core core-min $(READERSOUT)
-	$(MKDIR) $(MKDIRFLAGS) $(TMP)
-	$(MKDIR) $(MKDIRFLAGS) $(TMP)/jsxgraph
-	$(CP) $(BUILDBIN)/jsxgraphcore.min.js $(TMP)/jsxgraph/jsxgraphcore.js
-	$(CP) distrib/jsxgraph.css $(TMP)/jsxgraph/jsxgraph.css
-	$(CP) ../moodle-jsxgraph-plugin/moodle2/*.php $(TMP)/jsxgraph/
-	$(CP) ../moodle-jsxgraph-plugin/moodle2/styles.css $(TMP)/jsxgraph/
-	$(CP) ../moodle-jsxgraph-plugin/README.md $(TMP)/jsxgraph/
-	$(CP) -r ../moodle-jsxgraph-plugin/moodle2/lang $(TMP)/jsxgraph/
-	$(CP) $(BUILDREADERS)/* $(TMP)/jsxgraph/
-
-	# zip -r tmp/jsxgraph.zip tmp/jsxgraph
-	$(CD) $(TMP) && $(ZIP) $(ZIPFLAGS) jsxgraph_moodle.zip jsxgraph/
-	$(CP) $(TMP)/jsxgraph_moodle.zip $(OUTPUT)/jsxgraph_moodle.zip
-
-	$(RM) $(RMFLAGS) tmp
+	# Protect against privacy breaches
+	sed -e 's/.*gaJsHost.*//' \
+	    -e 's/.*pageTracker.*//' \
+	    distrib/docs/index.html > distrib/docs/index.html.tmp && \
+	  mv distrib/docs/index.html.tmp distrib/docs/index.html
 
 readers: $(READERSOUT)
 	$(MKDIR) $(MKDIRFLAGS) $(OUTPUT)
@@ -130,14 +132,14 @@ build/bin/readers/%.min.js: src/reader/%
 	{ $(CAT) COPYRIGHT; $(UGLIFYJS) $^; } > $@
 
 compressor: core
-	$(REQUIREJS) -o build/compressor.build.json
+	nodejs $(REQUIREJS) -o build/compressor.build.json
 	{ $(CAT) JSXCompressor/COPYING; $(CAT) $(BUILDBIN)/jsxcompressor.js; } > JSXCompressor/jsxcompressor.min.js
 	$(CP) $(BUILDBIN)/jsxgraphcore.js JSXCompressor/jsxgraphcore.js
 	$(CP) distrib/jsxgraph.css JSXCompressor/jsxgraph.css
 
 plot:
 	$(MKDIR) $(MKDIRFLAGS) $(BUILDBIN)
-	$(REQUIREJS) -o build/plot.build.json
+	nodejs $(REQUIREJS) -o build/plot.build.json
 
 hint:
 	$(HINT) src/$(LINTLIST).js
@@ -145,11 +147,38 @@ hint:
 lint:
 	$(LINT) $(LINTFLAGS) src/$(LINTLIST).js
 
-test-server:
-	$(JSTESTDRIVER) --port $(JSTESTPORT)
+#test-server:
+#	$(JSTESTDRIVER) --port $(JSTESTPORT)
+
+#test: core
+#	$(JSTESTDRIVER) $(JSTESTSERVER) $(JSTESTFLAGS) --basePath ./ --config test/jsTestDriver.conf
 
-test: core
-	$(JSTESTDRIVER) $(JSTESTSERVER) $(JSTESTFLAGS) --basePath ./ --config test/jsTestDriver.conf
+#tests:
+#	$(INTERN) config=tests/intern
 
-tests:
-	$(INTERN) config=tests/intern
+clean:
+	for d in $$(ls node_modules/ | grep -v bin); do \
+	  rm -rf node_modules/$$d; \
+	done
+	rm -f build/bin/jsxgraphcore.js
+	rm -f doc/jsdoc-tk/template/static/jquery.min.js
+	rm -rf distrib/docs/*
+	rm -f docs.zip
+	rm -f jsxgraph_moodle.zip
+	rm -f JSXCompressor/jsxcompressor.min.js
+	rm -f JSXCompressor/jsxgraph.css
+	rm -f JSXCompressor/jsxgraphcore.js
+	rm -f build/bin/jsxcompressor.js
+	rm -f build/bin/jsxgraphcore-min.js
+	rm -f build/bin/jsxgraphcore.min.js
+	rm -f build/bin/readers/geogebra.min.js
+	rm -f build/bin/readers/geonext.min.js
+	rm -f build/bin/readers/intergeo.min.js
+	rm -f build/bin/readers/sketch.min.js
+	rm -f distrib/geogebra.min.js
+	rm -f distrib/geonext.min.js
+	rm -f distrib/intergeo.min.js
+	rm -f distrib/jsxgraphcore.js
+	rm -f distrib/sketch.min.js
+	rm -f doc/jsdoc-tk/template/static/jsxgraph.css
+	rm -f doc/jsdoc-tk/template/static/jsxgraphcore.js
