summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile10
-rw-r--r--src/ocaml_backend.ml7
-rw-r--r--src/process_file.ml7
3 files changed, 20 insertions, 4 deletions
diff --git a/src/Makefile b/src/Makefile
index cb1a8eb8..d71fb20b 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -67,6 +67,8 @@ endif
# set to -p on command line to enable gprof profiling
OCAML_OPTS?=
+INSTALL_DIR?=$(realpath ..)
+
all: sail lib doc
full: sail lib power doc test
@@ -88,10 +90,14 @@ bytecode.ml: bytecode.lem
lem_interp/interp_ast.lem: ../language/l2.ott
ott -sort false -generate_aux_rules true -o lem_interp/interp_ast.lem -picky_multiple_parses true ../language/l2.ott
-sail: ast.ml bytecode.ml
+install_directory.ml:
+ echo "(* Generated file -- do not edit. *)" > install_directory.ml
+ echo let d=\"$(INSTALL_DIR)\" >> install_directory.ml
+
+sail: ast.ml bytecode.ml install_directory.ml
ocamlbuild -use-ocamlfind sail.native sail_lib.cma sail_lib.cmxa
-isail: ast.ml bytecode.ml
+isail: ast.ml bytecode.ml install_directory.ml
ocamlbuild -use-ocamlfind isail.native
sail.native: sail
diff --git a/src/ocaml_backend.ml b/src/ocaml_backend.ml
index 34039080..91ca17b6 100644
--- a/src/ocaml_backend.ml
+++ b/src/ocaml_backend.ml
@@ -685,7 +685,12 @@ let system_checked str =
let ocaml_compile spec defs =
let sail_dir =
try Sys.getenv "SAIL_DIR" with
- | Not_found -> failwith "Environment variable SAIL_DIR needs to be set"
+ | Not_found ->
+ let share_dir = Filename.concat Install_directory.d "share/sail" in
+ if Sys.is_directory share_dir then
+ share_dir
+ else
+ failwith "Could not find sail share directory, " ^ share_dir ^ ". Make sail is installed or try setting environment variable SAIL_DIR."
in
if Sys.file_exists "_sbuild" then () else Unix.mkdir "_sbuild" 0o775;
let cwd = Unix.getcwd () in
diff --git a/src/process_file.ml b/src/process_file.ml
index 88220841..dd34f49c 100644
--- a/src/process_file.ml
+++ b/src/process_file.ml
@@ -149,7 +149,12 @@ let rec preprocess = function
let file = String.sub file 1 (len - 2) in
let sail_dir =
try Sys.getenv "SAIL_DIR" with
- | Not_found -> (failwith ("Environment variable SAIL_DIR unset. Cannot $include " ^ file))
+ | Not_found ->
+ let lib_dir = Filename.concat Install_directory.d "lib" in
+ if Sys.is_directory lib_dir then
+ Install_directory.d
+ else
+ (failwith ("Library directory " ^ lib_dir ^ " does not exist. Make sure sail is installed or try setting environment variable SAIL_DIR so that I can find $include " ^ file))
in
let file = Filename.concat sail_dir ("lib/" ^ file) in
let (Parse_ast.Defs include_defs) = parse_file file in