#
# Warning: this is not so much a typical Makefile as it is a set of
# abbreviations for a number of commands that I wanted to make sure
# work reproducibly.  Designed for Ubuntu, may require tailoring to
# work elsewhere.
#

all: static viewServer/javascript db_root

viewServer/javascript:
	svn checkout http://couchdb.googlecode.com/svn/trunk/src/js tmp-js
	mkdir -p viewServer/javascript
	mv tmp-js/json.js tmp-js/main.js tmp-js/.svn viewServer/javascript
	rm -rf tmp-js

static:
	svn checkout http://couchdb.googlecode.com/svn/trunk/dist/common/ht_utils static

db_root:
	mkdir db_root

update:
	cd static; svn up
	cd viewServer/javascript; svn up *.js

compdemo: viewServer/javascript
	-curl -s -X QUIT http://localhost:8080/
	gnome-terminal -t basura -e "python server.py"
	sleep 1
	ruby compdemo.rb

httptest.beam: httptest.erl
	erlc httptest.erl

httptest: httptest.beam
	-curl -s -X QUIT http://localhost:8080/
	gnome-terminal -t basura -e "python server.py"
	sleep 1
	erl -noshell -s httptest main http://localhost:8080/

lostupdate:
	-curl -s -X QUIT http://localhost:8080/
	gnome-terminal -t basura -e "python server.py"
	sleep 1
	python lostupdate.py http://localhost:8080/

clean:
	rm -f viewServer/javascript/main.js viewServer/javascript/json.js
	rm -rf viewServer/javascript/.svn
	test ! -d viewServer/javascript || rmdir -p viewServer/javascript
	rm -f *.pyc basura/*.pyc erl_crash.dump *.beam
	cd static; (for file in couch.js couch_tests.html couch_tests.js favicon.ico json.js shell.html .svn; do rm -rf $$file; done)
	test ! -d static || rmdir -p static
	rm -rf db_root
