--- src/Driver.ml	2019-10-28 15:27:27.000000000 -0600
+++ src/Driver.ml	2019-10-28 15:48:43.000000000 -0600
@@ -52,6 +52,7 @@
 let fstar_options = ref []
 
 (** By [detect_karamel] *)
+let bin_dir = ref ""
 let krmllib_dir = ref ""
 let runtime_dir = ref ""
 let include_dir = ref ""
@@ -145,6 +146,16 @@
 let detect_karamel () =
   detect_base_tools_if ();
 
+  let real_krml =
+    let me = Sys.argv.(0) in
+    if Sys.os_type = "Win32" && not (Filename.is_relative me) then
+      me
+    else
+      try read_one_line !readlink [| "-f"; read_one_line "which" [| me |] |]
+      with _ -> fatal_error "Could not compute full krml path"
+  in
+  bin_dir := Filename.dirname (real_krml);
+
   if AutoConfig.krmllib_dir <> "" && try ignore (Sys.getenv "KRML_HOME"); false with Not_found -> true then begin
     krmllib_dir := AutoConfig.krmllib_dir;
     runtime_dir := AutoConfig.runtime_dir;
@@ -159,18 +170,10 @@
       begin try
         Sys.getenv "KRML_HOME"
       with Not_found -> try
-        let real_krml =
-          let me = Sys.argv.(0) in
-          if Sys.os_type = "Win32" && not (Filename.is_relative me) then
-            me
-          else
-            try read_one_line !readlink [| "-f"; read_one_line "which" [| me |] |]
-            with _ -> fatal_error "Could not compute full krml path"
-        in
         (* ../_build/src/Karamel.native *)
         if not !Options.silent then
           KPrint.bprintf "%sthe Karamel executable is:%s %s\n" Ansi.underline Ansi.reset real_krml;
-        read_one_line !readlink [| "-f"; d real_krml ^^ ".." ^^ ".." |]
+        read_one_line !readlink [| "-f"; d real_krml ^^ ".." |]
       with _ ->
         fatal_error "Could not compute krml_home"
       end
@@ -185,11 +188,20 @@
       Sys.chdir cwd
     end;
 
-    krmllib_dir := krml_home ^^ "krmllib";
-    runtime_dir := krml_home ^^ "runtime";
-    include_dir := krml_home ^^ "include";
-    misc_dir := krml_home ^^ "misc"
+    if try Sys.is_directory (krml_home ^^ "krmllib") with Sys_error _ -> false; then begin
+      if not !Options.silent then
+        KPrint.bprintf "Detected source layout in KreMLin home\n";
 
+      krmllib_dir := krml_home ^^ "krmllib";
+      runtime_dir := krml_home ^^ "runtime";
+      include_dir := krml_home ^^ "include";
+      misc_dir := krml_home ^^ "misc"
+    end else begin
+      krmllib_dir := krml_home ^^ "lib" ^^ "kremlin";
+      runtime_dir := !krmllib_dir ^^ "runtime";
+      include_dir := krml_home ^^ "include";
+      misc_dir := krml_home ^^ "share" ^^ "kremlin" ^^ "misc"
+    end;
   end;
 
   (* The first one for the C compiler, the second one for F* *)
@@ -221,12 +233,16 @@
     fstar_home := r;
     fstar := r ^^ "bin" ^^ "fstar.exe"
   with Not_found -> try
-    fstar := read_one_line "which" [| "fstar.exe" |];
+    let real_fstar =
+      try read_one_line !readlink [| "-f"; !bin_dir ^^ "fstar" |]
+      with _ -> fatal_error "Could not compute full fstar path"
+    in
+    fstar := real_fstar;
     fstar_home := d (d !fstar);
     if not !Options.silent then
-      KPrint.bprintf "FSTAR_HOME is %s (via fstar.exe in PATH)\n" !fstar_home
+      KPrint.bprintf "FSTAR_HOME is %s\n" !fstar_home
   with _ ->
-    fatal_error "Did not find fstar.exe in PATH and FSTAR_HOME is not set"
+    fatal_error "Did not find fstar in %s and FSTAR_HOME is not set" !bin_dir
   end;
 
   let fstar_ulib = !fstar_home ^^ "ulib" in
