
help:
	@echo "Goals:"
	@echo " - plots          : Generate all questions graphs"
	@echo " - regtests       : Run the regression tests"
	@echo " - clean          : Remove not necessary files"
	@echo " - figures        : run 'make' on all 'Questions/*/HTML' dirs"
	@echo " - stats          : Statistics on the source code"
	@echo " - tar            : Make the tar.gz, and verify it"
	@echo " - load_simulator : Run a simulator to see server load"
	@echo "                    It uses real student behavior data"
	@echo " - profiling      : Profil the python functions"
	@echo "                    It uses real student behavior data"
	@echo " - simulator_plot : Compute graphics from simulator data"
	@echo "To run/configure the server, run the command: 'main.py'"

# Generate statistic graph
plots:
	for I in `cd Students ; echo *` ; \
		do echo ; echo $$I ;  main.py $$I plot ; \
	done

regtest: # Use port 34000
	Scripts/regtest.py nowait

load_simulator: # Use port 34001
	ulimit -s 512 ; \
	TIME_SLICE=300 ; \
	for NR_STUDENTS in 50 100 200 300 400 ; \
	do \
	Scripts/load_simulator.py \
		$$NR_STUDENTS \
		$$TIME_SLICE \
		Students/L2unix2006s1/Logs \
		Questions/unix \
		1 0 34001 load_simulator \
		 >Stats/load_simulator.$$NR_STUDENTS.$$TIME_SLICE.unix ; \
	done

profiling: # Use port 34002
	ulimit -s 512 ; \
	TIME_SLICE=300 ; \
	NR_STUDENTS=50 ; \
	QUESTIONS=unix ; \
	Scripts/load_simulator.py \
		$$NR_STUDENTS \
		$$TIME_SLICE \
		Students/L2unix2006s1/Logs \
		Questions/$$QUESTIONS \
		100 `expr $$NR_STUDENTS '*' 1` 34002 profiling ; \
	awk '/primitive calls/ { T=1 ; } T == 1 { print $$0 ; }' \
		<Students/profiling/logs \
		>Stats/profiling.$$NR_STUDENTS.$$QUESTIONS

simulator_plot:
	# Scripts/simulator_plot 0.fixed_ttl
	Scripts/simulator_plot 1.variable_ttl
	Scripts/simulator_plot 2.caches_answerable_action

clean:
	find . -name 'xxx*' -o -name '*~' -o -name '*.pyc' \
		-o -name 'nohup.out' | xargs rm -f
	# -rm -r Students/profiling Students/regtest

figures:
	for I in HTML Questions/*/HTML ; do ( cd $$I ; $(MAKE) ) ; done

stat:
	@echo 'Python lines Quenlig : ' `cat *.py | wc -l`
	@echo 'Python lines Unix    : ' `cat Questions/unix/*.py | wc -l`
	@echo 'Python lines Python  : ' `cat Questions/python/*.py | wc -l`
	@echo 'Python lines regtest : ' `cat Scripts/regtest.py | wc -l`
	@echo 'CSS lines            : ' `cat HTML/*.css | wc -l`
	@echo 'Doc HTML             : ' `wc -l <Welcome.html`

MEDIA=/usbmem
tar:clean
	A=$$(basename $$(pwd)) ; \
	A=$$(basename $$(pwd)) ; \
	echo '# See "Scripts//nom_prenom" for help' >real_names.py ; \
	echo 'real_names = {"loginName": ("Surname","Firstname", "admin@mail"),}' >>real_names.py ; \
	cd .. ; \
	tar --exclude='Students' \
	    --exclude='*.pyc' \
	    --exclude='PyChart*' \
            -cvf - $$A | \
	gzip >~/public_html/QUENLIG/$$A.tar.gz ; \
	cd ~/public_html/QUENLIG ; ls -lsh ; \
	mkdir /tmp/XXX-$$A ; cd /tmp/XXX-$$A ; \
	zcat ~/public_html/QUENLIG/$$A.tar.gz | tar -xvf - ; \
	cd $$A ; \
	make regtest ; \
	cd ; \
	rm -r /tmp/XXX-$$A
