# $Id: Makefile,v 1.6 2001/10/02 23:25:20 ddr Exp $

include ../config/Makefile

SHELL=/bin/sh

INCLUDES=-I ../odyl -I ../boot -I $(OTOP)/utils -I $(OTOP)/parsing -I $(OTOP)/otherlibs/dynlink
OCAMLCFLAGS=$(INCLUDES)
LINKFLAGS=$(INCLUDES)
INTERFACES=-I $(OLIBDIR) Arg Array Buffer Callback Char Digest Filename Format Gc Genlex Hashtbl Lazy Lexing List Map Marshal Obj Oo Parsing Pervasives Printexc Printf Queue Random Set Sort Stack Stream String Sys Weak -I ../boot Extfun Fstream Gramext Grammar Plexer Stdpp Token -I $(OTOP)/utils Config Warnings -I $(OTOP)/parsing Asttypes Location Longident Parsetree -I . Ast2pt MLast Pcaml Quotation Spretty
CAMLP4_INTF=$(OTOP)/utils/config.cmi $(OTOP)/utils/warnings.cmi $(OTOP)/parsing/asttypes.cmi $(OTOP)/parsing/location.cmi $(OTOP)/parsing/longident.cmi $(OTOP)/parsing/parsetree.cmi ast2pt.cmo mLast.cmi pcaml.cmi spretty.cmi quotation.cmi
CAMLP4_OBJS=../boot/stdpp.cmo ../boot/token.cmo ../boot/plexer.cmo ../boot/gramext.cmo ../boot/grammar.cmo ../boot/extfun.cmo ../boot/fstream.cmo $(OTOP)/utils/config.cmo quotation.cmo ast2pt.cmo spretty.cmo reloc.cmo pcaml.cmo argl.cmo crc.cmo
CAMLP4_XOBJS=../lib/stdpp.cmx ../lib/token.cmx ../lib/plexer.cmx ../lib/gramext.cmx ../lib/grammar.cmx ../lib/extfun.cmx ../lib/fstream.cmx $(OTOP)/utils/config.cmx quotation.cmx ast2pt.cmx spretty.cmx reloc.cmx pcaml.cmx argl.cmx
OBJS=../odyl/odyl.cma camlp4.cma
CAMLP4M=

CAMLP4=camlp4$(EXE)
CAMLP4OPT=phony

all: $(CAMLP4)
opt: $(OBJS:.cma=.cmxa)
optp4: $(CAMLP4OPT)

$(CAMLP4): $(OBJS) ../odyl/odyl.cmo
	$(OCAMLC) $(OBJS) $(CAMLP4M) ../odyl/odyl.cmo -linkall -o $(CAMLP4)

$(CAMLP4OPT): $(OBJS:.cma=.cmxa) ../odyl/odyl.cmx
	$(OCAMLOPT) $(OBJS:.cma=.cmxa) $(CAMLP4M) ../odyl/odyl.cmx -linkall -o $(CAMLP4OPT)

$(OTOP)/utils/config.cmx: $(OTOP)/utils/config.ml
	$(OCAMLOPT) -c $(OTOP)/utils/config.ml

camlp4.cma: $(CAMLP4_OBJS)
	$(OCAMLC) $(LINKFLAGS) $(CAMLP4_OBJS) -a -o camlp4.cma

camlp4.cmxa: $(CAMLP4_XOBJS)
	$(OCAMLOPT) $(LINKFLAGS) $(CAMLP4_XOBJS) -a -o camlp4.cmxa

crc.cmo: $(CAMLP4_INTF)
	@OTOP=$(OTOP) EXE=$(EXE) ../tools/extract_crc.sh $(INTERFACES) > crc.ml
	echo "let _ = Dynlink.add_available_units crc_unit_list" >> crc.ml
	$(OCAMLC) $(OCAMLCFLAGS) -c crc.ml

clean::
	rm -f *.cm* *.pp[io] *.o *.bak .*.bak *.out *.opt
	rm -f $(CAMLP4) crc.ml

depend:
	cp .depend .depend.bak
	> .depend
	@for i in *.mli *.ml; do \
	  ../tools/apply.sh pr_depend.cmo -- $$i >> .depend; \
	done

promote:
	cp $(CAMLP4) ../boot/.

compare:
	@for j in $(CAMLP4); do \
		if cmp $$j ../boot/$$j; then :; else exit 1; fi; \
	done

install:
	-$(MKDIR) $(BINDIR)
	cp $(CAMLP4) $(BINDIR)/.
	cp mLast.mli quotation.mli pcaml.mli spretty.mli $(LIBDIR)/.
	cp mLast.cmi quotation.cmi ast2pt.cmi pcaml.cmi spretty.cmi $(LIBDIR)/.
	cp camlp4.cma $(LIBDIR)/.

include .depend
