CONFIG_ARGS=
PREFIX=/usr
LIB_DIR=${PREFIX}/lib
SHLIB_DIR=${PREFIX}/rtl
SHINC_DIR=${PREFIX}/include
INSTALL_DIR=${PREFIX}/lib/felix
EXEC_DIR=${PREFIX}/bin
MAN_DIR=${PREFIX}/man
BUILTIN_ISCR=python -O interscript/bin/iscr.py --nocache

all: dummy
	python script/maker extract compiler rtl elkhound drivers optimise_c
	#make tools libdoc
	python script/maker clean test log_output stop_on_error check_output
	python script/maker clean test static log_output stop_on_error check_output
	python script/maker clean test optimise_c inline log_output stop_on_error check_output
	python script/maker clean test optimise_c inline static log_output stop_on_error check_output
	sh bagley/compile.sh
	sh bagley/run.sh
	sh bagley/check.sh


all.quiet: dummy
	python script/maker quiet extract compiler rtl elkhound drivers test log_output stop_on_error check_output optimise_c
	make tools libdoc


profile: dummy
	python script/maker compiler profile

bytecode: dummy
	python script/maker compiler bytecode

bytecode.profile: dummy
	python script/maker compiler bytecode profile

bytecode.debug: dummy
	python script/maker compiler bytecode debug

extract_compiler: dummy
	${BUILTIN_ISCR} lpsrc/flx.pak
	python script/maker compiler

extract: dummy
	python script/maker extract

extract.force: dummy
	python script/maker extract force

tut: dummy
	python script/maker tutorial

grammar: dummy
	env PYTHONPATH=. python script/get_grammar src/flx_parse.mly >misc/flx_parse.grammar
	env PYTHONPATH=. python script/get_grammar src/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
	python script/maker compiler

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 tutdoc

#doc: grammar tools libdoc man impldoc tutdoc tutstyle

impldoc: dummy
	python script/maker doc impldoc

