| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
let escape = |
| 19 |
let s' = Buffer.create 10 in |
| 20 |
fun s -> |
| 21 |
Buffer.clear s'; |
| 22 |
for i = 0 to String.length s - 1 do |
| 23 |
let c = s.[i] in |
| 24 |
if c = ' ' || c = '#' || c = ':' |
| 25 |
|| c = '%' |
| 26 |
|| c = '?' || c = '[' || c = ']' || c = '*' |
| 27 |
|| i=0 && c = '~' && (String.length s = 1 || s.[1] = '/' || |
| 28 |
'A' <= s.[1] && s.[1] <= 'Z' || |
| 29 |
'a' <= s.[1] && s.[1] <= 'z') |
| 30 |
then begin |
| 31 |
let j = ref (i-1) in |
| 32 |
while !j >= 0 && s.[!j] = '\\' do |
| 33 |
Buffer.add_char s' '\\'; decr j |
| 34 |
done; |
| 35 |
Buffer.add_char s' '\\'; |
| 36 |
end; |
| 37 |
if c = '$' then Buffer.add_char s' '$'; |
| 38 |
Buffer.add_char s' c |
| 39 |
done; |
| 40 |
Buffer.contents s' |
| 41 |
|
| 42 |
open Format |
| 43 |
|
| 44 |
type dynlink = Opt | Byte | Both | No | Variable |
| 45 |
let option_dynlink = ref Both |
| 46 |
|
| 47 |
let set_dyndep = function |
| 48 |
| "no" -> option_dynlink := No |
| 49 |
| "opt" -> option_dynlink := Opt |
| 50 |
| "byte" -> option_dynlink := Byte |
| 51 |
| "both" -> option_dynlink := Both |
| 52 |
| "var" -> option_dynlink := Variable |
| 53 |
| o -> CErrors.user_err Pp.(str "Incorrect -dyndep option: " ++ str o) |
| 54 |
|
| 55 |
let mldep_to_make base = |
| 56 |
match !option_dynlink with |
| 57 |
| No -> [] |
| 58 |
| Byte -> [sprintf "%s.cma" base] |
| 59 |
| Opt -> [sprintf "%s.cmxs" base] |
| 60 |
| Both -> |
| 61 |
[sprintf "%s.cma" base; sprintf "%s.cmxs" base] |
| 62 |
| Variable -> |
| 63 |
[sprintf "%s%s" base "$(DYNLIB)"] |
| 64 |
|
| 65 |
let string_of_dep ~suffix = let open Dep_info.Dep in |
| 66 |
function |
| 67 |
| Require basename -> [escape basename ^ suffix] |
| 68 |
| Ml base -> mldep_to_make (escape base) |
| 69 |
| Other s -> [escape s] |
| 70 |
|
| 71 |
let string_of_dependency_list ~suffix deps = |
| 72 |
List.map (string_of_dep ~suffix) deps |
| 73 |
|> List.concat |> String.concat " " |
| 74 |
|
| 75 |
let option_noglob = ref false |
| 76 |
let option_write_vos = ref false |
| 77 |
let set_noglob glob = option_noglob := glob |
| 78 |
let set_write_vos vos = option_write_vos := vos |
| 79 |
|
| 80 |
let print_dep fmt { Dep_info.name; deps } = |
| 81 |
let ename = escape name in |
| 82 |
let glob = if !option_noglob then "" else ename^".glob " in |
| 83 |
fprintf fmt "%s.vo %s%s.v.beautified %s.required_vo: %s.v %s\n" ename glob ename ename ename |
| 84 |
(string_of_dependency_list ~suffix:".vo" deps); |
| 85 |
if !option_write_vos then |
| 86 |
fprintf fmt "%s.vos %s.vok %s.required_vos: %s.v %s\n" ename ename ename ename |
| 87 |
(string_of_dependency_list ~suffix:".vos" deps); |
| 88 |
fprintf fmt "%!" |