##########

# Dependencies for automatically generated source files
GENERATED_FILES = parser.ml lexer.ml

# source files, including generated files. order is important.
SRCS = global.ml types.ml smap.ml robot.ml world.ml $(GENERATED_FILES) main.ml cmdline.ml

# compile options such as -O 293
FLAGS =

# library linking options such as -I ...
INCS =

# libraries, such as hoge.cmxa
LIBS = unix.cmxa

# name of resulting executable
TARGET = main

##########
OBJS = $(SRCS:.ml=.cmx)

OCAML = ocamlopt
OCAMLFLAGS = $(FLAGS) $(INCS)

OCAMLDEPFLAGS =

OCAMLYACC = ocamlyacc
OCAMLYACCFLAGS = -v

OCAMLLEX = ocamllex
OCAMLLEXFLAGS =

##########

all: $(TARGET)

$(TARGET):$(OBJS)
	$(OCAML) $(OCAMLFLAGS) -o $(TARGET) $(LIBS) $(OBJS)

clean:
	rm -f *~ *.o *.cm* *.output $(GENERATED_FILES) $(TARGET)

.SUFFIXES: .ml .mli .cmi .cmx .mly .mll

.ml.cmx:
	$(OCAML) $(OCAMLFLAGS) -c $<

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

.mly.ml:
	$(OCAMLYACC) $(OCAMLYACCFLAGS) $<
	rm -f $*.mli

.mll.ml:
	$(OCAMLLEX) $(OCAMLLEXFLAGS) $<

##########

parser.ml: parser.mly
lexer.ml: lexer.mll

depend: $(GENERATED_FILES)
	ocamldep $(OCAMLDEPFLAGS) $(SRCS) > depfile

include depfile