tutdoc: dummy
	python script/maker doc tutdoc
	cp doc/*.css tut/doc >/dev/null 2>&1

doc.quiet: grammar tools libdoc
	python script/maker 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
	python script/maker man

test: dummy
	python script/maker test stop_on_error check_output
	sh bagley/compile.sh
	sh bagley/run.sh
	sh bagley/check.sh

test.static: dummy
	python script/maker test static stop_on_error

test.flx_ptf_static_pointer: dummy
	python script/maker test -DFLX_PTF_STATIC_POINTER stop_on_error

test.inline: dummy
	python script/maker inline test stop_on_error

test.inline.static: dummy
	python script/maker inline test static stop_on_error

test.debug: dummy
	python script/maker debug test stop_on_error

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

tests: dummy
	python script/maker test check_output
	make tests.bagley
	make test.lua_parser

tests.verify: dummy
	python script/maker test check_output

tests.static: dummy
	python script/maker test static log_output

tests.inline: dummy
	python script/maker inline test log_output

tests.performance: dummy
	python script/maker performance

performance: tests.performance

tests.regression: dummy
	python script/maker regression

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

speed: dummy
	python script/maker speed

pfcount.all:
	python script/maker pfcount_all

pfcount:
	python script/maker pfcount

rtl.debug: dummy
	python script/maker rtl debug

rtl: dummy
	python script/maker rtl

rtl.optimise: dummy
	python script/maker rtl optimise_c

elkhound: dummy
	python script/maker elkhound

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

expect: clean
	python script/maker bagley
	sh bagley/compile.sh
	sh bagley/run.sh
	python script/maker 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
	python script/maker drivers

drivers.debug: dummy
	python script/maker drivers debug

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 priviledges to install into the chosen directories
	#or ask someone who has the to do it for you
	#type "make install" to install Felix


src_tarball: extract 
	rm -f felix-1.1.1_rc1
	ln -s . felix-1.1.1_rc1
	tar -cvf flx_1.1.1_rc1_src.tar\
		felix-1.1.1_rc1/configure \
		felix-1.1.1_rc1/win32env.bat \
		felix-1.1.1_rc1/win32iscr.bat \
		felix-1.1.1_rc1/win32make.bat \
		felix-1.1.1_rc1/win32config.bat \
		felix-1.1.1_rc1/Makefile \
		felix-1.1.1_rc1/README \
		felix-1.1.1_rc1/CONTENTS \
		felix-1.1.1_rc1/INSTALL \
		felix-1.1.1_rc1/VERSION \
		felix-1.1.1_rc1/LICENCE \
		felix-1.1.1_rc1/NEWS \
		felix-1.1.1_rc1/AUTHORS \
		felix-1.1.1_rc1/COPYING \
		felix-1.1.1_rc1/ChangeLog \
		felix-1.1.1_rc1/lpsrc/*.ipk \
		felix-1.1.1_rc1/lpsrc/*.pak \
		felix-1.1.1_rc1/interscript/*.py \
		felix-1.1.1_rc1/interscript/bin/*.py \
		felix-1.1.1_rc1/interscript/compilers/*.py \
		felix-1.1.1_rc1/interscript/core/*.py \
		felix-1.1.1_rc1/interscript/drivers/*.py \
		felix-1.1.1_rc1/interscript/drivers/sinks/*.py \
		felix-1.1.1_rc1/interscript/drivers/sources/*.py \
		felix-1.1.1_rc1/interscript/drivers/storage/*.py \
		felix-1.1.1_rc1/interscript/encoding/*.py \
		felix-1.1.1_rc1/interscript/frames/*.py \
		felix-1.1.1_rc1/interscript/frames/platform/*.py \
		felix-1.1.1_rc1/interscript/languages/*.py \
		felix-1.1.1_rc1/interscript/parsers/*.py \
		felix-1.1.1_rc1/interscript/tanglers/*.py \
		felix-1.1.1_rc1/interscript/tokenisers/*.py \
		felix-1.1.1_rc1/interscript/utilities/*.py \
		felix-1.1.1_rc1/interscript/weavers/*.py 
	gzip -9 flx_1.1.1_rc1_src.tar
	mv -f flx_1.1.1_rc1_src.tar.gz flx_1.1.1_rc1_src.tgz

bin_tarball:
	rm -f felix-1.1.1_rc1
	ln -s . felix-1.1.1_rc1
	tar -zcvf flx_1.1.1_rc1_share.tgz\
		felix-1.1.1_rc1/configure\
		felix-1.1.1_rc1/Makefile\
		felix-1.1.1_rc1/README \
		felix-1.1.1_rc1/CONTENTS \
		felix-1.1.1_rc1/INSTALL \
		felix-1.1.1_rc1/VERSION \
		felix-1.1.1_rc1/LICENCE \
		felix-1.1.1_rc1/NEWS \
		felix-1.1.1_rc1/AUTHORS \
		felix-1.1.1_rc1/COPYING\
		felix-1.1.1_rc1/ChangeLog \
		felix-1.1.1_rc1/lpsrc/*.ipk \
		felix-1.1.1_rc1/lpsrc/*.pak \
		felix-1.1.1_rc1/script/maker \
		felix-1.1.1_rc1/script/*\
		felix-1.1.1_rc1/src/*.ml \
		felix-1.1.1_rc1/src/*.mli \
		felix-1.1.1_rc1/src/*.mly \
		felix-1.1.1_rc1/src/*.mll \
		felix-1.1.1_rc1/tools/*.flx \
		felix-1.1.1_rc1/rtl/*.cpp\
		felix-1.1.1_rc1/rtl/*.hpp\
		felix-1.1.1_rc1/lib/*.flx \
		felix-1.1.1_rc1/test/*.flx \
		felix-1.1.1_rc1/test/*.cpp \
		felix-1.1.1_rc1/test/*.expect \
		felix-1.1.1_rc1/tut/examples/*.flx \
		felix-1.1.1_rc1/tut/examples/*.expect \
		felix-1.1.1_rc1/tut/doc/*.html \
		felix-1.1.1_rc1/tut/doc/*.css \
		felix-1.1.1_rc1/tut/doc/*.tex \
		felix-1.1.1_rc1/doc/*.html \
		felix-1.1.1_rc1/doc/*.css \
		felix-1.1.1_rc1/doc/*.tex \
		felix-1.1.1_rc1/licences/*.txt \
		felix-1.1.1_rc1/misc/* \
		felix-1.1.1_rc1/htmlman/*.html \
		felix-1.1.1_rc1/man/man1/*.1 \
		felix-1.1.1_rc1/impldoc/*.html \
		felix-1.1.1_rc1/www/*.html \
		felix-1.1.1_rc1/bin/flx \
		felix-1.1.1_rc1/speed/*.py \
		felix-1.1.1_rc1/speed/*.html \
		felix-1.1.1_rc1/speed/*.css \
		felix-1.1.1_rc1/speed/*.gpl \
		felix-1.1.1_rc1/speed/images/rosella/*.jpg \
		felix-1.1.1_rc1/interscript/*.py \
		felix-1.1.1_rc1/interscript/bin/*.py \
		felix-1.1.1_rc1/interscript/compilers/*.py \
		felix-1.1.1_rc1/interscript/core/*.py \
		felix-1.1.1_rc1/interscript/drivers/*.py \
		felix-1.1.1_rc1/interscript/drivers/sinks/*.py \
		felix-1.1.1_rc1/interscript/drivers/sources/*.py \
		felix-1.1.1_rc1/interscript/drivers/storage/*.py \
		felix-1.1.1_rc1/interscript/encoding/*.py \
		felix-1.1.1_rc1/interscript/frames/*.py \
		felix-1.1.1_rc1/interscript/frames/platform/*.py \
		felix-1.1.1_rc1/interscript/languages/*.py \
		felix-1.1.1_rc1/interscript/parsers/*.py \
		felix-1.1.1_rc1/interscript/tanglers/*.py \
		felix-1.1.1_rc1/interscript/tokenisers/*.py \
		felix-1.1.1_rc1/interscript/utilities/*.py \
		felix-1.1.1_rc1/interscript/weavers/*.py \

tarball: src_tarball bin_tarball

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 tut/examples/*.cpp tut/examples/*.hpp tut/examples/*.so tut/examples/*.dll tut/examples/*.par tut/examples/*.o tut/examples/*.output
	rm -rf test/*.cpp test/*.hpp test/*.so test/*.dll test/*.par test/*.o test/*.output
	rm -rf bagley/felix/*.cpp bagley/felix/*.hpp bagley/felix/*.so bagley/felix/*.dll bagley/felix/*.par bagley/felix/*.o
	rm -rf speed/exes/*

distclean:
	rm -rf tut rtl test www src misc man bin doc lib impldoc htmlman tmp tmp.tmp
	rm -rf elk
	rm -rf flxcc_out c89 c99 cxx gnu89 gnu99 gnucxx cxx_sys
	rm -rf bagley
	rm -rf doc_out libdoc tools
	rm -rf meta licences
	rm -rf lpsrc/*.cache
	rm -rf interscript/*.pyo
	rm -rf interscript/*/*.pyo
	rm -rf interscript/*/*/*.pyo
	rm -rf speed/

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


