forked from ocaml/opam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrunch.ml
31 lines (30 loc) · 834 Bytes
/
crunch.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
let add_chan buf chan =
try
while true do
let line = input_line chan in
Buffer.add_string buf line;
Buffer.add_char buf '\n'
done
with End_of_file ->
()
let () =
let buf = Buffer.create 1024 in
print_endline "(* THIS FILE IS AUTOMATICALLY GENERATED, EDIT ../Makefile INSTEAD *)";
for i = 1 to Array.length Sys.argv - 1 do
let file = Sys.argv.(i) in
let name =
let file = Filename.basename file in
if Filename.check_suffix file ".sh" then
Filename.chop_extension file
else
String.map (function '.' -> '_' | c -> c) file
in
let c = open_in_bin file in
Buffer.clear buf;
add_chan buf c;
close_in c;
let contents = Buffer.contents buf in
Printf.printf "let %s =\n\"%s\"\n\n"
name
(String.escaped contents)
done