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,12 +1,14 @@
 .PHONY: test docs core core-min prettier release lint eslint readers
 
+BUILD_DATE := $(shell dpkg-parsechangelog --show-field=Date)
+
 # Build tools
-WEBPACK=./node_modules/.bin/webpack
-MINIFYER=./node_modules/terser/bin/terser
+WEBPACK=/usr/bin/webpack
+MINIFYER=/usr/bin/terser
 
 # Code quality
 LINT=./node_modules/.bin/jslint
-ESLINT=./node_modules/eslint/bin/eslint.js
+ESLINT=/usr/share/nodejs/eslint/bin/eslint.js
 HINT=./node_modules/.bin/jshint
 KARMA=node_modules/karma/bin/karma
 PRETTIER=./node_modules/.bin/prettier
@@ -30,7 +32,7 @@ TMP=tmp
 BUILDREADERS=tmpreaders
 
 # API docs
-JSDOC2=node ./node_modules/.bin/jsdoc2
+JSDOC2=jsdoc2
 JSDOC2PLG=doc/jsdoc-tk/plugins
 JSDOC2PTCH=doc/jsdoc-tk/patches
 JSDOC2TPL=doc/jsdoc-tk/template
@@ -40,7 +42,7 @@ JSDOC2FLAGS=-v -p -t=$(JSDOC2TPL) -d=$(T
 # Flags
 MKDIRFLAGS=-p
 RMFLAGS=-rf
-ZIPFLAGS=-r
+ZIPFLAGS=-r --latest-time
 
 # Extract version number from package.json
 VERSION=$(shell grep -o '"version": "[^"]*' package.json | grep -o '[^"]*$$')
@@ -66,7 +68,14 @@ READERSOUT=tmpreaders/geonext.min.js tmp
 # tmpreaders/sketch.min.js
 
 # Rules
-all: core readers docs
+all: symlinks core .WAIT readers docs
+
+symlinks:
+	# add symlinks to replace node_modules utilities
+	#################################################
+	# replace almond
+	$(MKDIR) $(MKDIRFLAGS) node_modules/almond
+	ln -s /usr/share/nodejs/almond/almond.js node_modules/almond/
 
 core:
 	# Build uncompressed AND minified files
@@ -82,18 +91,21 @@ core:
 core-min:
 	echo "INFO: core-min deactivated. It is covered by core"
 
-release: core docs
+release: core .WAIT docs
 	$(MKDIR) $(MKDIRFLAGS) $(TMP)
 	$(CP) $(OUTPUT)/jsxgraphcore.js $(TMP)/jsxgraphcore.js
 	$(CP) $(OUTPUT)/jsxgraphsrc.js  $(TMP)/jsxgraphsrc.js
 	$(CP) $(OUTPUT)/jsxgraphcore.mjs $(TMP)/jsxgraphcore.mjs
 	$(CP) $(OUTPUT)/jsxgraphsrc.mjs  $(TMP)/jsxgraphsrc.mjs
 	$(CP) $(OUTPUT)/jsxgraph.css    $(TMP)/jsxgraph.css
-	$(CP) $(OUTPUT)/docs.zip        $(TMP)/docs.zip
+	$(CP) $(OUTPUT)/docs.tgz        $(TMP)/docs.tgz
 	$(CP) src/index.d.ts            $(TMP)/index.d.ts
 	$(CP) -r src/themes             $(TMP)/themes
 	$(CP) README.md LICENSE.MIT LICENSE.LGPL $(TMP)/
-	$(CD) $(TMP) && $(ZIP) $(ZIPFLAGS) jsxgraph.zip jsxgraph* themes/ index.d.ts docs.zip README.md LICENSE.*
+	: # make reproducible timestamps
+	find '$(TMP)' -newermt '$(BUILD_DATE)' -print0 | \
+               xargs -0r touch --no-dereference --date='$(BUILD_DATE)'
+	$(CD) $(TMP) && $(ZIP) $(ZIPFLAGS) jsxgraph.zip jsxgraph* themes/ index.d.ts docs.tgz README.md LICENSE.*
 	$(CP) $(TMP)/jsxgraph.zip $(OUTPUT)/jsxgraph.zip
 	$(RM) $(RMFLAGS) $(TMP)
 
@@ -112,7 +124,9 @@ beta: docs
 	cat COPYRIGHT $(BETA)/jsxgraphcore.js >$(BETA)/tmp.file; mv $(BETA)/tmp.file $(BETA)/jsxgraphcore.js
 	cat COPYRIGHT $(BETA)/jsxgraphcore.mjs >$(BETA)/tmp.file; mv $(BETA)/tmp.file $(BETA)/jsxgraphcore.mjs
 
-docs: core docsonly
+SOURCE_DATE := $(shell dpkg-parsechangelog --show-field=Date)
+
+docs: core .WAIT docsonly
 
 docsonly: 
 	# Set up tmp dir
@@ -120,7 +134,7 @@ docsonly:
 	$(MKDIR) $(MKDIRFLAGS) $(OUTPUT)
 
 	# Update template related files
-	$(CP) $(THIRDPARTY)/jquery.min.js $(JSDOC2TPLSTAT)/jquery.min.js
+	ln -sf /usr/share/javascript/jquery/jquery.min.js $(JSDOC2TPLSTAT)
 	$(CP) $(OUTPUT)/jsxgraphcore.js   $(JSDOC2TPLSTAT)/jsxgraphcore.js
 	$(CP) $(OUTPUT)/jsxgraph.css      $(JSDOC2TPLSTAT)/jsxgraph.css
 
@@ -128,6 +142,8 @@ docsonly:
 	sed -i '2s/.*/<h1>JSXGraph $(VERSION) Reference<\/h1>/' doc/jsdoc-tk/template/static/header.html
 
 	# Patch run.js
+	mkdir -p ./node_modules/
+	cp -a /usr/share/nodejs/jsdoc2 ./node_modules
 	$(CP) $(JSDOC2PTCH)/*.js ./node_modules/jsdoc2/app
 
 	# Update the plugin
@@ -136,13 +152,15 @@ docsonly:
 	# Run node-jsdoc2
 	$(JSDOC2) $(JSDOC2FLAGS) $(FILELIST)
 
-	# Compress the result: zip -r tmp/docs.zip tmp/docs/
-	$(CD) $(TMP) && $(ZIP) $(ZIPFLAGS) docs.zip docs/
-	$(CP) $(TMP)/docs.zip $(OUTPUT)/docs.zip
+	# Compress the result: tar czf tmp/docs.tgz tmp/docs/
+	# with a reproducible timestamp
+	$(CD) $(TMP) && \
+	  tar --clamp-mtime --mtime="$(SOURCE_DATE)" -czf docs.tgz docs/
+	$(CP) $(TMP)/docs.tgz $(OUTPUT)/docs.tgz
 	$(RM) $(RMFLAGS) tmp
 
 	# Test
-	$(CD) $(OUTPUT) && $(UNZIP) -o docs.zip
+	#$(CD) $(OUTPUT) && $(UNZIP) -o docs.zip
 
 # prettier:
 # 	$(PRETTIER) $(PRETTIERFLAGS) src
@@ -173,6 +191,41 @@ lint:
 eslint:
 	$(ESLINT) $(ESLINTFLAGS) $(LINTLIST)
 
-# test:
-test: core
-	$(KARMA) start karma/karma.conf.js
+#test: core
+#	$(KARMA) start karma/karma.conf.js
+
+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.tgz
+	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
+	rm -f JSXCompressor/jsxcompressor.min.js
+	rm -f JSXCompressor/jsxgraphcore.js
+	rm -rf distrib/docs/
+	rm -rf distrib/geogebra.min.js
+	rm -rf distrib/geonext.min.js
+	rm -rf distrib/intergeo.min.js
+	rm -rf distrib/jsxgraphcore.js
+	rm -rf distrib/sketch.min.js
+	rm -rf distrib/docs.tgz
