# To run this makefile, you must do the following.
#
# 1.)  Download http://closure-compiler.googlecode.com/files/compiler-latest.zip
#      and place compiler.jar within the tools directory.
#
# 2.)  Install closure-linter tool at by following
#      http://code.google.com/closure/utilities/docs/linter_howto.html
#
# 3.)  Download the JSDoc toolkit found at
#      http://code.google.com/p/jsdoc-toolkit and place the jsdoc-toolkit
#      directory within the tools directory.

# Create the list of files
files =   src/minplayer.compatibility.js\
          src/minplayer.async.js\
          src/minplayer.flags.js\
          src/minplayer.plugin.js\
          src/minplayer.display.js\
          src/minplayer.js\
          src/minplayer.image.js\
          src/minplayer.file.js\
          src/minplayer.playLoader.js\
          src/minplayer.players.base.js\
          src/minplayer.players.html5.js\
          src/minplayer.players.flash.js\
          src/minplayer.players.minplayer.js\
          src/minplayer.players.youtube.js\
          src/minplayer.players.vimeo.js\
          src/minplayer.controller.js

.DEFAULT_GOAL := all

all: jslint js jsdoc

# Perform a jsLint on all the files.
jslint: ${files}
	gjslint $^

# Create an aggregated js file and a compressed js file.
js: ${files}
	@echo "Generating aggregated bin/minplayer.js file"
	@cat > bin/minplayer.js $^
	@echo "Generating compressed bin/minplayer.compressed file"
	curl -s \
	  -d compilation_level=SIMPLE_OPTIMIZATIONS \
	  -d output_format=text \
	  -d output_info=compiled_code \
	  --data-urlencode "js_code@bin/minplayer.js" \
	  http://closure-compiler.appspot.com/compile \
	  > bin/minplayer.compressed.js

# Create the documentation from source code.
jsdoc: ${files}
	@echo "Generating documetation."
	@java -jar tools/jsdoc-toolkit/jsrun.jar tools/jsdoc-toolkit/app/run.js -a -t=tools/jsdoc-toolkit/templates/jsdoc -d=doc $^

# Fix the js style on all the files.
fixjsstyle: ${files}
	fixjsstyle $^

# Install the necessary tools.
tools:
	wget http://jsdoc-toolkit.googlecode.com/files/jsdoc_toolkit-2.4.0.zip -P tools
	unzip tools/jsdoc_toolkit-2.4.0.zip -d tools
	mv tools/jsdoc_toolkit-2.4.0/jsdoc-toolkit tools/jsdoc-toolkit
	rm -rd tools/jsdoc_toolkit-2.4.0
	rm tools/jsdoc_toolkit-2.4.0.zip