backup: dummy
	(DATE=`date -I`;\
	mkdir -p "lpbackup/$${DATE}";\
	cp lpsrc/*.ipk "lpbackup/$${DATE}";\
	cp lpsrc/*.pak "lpbackup/$${DATE}";\
	cp homepage/*.html "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.pak
	cp src/flx_cil_machdep_type.mli src/flx_cil_machdep_type.ml
	cp src/flx_cil_cabs.mli src/flx_cil_cabs.ml
	cp src/flx_ast.mli src/flx_ast.ml
	cp src/flx_types.mli src/flx_types.ml
	cp src/flx_ctypes.mli src/flx_ctypes.ml

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_DIR=${INSTALL_DIR}"
	#"EXEC_DIR=${EXEC_DIR}"
	#"MAN_DIR=${MAN_DIR}"
	#"SHLIB_DIR=${SHLIB_DIR}"
	#"LIB_DIR=${LIB_DIR}"
	#"SHINC_DIR=${SHINC_DIR}"
	install -d ${MAN_DIR}
	install -d ${SHLIB_DIR}
	install -d ${LIB_DIR}
	install -d ${SHINC_DIR}
	install -d ${INSTALL_DIR}/lib
	install -d ${INSTALL_DIR}/rtl
	install -d ${INSTALL_DIR}/config
	install -d ${INSTALL_DIR}/doc
	install -d ${INSTALL_DIR}/htmlman
	install config/*.py ${INSTALL_DIR}/config
	install config/*.flxcc ${INSTALL_DIR}/config
	install lib/* ${INSTALL_DIR}/lib
	install rtl/*.hpp ${SHINC_DIR}
	install rtl/* ${INSTALL_DIR}/rtl
	ranlib  ${INSTALL_DIR}/rtl/libflx_static.a
	install rtl/libflx_static.a ${LIB_DIR}
	ranlib  ${LIB_DIR}/libflx_static.a
	install rtl/libflx_dynamic.so.1.1.1_rc1 ${SHLIB_DIR}
	install rtl/libflx_dynamic.so.1 ${SHLIB_DIR}
	install rtl/libflx_dynamic.so ${SHLIB_DIR}
	(install doc/* ${INSTALL_DIR}/doc || exit 0) > /dev/null 2>&1
	(install impldoc/* ${INSTALL_DIR}/impldoc || exit 0) > /dev/null 2>&1
	(install htmlman/* ${INSTALL_DIR}/htmlman || exit 0) > /dev/null 2>&1
	install bin/* ${EXEC_DIR}
	(install man/man1/* ${MAN_DIR}/man1 || exit 0) > /dev/null 2>&1
	echo "Stuff in misc has to be installed by hand"


dummy:
	#Id: flx_maker.ipk,v 1.172 2005/10/29 05:48:20 skaller Exp 

# These targets are for SKALLER only
# they're used to upload stuff to sourceforge
upload_images:
	scp homepage/images/*.jpg skaller@felix.sf.net:/home/groups/f/fe/felix/htdocs/images

upload_homepage: dummy
	scp homepage/*.html skaller@felix.sf.net:/home/groups/f/fe/felix/htdocs/

upload_www: upload_homepage
	scp www/*.html skaller@felix.sf.net:/home/groups/f/fe/felix/htdocs/current/www

upload_src: dummy
	scp flx_1.1.1_rc1_src.tgz skaller@felix.sf.net:/home/groups/f/fe/felix/htdocs

upload_speed: dummy
	scp -r speed/*.html speed/images skaller@felix.sf.net:/home/groups/f/fe/felix/htdocs/current/speed

upload: dummy
	scp flx_1.1.1_rc1_src.tgz skaller@felix.sf.net:/home/groups/f/fe/felix/htdocs
	scp flx_1.1.1_rc1_share.tgz skaller@felix.sf.net:/home/groups/f/fe/felix/htdocs


