CONFIG_ARGS=
PREFIX=/usr/local
INSTALL_DIR=${PREFIX}/lib/felix/felix-1.1.3_rc4
EXEC_DIR=${PREFIX}/bin
MAN_DIR=${PREFIX}/man
DOC_DIR=${INSTALL_DIR}
BUILTIN_ISCR=python -O interscript/bin/iscr.py --nocache

all: lpsrc config script
	./mk extract 
	./mk --phase=build
	./mk --phase=host
	./mk --phase=target
	./mk test 

profile: dummy
	./mk --pkg=flx_compiler profile

bytecode: dummy
	./mk --pkg=flx_compiler bytecode

bytecode.profile: dummy
	./mk --pkg=flx_compiler bytecode profile

bytecode.debug: dummy
	./mk --pkg=flx_compiler bytecode debug

extract: dummy
	./mk extract

extract.force: dummy
	./mk extract force

tut: dummy
	./mk tutorial

grammar: dummy
	env PYTHONPATH=. python script/get_grammar src/flx_parse.mly >misc/flx_parse.grammar
	env PYTHONPATH=. python script/get_grammar src/cil/flx_cil_cparser.mly >misc/flx_cil_cparser.grammar
#@tangle('\tenv PYTHONPATH=. python script/elk_flx_grgen misc/flx_parse.grammar >misc/elk_flx_gr.gr')
	env PYTHONPATH=. python script/flx_flx_grgen misc/flx_parse.grammar >lib/flx_grammar.flx
#@tangle('\tenv PYTHONPATH=. python script/elk_flx_lexgen misc/flx_parse.grammar >misc/elk_flx_lex.cc')
	env PYTHONPATH=. python script/flx_tokgen misc/flx_parse.grammar >lib/flx_token.flx

compiler: dummy
	./mk --pkg=flx_compiler

flx_tools:
	./mk tools

tools: flx_tools grammar
#tools: flx_tools grammar tools/lua_parser

#tools: grammar bin/flx_doc tools/lua_parser

tools/lua_parser: tools/lua_parser.flx
	bin/flx --test --static -c tools/lua_parser

bin/flx_doc: tools/flx_doc.flx
	bin/flx --test --static -c tools/flx_doc && mv tools/flx_doc bin/flx_doc

doc: grammar tools man impldoc rtldoc tutdoc

#doc: grammar tools libdoc man impldoc tutdoc tutstyle

impldoc: dummy
	./mk doc impldoc

rtldoc: dummy
	./mk rtldoc

tutdoc: dummy
	./mk doc tutdoc
	#cp doc/*.css tut/doc >/dev/null 2>&1

