# Makefile 
# 15-411 
# Modified by Roland Flury
# @version $Id: Makefile,v 1.17 2003/09/29 17:01:49 rflury Exp $ #

#*********************************************************************#
#                                                                     #
#                           Objective Caml                            #
#                                                                     #
#            Pierre Weis, projet Cristal, INRIA Rocquencourt          #
#                                                                     #
#  Copyright 1998 Institut National de Recherche en Informatique et   #
#  en Automatique.  Distributed only by permission.                   #
#                                                                     #
#*********************************************************************#

#                   Generic Makefile for Objective Caml Programs

############################ Documentation ######################
#
# To use this Makefile:
# -- You must fix the value of the variable SOURCES below.
# (The variable SOURCES is the list of your Caml source files.)
# -- You must create a file .depend, using
# $touch .depend
# (This file will contain the dependancies between your Caml modules,
#  automatically computed by this Makefile.)

# Usage of this Makefile:
# To incrementally recompile the system, type
#     make
# To recompute dependancies between modules, type
#     make depend
# To remove the executable and all the compiled files, type
#     make clean
# To compile using the native code compiler
#     make opt
#
##################################################################


##################################################################
#
# Advanced usage:
# ---------------

# If you want to fix the name of the executable, set the variable
# EXEC, for instance, if you want to obtain a program named my_prog:
# EXEC = my_prog

# If you need special libraries provided with the Caml system,
# (graphics, arbitrary precision numbers, regular expression on strings, ...),
# you must set the variable LIBS to the proper set of libraries. For
# instance, to use the graphics library set LIBS to $(WITHGRAPHICS):
# LIBS=$(WITHGRAPHICS)

# You may use any of the following predefined variable
# WITHGRAPHICS : provides the graphics library
# WITHUNIX : provides the Unix interface library
# WITHSTR : provides the regular expression string manipulation library
# WITHNUMS : provides the arbitrary precision arithmetic package
# WITHTHREADS : provides the byte-code threads library
# WITHDBM : provides the Data Base Manager library
#
#
########################## End of Documentation ####################



########################## User's variables #####################
#
# The Caml sources (including camlyacc and camllex source files)

SOURCES = helpers.ml summary.ml errormsg.ml absyn.ml \
lexer.mll grammar.mly pcc.ml temp.ml checker.ml evaluator.ml ir.ml frame.ml loops.ml translate.ml canon.ml bitlist.ml \
alloca.ml \
dataflow/sigs.ml dataflow/bitset.ml dataflow/CFG.ml dataflow/dataflow.ml \
dataflow/util.ml dataflow/reaching.ml dataflow/aexp.ml dataflow/live_vars.ml \
dataflow/constant_fold.ml dataflow/cprop.ml dataflow/cse.ml \
dataflow/deadcode.ml \
dataflow/dominators.ml dataflow/hoist.ml \
dataflow/path.ml \
assem.ml munch.ml igraph.ml liveness.ml regalloc.ml finalize.ml command_line.ml main.ml
# test_path.ml \

########################## PATH #####################
#
# The path where to find the OCaml and glut installation
# If you work on andrew, you can set 411PATH=/afs/andrew/course/15/411
# If OCaml and glut are in your PATH, leave 411PATH empty.
# If make is called in an /afs directory, make tries to use
# /afs/andrew/course/15/411 as source for OCaml and glut.

#These are the variables set in your personal environment
411PATH=
  # Where to find the binaries of OCaml
BINPATH=
  # Where to find the libraries of OCaml (local copies used -wjl)
LIBPATH=/afs/cs/user/wlovas/src/compilers-shared
# Define USEGLUT if the interpreter should be able to handle graphics
# USEGLUT=true


########################## Advanced user's variables #####################
#
# The Caml compilers.
# You may fix here the path to access the Caml compiler on your machine
CAMLC = $(BINPATH)ocamlc -I dataflow -g
CAMLOPT = $(BINPATH)ocamlopt -I dataflow
CAMLDEP = $(BINPATH)ocamldep -I dataflow
CAMLLEX = $(BINPATH)ocamllex
CAMLYACC = $(BINPATH)ocamlyacc -v
GCC=gcc

# The executable file to generate (default a.out under Unix)
EXEC = compile

############################## FFI ##############################
# The Object files for the FFI, please without the '.o' suffix
ifdef USEGLUT
  FFI_O_FILES = ffi/ffi_lib_ocaml ffi/ffi_graphics
else
  FFI_O_FILES = ffi/ffi_lib_ocaml ffi/ffi_nographics
endif



# The list of Caml libraries needed by the program
# For instance:
# LIBS=$(WITHGRAPHICS) $(WITHUNIX) $(WITHSTR) $(WITHNUMS) $(WITHTHREADS)\
# $(WITHDBM)


