# $Id: Makefile,v 1.5 2004/02/23 18:03:37 kwxm Exp $

# All ocaml source files here are copied from the ASDL source directory
# The makefile creates a local symbolic link to the src directory,  then
# copies the source files into the current directory and compiles them.
# [So you can start with a directory containing nothing but the makefile]
# Dependencies must now be generated manually via "make depend"

OCAMLC=ocamlc
OCAMLOPT=ocamlopt
OCAMLLEX=ocamllex
OCAMLYACC=ocamlyacc
OCAMLDEP=ocamldep
INCLUDES=-nolabels                 # add all options here
OCAMLFLAGS=$(INCLUDES)              # add other options for ocamlc here
OCAMLOPTFLAGS=$(INCLUDES)           # add other options for ocamlopt here

# order matters to ocamlc and ocamlopt ...
#ML=$(shell ls *.ml)
ML=stdPrims.ml assertions_ASDL.ml camelot_absyn_ASDL.ml sexpLex.ml sexpPkl.ml pklInt.ml\
   share.ml stdPkl.ml stdPrimsUtil.ml assertions_ASDLUtil.ml camelot_absyn_ASDLUtil.ml
MLI=$(shell ls *.mli)
CMO=$(ML:.ml=.cmo)
CMX=$(ML:.ml=.cmx)
CMI=$(ML:.ml=.cmi)


default: $(ML)
	$(MAKE) $(CMO)

opt: $(ML)
	$(MAKE) $(CMX)

depend:	.depend

$(addprefix src/,$(ML)): src

$(ML): %: src/%
	cp $< .

src: ../../Camelot/src/asdl/src
	ln -s $< $@
	cd src; $(MAKE)

# Clean up
clean:
	rm -f .depend
	rm -f *.cm[iox] *.o

# Dependencies
.depend: $(ML)
	$(OCAMLDEP) *.mli *.ml > .depend

# Common rules
.SUFFIXES: .ml .mll .mly .mli .cmo .cmi .cmx .o


.ml.mli:
	$(OCAMLC) $(OCAMLFLAGS) -c $<

.ml.cmo:
	$(OCAMLC) $(OCAMLFLAGS) -c $<

.mli.cmi:
	$(OCAMLC) $(OCAMLFLAGS) -c $<

.ml.cmx:
	$(OCAMLOPT) $(OCAMLOPTFLAGS) -c $<

# Include dependencies if available
ifeq (.depend,$(wildcard .depend))
include .depend
endif
