# Makefile for Hlins
#########################################################################

include ../Version

CAMLC    = @OCAMLC@
CAMLCOPT = @OCAMLOPT@
CAMLLEX  = ocamllex
CAMLDEP  = @OCAMLDEP@

# use this one for profiling
# CAMLCOPT = ocamlopt -p

# installation
BINDIR  = /usr/bin
# BINDIR = /users/demons/demons/bin/$(OSTYPE)
DESTDIR =

###########################################################################

.SUFFIXES: .cmi .cmx .cmo .ml .mli .mll

MODULES=html_chars.cmx addr_lex.cmx read_html.cmx errors.cmx names.cmx\
	 read_databases.cmx automaton.cmx build_automaton.cmx files.cmx\
	 replace.cmx dumpdb.cmx cyclic_buffer.cmx run_automaton.cmx\
	 version.cmx  hlins.cmx 

# automatic selection native / byte code
all: @BEST@

opt: hlins

byte: hlins.bc

# native code compilation
hlins: $(MODULES)
	$(CAMLCOPT) -o hlins str.cmxa unix.cmxa $(MODULES) -cclib -lstr
	strip hlins

# byte code compilation
hlins.bc: $(MODULES:.cmx=.cmo)
	$(CAMLC) -custom -o hlins.bc str.cma unix.cma $(MODULES:.cmx=.cmo)\
		 -cclib -lstr

.mli.cmi:
	$(CAMLC) -c $<

.ml.cmx:
	$(CAMLCOPT) -c $<

.ml.cmo:
	$(CAMLC) -c $<

.mll.ml:
	$(CAMLLEX) $<

clean:
	-rm -f *.cm[iox] *.o a.out\
		read_html.ml addr_lex.ml html_chars.ml version.ml 

distclean: clean
	-rm -f hlins hlins.bc gmon.out Makefile config.* *~

# automatic selectionj native/byte
install:
	if test @BEST@ = opt ; then \
                cp hlins $(DESTDIR)/$(BINDIR) ; \
        else \
                cp hlins.bc $(DESTDIR)/$(BINDIR)/hlins ; \
	fi

# for byte code
install.bc: hlins.bc
	cp hlins.bc $(DESTDIR)/$(BINDIR)/hlins

depend:
	$(CAMLDEP) *.ml *.mli > .depend

##########################################################################

include .depend

read_html.cmi: read_html.mli
read_html.ml:  read_html.mll
read_html.cmx read_html.cmo: read_html.ml read_html.cmi

addr_lex.cmi: addr_lex.mli
addr_lex.ml:  addr_lex.mll
addr_lex.cmx addr_lex.cmo: addr_lex.ml addr_lex.cmi

html_chars.cmi: html_chars.mli
html_chars.ml:  html_chars.mll
html_chars.cmx html_chars.cmo: html_chars.ml html_chars.cmi

version.ml: Makefile
	echo "let version = \""$(VERSION)"\"" > version.ml
