## Configuration
CPP=/lib/cpp -P -Dunix

# Where mletags will live
BINDIR=/usr/local/bin

# Where the man page will sleep
MANEXT=1
MANDIR=/usr/man/man$(MANEXT)

## End of configuration

CAMLCOMP=camlc -c
CAMLLEX=camllex
CAMLYACC=camlyacc

COMPFLAGS=-O fast
LINKFLAGS=-g

OBJS=lexer.zo parser.zo main.zo

mletags: $(OBJS)
	camlc -o mletags  $(OBJS)

lexer.mll: lexer.mlp
	$(CPP) lexer.mlp > lexer.mll

lexer.ml: lexer.mll
	$(CAMLLEX) lexer.mll

parser.ml parser.mli: parser.mly
# 	$(CAMLYACC) parser.mly
	$(CAMLYACC) -s parser.mly

clean:
	rm -f *.z? mletags 

scratch: clean
	rm -f lexer.ml lexer.mll parser.ml parser.mli

distrib: main.ml parser.mly lexer.mlp tags.mli Makefile mletags.man INSTALL
	tar cf mletags.tar main.ml parser.mly lexer.mlp tags.mli Makefile mletags.man INSTALL
	compress mletags.tar

install: mletags mletags.man
	cp mletags $(BINDIR)
	cp mletags.man $(MANDIR)/mletags.$(MANEXT)

TAGS:
	mletags *.ml *.mli

.SUFFIXES :
.SUFFIXES : .mli .ml .zi .zo .mlp

.mli.zi:
	$(CAMLCOMP) $(COMPFLAGS) $<

.ml.zo:
	$(CAMLCOMP) $(COMPFLAGS) $<

.mlp.ml:
	@rm -f $@
	$(CPP) $< > $@
	@chmod a-w $@

depend: lexer.ml parser.ml parser.mli
	mv Makefile Makefile.bak
	(sed -n -e '1,/^### DO NOT DELETE THIS LINE/p' Makefile.bak; \
         camldep *.mli *.ml) > Makefile

### EVERYTHING THAT GOES BEYOND THIS COMMENT IS GENERATED
### DO NOT DELETE THIS LINE
parser.zi: tags.zi 
lexer.zo: parser.zi 
main.zo: parser.zi lexer.zo tags.zi 
parser.zo: parser.zi lexer.zo tags.zi 
