#########################################################################
#                                                                       #
#                            Objective Caml                             #
#                                                                       #
#            Xavier Leroy, projet Cristal, INRIA Rocquencourt           #
#                                                                       #
#   Copyright 1999 Institut National de Recherche en Informatique et    #
#   en Automatique.  All rights reserved.  This file is distributed     #
#   under the terms of the GNU Library General Public License, with     #
#   the special exception on linking described in file ../LICENSE.      #
#                                                                       #
#########################################################################

# $Id$

include ../config/Makefile

RUNTIME=../boot/ocamlrun
COMPILER=../ocamlc
CAMLC=$(RUNTIME) $(COMPILER)
OPTCOMPILER=../ocamlopt
CAMLOPT=$(RUNTIME) $(OPTCOMPILER)
CAMLDEP=../boot/ocamlrun ../tools/ocamldep

BASIC=pervasives.cmo array.cmo list.cmo char.cmo string.cmo sys.cmo \
  hashtbl.cmo sort.cmo marshal.cmo obj.cmo \
  lexing.cmo parsing.cmo \
  set.cmo map.cmo stack.cmo queue.cmo stream.cmo buffer.cmo \
  printf.cmo format.cmo scanf.cmo \
  arg.cmo printexc.cmo gc.cmo \
  digest.cmo random.cmo camlinternalOO.cmo oo.cmo \
  genlex.cmo callback.cmo weak.cmo \
  lazy.cmo filename.cmo int32.cmo int64.cmo nativeint.cmo complex.cmo
LABELLED=arrayLabels.ml listLabels.ml stringLabels.ml moreLabels.ml

OBJS=$(BASIC) labelled.cmo stdLabels.cmo
ALLOBJS=$(BASIC) $(LABELLED:.ml=.cmo) stdLabels.cmo

all: stdlib.cma std_exit.cmo camlheader camlheader_ur

allopt: stdlib.cmxa std_exit.cmx

install:
	cp stdlib.cma std_exit.cmo *.cmi *.mli *.ml camlheader camlheader_ur $(LIBDIR)

installopt:
	cp stdlib.cmxa stdlib.$(A) std_exit.$(O) *.cmx $(LIBDIR)

stdlib.cma: $(OBJS)
	$(CAMLC) -a -o stdlib.cma $(ALLOBJS)

stdlib.cmxa: $(OBJS:.cmo=.cmx)
	$(CAMLOPT) -a -o stdlib.cmxa $(ALLOBJS:.cmo=.cmx)

camlheader camlheader_ur: headernt.c ../config/Makefile
	$(BYTECC) $(BYTECCCOMPOPTS) $(BYTECCLINKOPTS) -o camlheader.exe headernt.c
	mv camlheader.exe camlheader.
	cp camlheader camlheader_ur

clean::
	rm -f camlheader camlheader_ur

pervasives.cmi: pervasives.mli
	$(CAMLC) $(COMPFLAGS) -nopervasives -c pervasives.mli

pervasives.cmo: pervasives.ml
	$(CAMLC) $(COMPFLAGS) -nopervasives -c pervasives.ml

pervasives.cmx: pervasives.ml
	$(CAMLOPT) $(COMPFLAGS) -nopervasives -c pervasives.ml

# camlinternalOO.cmi must be compiled with -nopervasives for applets
camlinternalOO.cmi: camlinternalOO.mli
	$(CAMLC) $(COMPFLAGS) -nopervasives -c camlinternalOO.mli

# labelled modules require the -nolabels flag
labelled.cmo:
	$(MAKEREC) EXTRAFLAGS=-nolabels RUNTIME=$(RUNTIME) COMPILER=$(COMPILER) $(LABELLED:.ml=.cmo)
	touch $@
labelled.cmx:
	$(MAKEREC) EXTRAFLAGS=-nolabels $(LABELLED:.ml=.cmx)
	touch $@
labelled.p.cmx:
	$(MAKEREC) EXTRAFLAGS=-nolabels $(LABELLED:.ml=.p.cmx)
	touch $@

# generic rules
.SUFFIXES: .mli .ml .cmi .cmo .cmx

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

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

.ml.cmx:
	$(CAMLOPT) $(COMPFLAGS) $(EXTRAFLAGS) -c $<

$(ALLOBJS) labelled.cmo std_exit.cmo: pervasives.cmi $(COMPILER)
$(ALLOBJS:.cmo=.cmx) labelled.cmx std_exit.cmx: pervasives.cmi $(OPTCOMPILER)
$(ALLOBJS:.cmo=.cmi) std_exit.cmi: $(COMPILER)
labelled.cmo labelled.cmx: $(LABELLED) $(LABELLED:.ml=.mli)

clean::
	rm -f *.cm* *.$(O) *.$(A)
	rm -f *~

include .depend

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