

# make            - makes everything
# make clean      - can be done after a make, removes tempoary files
#                   but not the compiled application
# make very_clean - total cleanup
# make publish    - publish the result
# make install    - copies ecc and elink to /usr/local/bin
#                   and all the .lib files to
#                   /usr/local/lib/erlsae 
#                   (need to be root to do this)
# Makefile by  joe.armstrong@telia.com

.SUFFIXES: .beam .erl .lib

../ebin/%.beam: %.erl
	erlc -o../ebin $<   

ERL = demand_prim.erl ecc.erl elink.erl epp_hacked.erl  \
      fake_demand_code.erl fake_demand_init.erl         \
      file_prim.erl find.erl mk_lib.erl pds.erl

## These library files need packaging

LIBS = stdlib kernel compiler demand	

all: ${ERL:%.erl=../ebin/%.beam} ${LIBS:%=../dist/%.lib} ecc elink

ecc: ../dist/ecc

elink: ../dist/elink

../dist/elink: ../ebin/elink.beam
	erl -noshell -pa ../ebin -s elink make_elink -s erlang halt
	mv elink ../dist/elink

../dist/ecc: ../ebin/ecc.beam ../ebin/pds.beam ../ebin/demand_prim.beam\
             ../ebin/file_prim.beam ../dist/demand.lib
	erl -noshell -pa ../ebin -s ecc make_ecc -s erlang halt
	mv ecc ../dist/ecc

../dist/stdlib.lib: ../ebin/epp_hacked.beam
	erl -noshell -pa ../ebin -s mk_lib pack stdlib -s erlang halt
#	Patch epp_hacked.beam into stdlib.lib
	erl -noshell -pa ../ebin -s ecc patch_stdlib -s erlang halt

../dist/kernel.lib:
	erl -noshell -pa ../ebin -s mk_lib pack kernel -s erlang halt

../dist/compiler.lib:
	erl -noshell -pa ../ebin -s mk_lib pack compiler -s erlang halt

../dist/demand.lib: ../ebin/fake_demand_init.beam          \
                    ../ebin/fake_demand_code.beam          \
                    ../ebin/pds.beam                       \
                    ../ebin/file_prim.beam                 \
                    ../ebin/demand_prim.beam
	erl -noshell -pa ../ebin -s demand_prim mk_demand_lib -s erlang halt

clean:
	rm -f ../ebin/* *~ erl_crash.dump core

very_clean:
	make clean
	rm -f ../../sae-3.0.tgz
	cd ../examples; make clean
	rm -f ../ebin/*
	rm -f ../dist/*

install: all
	if test ! -d /usr/local/bin ; then /usr/bin/install -c -d /usr/local/bin; fi
	cp ../dist/ecc ../dist/elink /usr/local/bin
	/usr/bin/install -c -d /usr/local/lib/erlsae 
	cp ../dist/*.lib /usr/local/lib/erlsae

## Publish the program


publish: ../../sae-3.0.tgz ../sae.html
	mv ../../sae-3.0.tgz /home/joe/sites/erlang_journal/sae-3x0.tgz
	cp ../sae.html /home/joe/sites/erlang_journal

../../sae-3.0.tgz:
	make very_clean
	cd ../..; tar cvf - sae-3.0 | gzip >sae-3.0.tgz
















