#
# This file is part of Cafesterol.
# Copyright (C) 2007-2010 Xavier Clerc.
# Original file (debugger/Makefile.shared in the Objective Caml source
# distribution) is Copyright (C) INRIA.
#
# Cafesterol is free software; you can redistribute it and/or modify
# it under the terms of the Q Public License v1.0 as published by
# Trolltech (with a change to choice of law).
#
# Cafesterol is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# Q Public License for more details.
#
# You should have received a copy of the Q Public License
# along with this program.  If not, see
# <http://qt.nokia.com/doc/4.0/qpl.html>.
#

include ../config/Makefile

UNIXDIR=../otherlibs/unix
OCAMLJAVA=../ocamljava
COMPFLAGS=-warn-error A $(INCLUDES)
LINKFLAGS=-I $(UNIXDIR)

INCLUDES=\
  -I ../utils -I ../parsing -I ../typing -I ../bytecomp -I ../toplevel \
  -I $(UNIXDIR)

OTHEROBJS=\
  $(UNIXDIR)/unix.cmja \
  ../utils/misc.cmj ../utils/config.cmj \
  ../utils/tbl.cmj ../utils/clflags.cmj ../utils/consistbl.cmj \
  ../parsing/longident.cmj \
  ../typing/ident.cmj ../typing/path.cmj ../typing/types.cmj \
  ../typing/btype.cmj ../typing/primitive.cmj ../typing/typedtree.cmj \
  ../typing/subst.cmj ../typing/predef.cmj \
  ../typing/datarepr.cmj ../typing/env.cmj ../typing/oprint.cmj \
  ../typing/ctype.cmj ../typing/printtyp.cmj ../typing/mtype.cmj \
  ../bytecomp/runtimedef.cmj ../bytecomp/bytesections.cmj \
  ../bytecomp/dll.cmj ../bytecomp/meta.cmj ../bytecomp/symtable.cmj \
  ../bytecomp/opcodes.cmj \
  ../toplevel/genprintval.cmj


OBJS=\
        dynlink.cmj \
	int64ops.cmj \
	primitives.cmj \
	unix_tools.cmj \
	debugger_config.cmj \
	envaux.cmj \
	parameters.cmj \
	lexer.cmj \
	input_handling.cmj \
	question.cmj \
	debugcom.cmj \
	exec.cmj \
	source.cmj \
	pos.cmj \
	checkpoints.cmj \
	events.cmj \
	program_loading.cmj \
	symbols.cmj \
	breakpoints.cmj \
	trap_barrier.cmj \
	history.cmj \
	printval.cmj \
	show_source.cmj \
	time_travel.cmj \
	program_management.cmj \
	frames.cmj \
	eval.cmj \
	show_information.cmj \
	loadprinter.cmj \
	parser.cmj \
	command_line.cmj \
	main.cmj

all: prepare ocamldebug restore

prepare:
	patch -b -f -p1 < debugger-patch

ocamldebug: $(OBJS) $(OTHEROBJS)
	$(OCAMLJAVA) $(LINKFLAGS) -o ocamldebug.jar $(OTHEROBJS) $(OBJS)
	$(OCAMLJAVA) $(LINKFLAGS) -standalone -o ocamldebug-standalone.jar $(OTHEROBJS) $(OBJS)

restore:
	for f in *.orig; do \
	  mv -f $$f `basename $$f .orig`; \
	done

install:
	cp ocamldebug*.jar $(BINDIR)

clean::
	rm -f ocamldebug*.jar
	rm -f *.cmj *.jo *.cmi

.SUFFIXES:
.SUFFIXES: .ml .cmj .mli .cmi

.ml.cmj:
	$(OCAMLJAVA) -c $(COMPFLAGS) $<

.mli.cmi:
	$(OCAMLJAVA) -c $(COMPFLAGS) $<
