Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dune switch [do not merge] #13

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 1.6)
8 changes: 4 additions & 4 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.PHONY: default clean
default:
../ocamlscript factorial.ml 100
../ocamlscript revised.ml
../ocamlscript with-includes.ml
echo "1+1" | ../ocamlscript calc.ml
../_build/default/src/main.exe factorial.ml 100
../_build/default/src/main.exe revised.ml
../_build/default/src/main.exe with-includes.ml
echo "1+1" | ../_build/default/src/main.exe calc.ml
clean:
$(RM) *~ *.exe
8 changes: 3 additions & 5 deletions opam → ocamlscript.opam
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
opam-version: "2.0"
synopsis: "Tool which compiles OCaml scripts into native code"
synopsis: "Tool compiling OCaml scripts to native code"
authors: "Martin Jambon"
maintainer: ["[email protected]"
"Francois Berenger <[email protected]>"]
homepage: "https://github.com/mjambon/ocamlscript"
bug-reports: "https://github.com/mjambon/ocamlscript/issues"
dev-repo: "git://github.com/mjambon/ocamlscript"
depends: ["ocaml" {>= "4.08"} # because of Fun.protect
"ocamlfind"]
build: [make]
install: [make "install"]
remove: ["ocamlfind" "remove" "ocamlscript"]
"dune" {>= "1.11"}]
build: ["dune" "build" "-p" name "-j" jobs]
# url {
# src: "https://github.com/mjambon/ocamlscript/archive/XXX"
# checksum: "md5=XXX"
Expand Down
16 changes: 0 additions & 16 deletions pa_opt310.ml

This file was deleted.

2 changes: 1 addition & 1 deletion common.ml → src/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ let extra_args = ref ([] : string list)
let trash = ref ([] : string list)
let verbose = ref false
let script_dir = ref (Sys.getcwd ())
let compile : (string -> string -> int) ref =
let compile : (string -> string -> int) ref =
ref (fun source result -> failwith "Compile.compile is unset")
File renamed without changes.
11 changes: 11 additions & 0 deletions src/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

(library
(name ocamlscript)
(modules ocamlscript pipeline version)
(libraries unix str))

(executable
(name main)
(public_name ocamlscript)
(modules main)
(libraries ocamlscript))
8 changes: 8 additions & 0 deletions src/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

open Printf

let () =
try Ocamlscript.main ()
with Failure s ->
(eprintf "ocamlscript: %s\n%!" s;
exit 2)
112 changes: 54 additions & 58 deletions ocaml.ml → src/ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ let use_camlp4 = ref true (* by default camlp4 is used *)
let use_ocamlc = ref false (* by default we want native code *)
let use_ocamlfind = ref false (* used only if necessary *)
let revised = ref false (* use this to use the revised syntax *)
let ocamlflags = Common.extra_args
(* any options that you may want to pass
to ocamlopt *)
let ocamlflags = Common.extra_args (* any options that you may want to pass
to ocamlopt *)
let ppopt = ref [] (* any options that you may want to pass
to camlp4o or camlp4r *)

Expand All @@ -33,37 +32,35 @@ let ppsrcloc = ref None (* non-standard source location generator *)

let exe s =
match Sys.os_type with
"Win32" | "Cygwin"->
if Filename.check_suffix s ".exe" then s
else s ^ ".exe"
| "Unix" | _ -> s
| "Win32" | "Cygwin"->
if Filename.check_suffix s ".exe" then s
else s ^ ".exe"
| "Unix" | _ -> s

let import path =
let import path =
let src = !+ path in
let dst = Filename.basename src in
let head =
let head =
match !pp, !ppsrcloc, !revised with
Some _, Some f, _ -> f src
| _, _, false -> sprintf "#1 %S;;\n" src
| _, _, true -> sprintf "#1 %S;\n" src in
| Some _, Some f, _ -> f src
| _, _, false -> sprintf "#1 %S;;\n" src
| _, _, true -> sprintf "#1 %S;\n" src in
Pipeline.copy_file ~head src dst

(*
let ocamllex_command input =
if !use_ocamllex then
Some ((fun () -> ()),
new_cmd [!ocamllex; input;
"-o"; "ocamlscript_ocamllex_out.ml"; "-q"],
"ocamlscript_ocamllex_out.ml")
else None
*)
(* let ocamllex_command input =
* if !use_ocamllex then
* Some ((fun () -> ()),
* new_cmd [!ocamllex; input;
* "-o"; "ocamlscript_ocamllex_out.ml"; "-q"],
* "ocamlscript_ocamllex_out.ml")
* else None *)