doc.quiet: grammar tools libdoc
	./mk quiet doc man impldoc
	cp doc/*.css tut/doc >/dev/null 2>&1

libdoc: grammar tools
	bin/flx_doc --outdir=libdoc \
	lib/std.flx lib/stl.flx lib/flx_lex.flx \
	lib/flx_token.flx lib/flx_grammar.flx lib/lua.flx lib/lua_parse.flx
	cp misc/flxdoc_style.css libdoc

man: dummy
	./mk man

test: dummy
	./mk test 

test.flx_ptf_static_pointer: dummy
	./mk test -DFLX_PTF_STATIC_POINTER 

test.inline: dummy
	./mk inline test 

test.inline.static: dummy
	./mk inline test static 

test.debug: dummy
	./mk debug test 

test.lua_parser: dummy
	for i in misc/lua/*.lua; do tools/lua_parser $$i; done;

tests: dummy
	./mk test check_output
	make tests.bagley
	make test.lua_parser

tests.sdl: dummy
	./mk sdl
	./mk static sdl

tests.verify: dummy
	./mk test check_output

tests.static: dummy
	./mk test static log_output

tests.inline: dummy
	./mk inline test log_output

tests.performance: dummy
	./mk performance

performance: tests.performance

tests.regression: dummy
	./mk regression

tests.bagley: dummy
	sh bagley/compile.sh
	sh bagley/run.sh
	sh bagley/check.sh

speed: dummy
	./mk speed

pfcount.all:
	./mk pfcount_all

pfcount:
	./mk pfcount

rtl.debug: dummy
	./mk rtl debug

rtl: dummy
	./mk rtl

rtl.optimise: dummy
	./mk rtl optimise_c

elkhound: dummy
	./mk elkhound

expect.bagley: clean
	./mk bagley
	sh bagley/compile.sh
	sh bagley/run.sh
	env PYTHONPATH=. python script/mk_expect bagley/felix > lpsrc/flx_bagley_expect.ipk

expect: clean
	./mk bagley
	sh bagley/compile.sh
	sh bagley/run.sh
	./mk test log_output
	env PYTHONPATH=. python script/mk_expect tut/examples > lpsrc/flx_tut_expect.ipk
	env PYTHONPATH=. python script/mk_expect test > lpsrc/flx_test_expect.ipk
	env PYTHONPATH=. python script/mk_expect bagley/felix > lpsrc/flx_bagley_expect.ipk

drivers: dummy
	./mk drivers

drivers.debug: dummy

help: dummy
	#type "make virgin" to wipe out the whole development system
	#other than the orginal sources, this makefile, and any user config data
	#
	#type "make boot" to extract the dervied sources
	#from the original sources, including the tutorial
	#
	#type "make" to build the felix compiler and runtime
	#REQUIRES OCAML 3.08.1 or better
	#REQUIRES g++ 3.xx or better
	#
	#type "make test" to build and execute all the tests
	#including all the tutorial examples
	#REQUIRES Felix
	#
	#type "make doc" to typeset the original sources
	#
	#Obtain the required privileges to install into the chosen directories
	#or ask someone who has the to do it for you
	#type "make install" to install Felix

script:
	./boot

clean-src:
	rm -rf lpsrc
	rm -rf interscript
	rm -rf raw
	rm -rf gpl
	rm -rf lgpl
	rm -rf sandbox
	rm -rf boot.sh
	rm -rf boot.bat

checkout:
	svn co https://svn.sourceforge.net:/svnroot/felix/felix/trunk .

update:
	svn update



debian/rules: lpsrc/flx_debian.pak lpsrc/flx_maker.ipk
	rm -rf debian
	${BUILTIN_ISCR} lpsrc/flx_debian.pak
	chmod u+x debian/rules

debian-package: debian/rules
	(cd .. && make -f flx/Makefile.debian_package_creator package)

www: dummy
	${BUILTIN_ISCR} lpsrc/flx_sourceforge.pak

clean: dummy
	rm -rf lpsrc/*.cache
	python script/maker clean

distclean:
	rm -rf pkg tut rtl test www src misc man bin doc lib impldoc htmlman tmp tmp.tmp
	rm -rf elk tmp faio demux tmp.out demos
	rm -rf flxcc_out c89 c99 cxx gnu89 gnu99 gnucxx cxx_sys
	rm -rf bagley
	rm -rf doc_out libdoc tools doxydoc
	rm -rf meta licences
	rm -rf lpsrc/*.cache
	rm -rf interscript/*.pyo
	rm -rf interscript/*/*.pyo
	rm -rf interscript/*/*/*.pyo
	rm -rf interscript/*.pyc
	rm -rf interscript/*/*.pyc
	rm -rf interscript/*/*/*.pyc
	rm -rf speed
	rm -rf cpkgs
	rm -rf spkgs
	rm -rf pthread
	rm -rf flxbuild
	rm -rf mkplugins
	rm -rf olddebian
	rm -rf script
	rm -rf manifests
	rm -rf pkg-stamps

virgin: distclean
	cp Makefile Makefile.old
	rm -rf debian/
	rm -f README LICENCE VERSION CONTENTS INSTALL AUTHORS NEWS COPYING ChangeLog