############################## FFI ##############################
# Modified for Graphical FFI by Roland
# Set LIBSPATH to the path where libglut.so* are located
# The current version assumes that they are in the directory LIBS/
#LIBSPATH = $(shell pwd)/LIBS
#LIBS0 = $(WITHSTR) -cclib -lpthread -cclib $(LIBSPATH)/libglut.so.3
#LIBS = $(LIBS0) -cclib -lGLU -cclib -lGL -cclib -Wl,-rpath,$(LIBSPATH)
#
# ==> use the following if glut is installed (comment the 3 previous lines)
#
LIBS = $(WITHSTR)
ifdef USEGLUT
  FFILIBS = -cclib -lpthread -cclib -lglut -cclib -lGLU -ccopt -rdynamic
else
  FFILIBS = -cclib -lpthread -ccopt -rdynamic
endif
#

# Should be set to -custom if you use any of the libraries above
# or if any C code have to be linked with your program
# (irrelevant for ocamlopt)
CUSTOM=-custom

# Default setting of the WITH* variables. Should be changed if your
# local libraries are not found by the compiler.
WITHGRAPHICS =graphics.cma -cclib -lgraphics -cclib -L/usr/X11R6/lib -cclib -lX11

WITHUNIX =unix.cma -cclib -lunix

WITHSTR =str.cma -cclib -lstr

WITHNUMS =nums.cma -cclib -lnums

WITHTHREADS =threads.cma -cclib -lthreads

WITHDBM =dbm.cma -cclib -lmldbm -cclib -lndbm

################ End of user's variables #####################


##############################################################
################ This part should be generic
################ Nothing to set up or fix here
##############################################################

#Compile native code
all: comments command_line_linux $(EXEC).opt

#Compile to byte code
byte: comments command_line_linux depend $(EXEC)

#Compile for mac OS X (other command lines)
macOSX: comments command_line_macOSX depend all

command_line_macOSX:
	cp macOSX.ml command_line.ml
command_line_linux: 
	cp linux.ml command_line.ml

comments:
ifndef USEGLUT
	@echo "Notice:"
	@echo "  The evaluator will not be able to perform ffi-calls to "
	@echo "  graphics-function. Uncomment USEGLUT=true in the Makefile"
	@echo "  if you wish that the evaluator is able to perform such functions."
endif


############################## FFI ##############################
# added by Roland Flury for the FFI, andrew environment
$(FFI_O_FILES): $(FFI_O_FILES:=.c)
	$(GCC) -c -I$(LIBPATH) $@.c -o $@.o
############################## FFI ##############################

#ocamlc -custom other options graphics.cma other files -cclib -lgraphics -cclib -lX11
#ocamlc -thread -custom other options threads.cma other files -cclib -lthreads
#ocamlc -custom other options str.cma other files -cclib -lstr
#ocamlc -custom other options nums.cma other files -cclib -lnums
#ocamlc -custom other options unix.cma other files -cclib -lunix
#ocamlc -custom other options dbm.cma other files -cclib -lmldbm -cclib -lndbm

SOURCES1 = $(SOURCES:.mly=.ml)
SOURCES2 = $(SOURCES1:.mll=.ml)
OBJS = $(SOURCES2:.ml=.cmo)
OPTOBJS = $(SOURCES2:.ml=.cmx)

## changed by Roland Flury for the FFI
$(EXEC): $(OBJS) $(FFI_O_FILES)
	$(CAMLC) $(CUSTOM) -o $(EXEC) $(LIBS) $(OBJS) $(FFILIBS) $(FFI_O_FILES:=.o)

# $(EXEC): $(OBJS) 
# 	$(CAMLC) $(CUSTOM) -o $(EXEC) $(LIBS) $(OBJS) 


$(EXEC).opt: $(OPTOBJS) $(FFI_O_FILES)
	$(CAMLOPT) -o $(EXEC) $(LIBS:.cma=.cmxa) $(OPTOBJS) $(FFILIBS) $(FFI_O_FILES:=.o)

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

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

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

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

.mll.cmo:
	$(CAMLLEX) $<
	$(CAMLC) -c $*.ml

.mll.cmx:
	$(CAMLLEX) $<
	$(CAMLOPT) -c $*.ml

.mly.cmo:
	$(CAMLYACC) $<
	$(CAMLC) -c $*.mli
	$(CAMLC) -c $*.ml

.mly.cmx:
	$(CAMLYACC) $<
	$(CAMLOPT) -c $*.mli
	$(CAMLOPT) -c $*.ml

.mly.cmi:
	$(CAMLYACC) $<
	$(CAMLC) -c $*.mli

.mll.ml:
	$(CAMLLEX) $<

.mly.ml:
	$(CAMLYACC) $<

clean: 
	rm -f *.cm[iox] *~ .*~
	rm -f dataflow/*.cm[iox]
	rm grammar.ml lexer.ml
	rm -f $(EXEC)
	rm -f $(EXEC).opt
# added by Roland Flury for FFI
	rm -f *.o
	rm -f $(FFI_O_FILES:=.o)
	rm -f dataflow/*.cm[iox] dataflow/*~


.depend: $(SOURCES2)
	$(CAMLDEP) *.mli *.ml dataflow/*.mli dataflow/*.ml > .depend

depend: .depend

include .depend