let file_kind file =
if Filename.check_suffix file ".mli" then `Mli
else if Filename.check_suffix file ".ml" then `Ml
else if Filename.check_suffix file ".mll" then `Mll
else if Filename.check_suffix file ".mly" then `Mly
else
else
try
let prefix = Filename.chop_extension file in
let len = String.length file - String.length prefix in
Expand All @@ -73,25 +70,25 @@ let file_kind file =

let extra_command file =
match file_kind file with
`Mli | `Ml -> ([], [file])
| `Mll ->
([command [!ocamllex; file; "-q"]],
[(Filename.chop_extension file) ^ ".ml"])
| `Mly ->
let p = Filename.chop_extension file in
([command [!ocamlyacc; file]],
[p ^ ".mli"; p ^ ".ml"])
| `Ext s ->
failwith (sprintf "don't know how to handle %s files: %s" s file)
| `Unknown ->
failwith (sprintf "don't know how to handle this file: %s" file)
| `Mli | `Ml -> ([], [file])
| `Mll ->
([command [!ocamllex; file; "-q"]],
[(Filename.chop_extension file) ^ ".ml"])
| `Mly ->
let p = Filename.chop_extension file in
([command [!ocamlyacc; file]],
[p ^ ".mli"; p ^ ".ml"])
| `Ext s ->
failwith (sprintf "don't know how to handle %s files: %s" s file)
| `Unknown ->
failwith (sprintf "don't know how to handle this file: %s" file)

let pp_command file =
match !pp with
None -> [], [file]
| Some f ->
let cmd, files = f file in
([cmd], files)
| None -> [], [file]
| Some f ->
let cmd, files = f file in
([cmd], files)


let extra_commands sources =
Expand All @@ -105,38 +102,37 @@ let extra_commands sources =
let ocaml_command input =
let really_use_ocamlfind =
match !use_ocamlfind, !packs with
true, _ | _, _ :: _ -> true
| _ -> false in
| true, _ | _, _ :: _ -> true
| _ -> false in
let compiler =
if really_use_ocamlfind then
if !use_ocamlc then [!ocamlfind; "ocamlc"]
else [!ocamlfind; "ocamlopt"]
else
if !use_ocamlc then [!ocamlc]
else [!ocamlopt] in

else if !use_ocamlc then [!ocamlc]
else [!ocamlopt] in

let flags = !ocamlflags in
let camlp4_stuff =
if !use_camlp4 then
let syntax, camlp4 =
if !revised then "camlp4r", !camlp4r
else "camlp4o", !camlp4o in
let ppoptions =
let ppoptions =
if !ppopt = [] then []
else
if really_use_ocamlfind then
List.flatten (List.map (fun s -> ["-ppopt"; s]) !ppopt)
else !ppopt in
else
if really_use_ocamlfind then
List.flatten (List.map (fun s -> ["-ppopt"; s]) !ppopt)
else !ppopt in
if really_use_ocamlfind then
"-syntax" :: syntax :: ppoptions
else
let space = function "" -> "" | s -> " " ^ s in
else
let space = function | "" -> "" | s -> " " ^ s in
["-pp"; sprintf "'%s%s'" camlp4 (space (String.concat " " ppoptions))]
else [] in
let packages =
if really_use_ocamlfind then
["-linkpkg"; "-package";
String.concat ","
String.concat ","
(if !use_camlp4 && not (List.mem "camlp4" !packs) then
"camlp4" :: !packs
else !packs) ]
Expand All @@ -145,19 +141,19 @@ let ocaml_command input =
let extra_sources = !sources in
let init () = List.iter import extra_sources in
let all_sources = extra_sources @ [input] in

let xcommands, all_ml_files = extra_commands all_sources in

let args = compiler @ "-o" :: "prog" ::
flags @ camlp4_stuff @ packages @ all_ml_files in
let args = compiler @ "-o" :: "prog" ::
flags @ camlp4_stuff @ packages @ all_ml_files in
(init, xcommands, command args, exe "prog")


let compile source result =
let internal_input =
let compile source result =
let internal_input =
if !use_ocamllex then "ocamlscript_main.mll"
else "ocamlscript_main.ml" in

let before, xcommands, main_command, internal_output =
ocaml_command internal_input in
let input = [internal_input, source] in
Expand Down
File renamed without changes.
Loading