backup: dummy
	(DATE=`date +"%Y-%m-%d-%H%M"`;\
	mkdir -p "lpbackup/$${DATE}";\
	find lpsrc -name "*.ipk" -exec cp "{}" "lpbackup/$${DATE}" ";";\
	find lpsrc -name "*.pak" -exec cp "{}" "lpbackup/$${DATE}" ";";\
	find homepage -name "*.html" -exec cp "{}" "lpbackup/$${DATE}" ";"\
	)


config: dummy
	${BUILTIN_ISCR} lpsrc/flx_config.pak
	env PYTHONPATH=. python -O script/make_config.py --quiet --prefix=${PREFIX} ${CONFIG_ARGS}

config/config.py: config

boot: config/config.py
	${BUILTIN_ISCR} lpsrc/flx_maker.pak

default_wrappers:
	for i in tmp/*.default; do cp $$i config/`basename $$i .default`; done

wrappers.clean:
	rm -rf flxcc_out c89 c99 cxx gnu89 gnu99 gnucxx cxx_sys

config/cxx.flxcc: default_wrappers

wrappers:
	bin/flxcc config/c89.flxcc
	bin/flxcc config/c99.flxcc
	bin/flxcc config/gnu89.flxcc
	bin/flxcc config/gnu99.flxcc
	bin/flxcc config/cxx.flxcc
	bin/flxcc config/cxx_sys.flxcc
	bin/flxcc config/gnucxx.flxcc
	bin/flxcc config/usr_include.flxcc

install: dummy
	install -d ${MAN_DIR}
	install -d ${INSTALL_DIR}/bin
	install -d ${INSTALL_DIR}/lib
	install -d ${INSTALL_DIR}/rtl
	install -d ${INSTALL_DIR}/config
	install -d ${DOC_DIR}/doc
	install -d ${EXEC_DIR}
	for file in `ls config/*.py` `ls config/*.fpc` `ls config/*.flxcc`; do if [ -f $$file ]; then install $$file ${INSTALL_DIR}/config; fi; done
	install bin/flx ${EXEC_DIR}
	for file in `ls bin/*`;      do if [ -f $$file ]; then install $$file ${INSTALL_DIR}/bin; fi; done
	for file in `ls rtl/*`;      do if [ -f $$file ]; then install $$file ${INSTALL_DIR}/rtl; fi; done
	for file in `ls lib/*`;      do if [ -f $$file ]; then install $$file ${INSTALL_DIR}/lib; fi; done
	for file in `ls doc/*`;      do if [ -f $$file ]; then install $$file ${DOC_DIR}/doc; fi; done
	for file in `ls man/man1/*`; do if [ -f $$file ]; then install $$file ${MAN_DIR}/man1; fi; done
	echo "Stuff in misc has to be installed by hand"


dummy:
	#Id: flx_maker.pak 1374 2007-04-13 18:40:51Z skaller 

.PHONY: dummy

#
# ============== TARBALL MAKERS AND UPLOADERS ==============
#
# ------- TARBALL MAKERS --------------
#

src_tarball: extract 
	rm -f felix-1.1.3_rc4
	ln -s . felix-1.1.3_rc4
	tar -cvf flx_1.1.3_rc4_src.tar\
		felix-1.1.3_rc4/configure \
		felix-1.1.3_rc4/mk \
		felix-1.1.3_rc4/autogen.sh \
		felix-1.1.3_rc4/*.bat \
		felix-1.1.3_rc4/Makefile \
		felix-1.1.3_rc4/README \
		felix-1.1.3_rc4/CONTENTS \
		felix-1.1.3_rc4/INSTALL \
		felix-1.1.3_rc4/VERSION \
		felix-1.1.3_rc4/LICENCE \
		felix-1.1.3_rc4/NEWS \
		felix-1.1.3_rc4/AUTHORS \
		felix-1.1.3_rc4/COPYING \
		felix-1.1.3_rc4/ChangeLog \
		felix-1.1.3_rc4/lpsrc/*.ipk \
		felix-1.1.3_rc4/lpsrc/*.pak \
		felix-1.1.3_rc4/interscript/*.py \
		felix-1.1.3_rc4/interscript/bin/*.py \
		felix-1.1.3_rc4/interscript/compilers/*.py \
		felix-1.1.3_rc4/interscript/core/*.py \
		felix-1.1.3_rc4/interscript/drivers/*.py \
		felix-1.1.3_rc4/interscript/drivers/sinks/*.py \
		felix-1.1.3_rc4/interscript/drivers/sources/*.py \
		felix-1.1.3_rc4/interscript/drivers/storage/*.py \
		felix-1.1.3_rc4/interscript/encoding/*.py \
		felix-1.1.3_rc4/interscript/frames/*.py \
		felix-1.1.3_rc4/interscript/frames/platform/*.py \
		felix-1.1.3_rc4/interscript/languages/*.py \
		felix-1.1.3_rc4/interscript/parsers/*.py \
		felix-1.1.3_rc4/interscript/tanglers/*.py \
		felix-1.1.3_rc4/interscript/tokenisers/*.py \
		felix-1.1.3_rc4/interscript/utilities/*.py \
		felix-1.1.3_rc4/interscript/weavers/*.py 
	gzip -9 flx_1.1.3_rc4_src.tar
	mv -f flx_1.1.3_rc4_src.tar.gz flx_1.1.3_rc4_src.tgz

media_tarball:
	rm -f flx_media.tgz
	tar -zcvf flx_media.tgz media

doc_tarball:
	rm -f flx_doc.tgz
	tar -zcvf flx_doc.tgz doc

speed_tarball:
	rm -f flx_speed.tgz
	tar -zcvf flx_speed.tgz speed/*.html speed/*.css speed/machine/*/images/*.jpg speed/machine/*/rankings/*.txt

#
# ------- TARBALL FILES  --------------
#
flx_media.tgz: media_tarball

flx_doc.tgz: doc_tarball

flx_speed.tgz: speed_tarball

flx_1.1.3_rc4_src.tgz: src_tarball

tarballs: flx_1.1.3_rc4_src.tgz flx_speed.tgz flx_doc.tgz flx_media.tgz

#
# ------- UPLOADERS --------------
#
#
# ******* WEB SITE MISC
#
upload_images:
	scp homepage/images/*.jpg ${USER}@felix.sf.net:/home/groups/f/fe/felix/htdocs/images

upload_homepage: dummy
	scp homepage/*.html ${USER}@felix.sf.net:/home/groups/f/fe/felix/htdocs/

upload_www: upload_homepage
	scp www/*.html ${USER}@felix.sf.net:/home/groups/f/fe/felix/htdocs/www

#
# ******* LP SOURCE TARBALL
#
upload_src: flx_1.1.3_rc4_src.tgz
	scp flx_1.1.3_rc4_src.tgz ${USER}@felix.sf.net:/home/groups/f/fe/felix/htdocs

#
# ******* MEDIA REQUIRED FOR TESTS
#
upload_media: flx_media.tgz
	scp flx_media.tgz ${USER}@felix.sf.net:/home/groups/f/fe/felix/htdocs

#
# ******* SPEED TEST TARBALL
#
upload_speed: flx_speed.tgz
	scp -r flx_speed.tgz ${USER}@felix.sf.net:/home/groups/f/fe/felix/htdocs/

#
# ******* DOC TARBALL
#
upload_docs: flx_doc.tgz
	scp -r flx_doc.tgz ${USER}@felix.sf.net:/home/groups/f/fe/felix/htdocs/

# note: media is not uploaded here because it does not change much 
upload: upload_src upload_speed upload_docs

#
# --------- UNPACKER -----------------------
#
unpack:
	ssh ${USER}@felix.sf.net "(cd /home/groups/f/fe/felix/htdocs/; tar -zxvf flx_doc.tgz; tar -zxvf flx_speed.tgz)"







