#
# Note:
#    This makefile requires that you specify a FLEX_SDK_HOME environment
#    variable which points to the flex sdk you wish to build with. The default
#    location for this is ~/usr/local/flex/4.1.0
#    


VERSION=2-0-4a

DATE:=`date +"%Y-%m-%d.%H-%M"`

MXMLC=./fcsh-wrap
REAL_MXMLC=mxmlc

FLEX_SDK:=4.1.0
FLEX_SDK_HOME?=~/local/flex/$(FLEX_SDK)
PATH:=${FLEX_SDK_HOME}/bin:${PATH}
LD_LIBRARY_PATH:=${FLEX_SDK_HOME}/lib:${LD_LIBRARY_PATH}

TARGET_MAJOR_VERSION=10
TARGET_MINOR_VERSION=1
TARGET_LOCALE=en_US

LIB_PATHS=${FLEX_SDK_HOME}/frameworks/libs \
		  ${FLEX_SDK_HOME}/frameworks/libs/player \
		  ${FLEX_SDK_HOME}/frameworks/libs/player/$(TARGET_MAJOR_VERSION) \
		  ${FLEX_SDK_HOME}/frameworks/locale/$(TARGET_LOCALE) 



all: ensure_installed city_planner.swf

ensure_installed:
	@if [ ! -e $(FLEX_SDK_HOME)/bin/mxmlc ]; then \
		echo "Please setup your FLEX_SDK_HOME env variable."; \
		echo "$(FLEX_SDK_HOME)/bin/mxmlc doesn't exist."; \
		echo "Failed to find flex installation."; \
		test 0 = 1; \
	fi


city_planner.swf: 
	@echo Compiling $< 
	time $(MXMLC) \
		main.mxml \
		-compiler.incremental=true \
		-compiler.optimize=false \
		-compiler.debug=true \
		-compiler.theme \
			${FLEX_SDK_HOME}/frameworks/themes/Halo/halo.swc \
			${FLEX_SDK_HOME}/frameworks/themes/Spark/spark.css \
			main.css \
		-warnings=true \
		-target-player $(TARGET_MAJOR_VERSION).$(TARGET_MINOR_VERSION).0 \
		-load-config ${FLEX_SDK_HOME}/frameworks/flex-config.xml \
		-output $@
	cp city_planner.swf ../server/city_planner/static/city_planner.swf
	cp city_planner.swf ../site/city_planner-$(VERSION).swf
	sync

city_planner_opt.swf: 
	@echo Compiling $< 
	time $(REAL_MXMLC) \
		main.mxml \
		-compiler.incremental=false \
		-compiler.optimize=true \
		-compiler.debug=false \
		-compiler.theme \
			${FLEX_SDK_HOME}/frameworks/themes/Halo/halo.swc \
			main.css \
		-warnings=true \
		-target-player $(TARGET_MAJOR_VERSION).$(TARGET_MINOR_VERSION).0 \
		-load-config ${FLEX_SDK_HOME}/frameworks/flex-config.xml \
		-output $@
	cp city_planner_opt.swf ../server/city_planner/static/city_planner.swf
	cp city_planner_opt.swf ../site/city_planner-$(VERSION).swf
	sync


opt: city_planner_opt.swf


clean:
	killall -9 fcsh-wrap || true
	rm -f *.swf *.cache .FW.pid.*
	rm -f ../site/*.swf

doc:
	asdoc -source-path . -doc-sources .


.PHONY: package pkg self run doc darknite
.PHONY: city_planner.swf city_planner_opt.swf opt clean doc all
