forked from haguenau/wyrd
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmake_oasis.ml
executable file
·38 lines (29 loc) · 1.17 KB
/
make_oasis.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
32
33
34
35
36
37
#!/usr/bin/env ocaml
#use "topfind";;
#thread;; (* Batteries apparently needs this... *)
#require "batteries";;
open Batteries;;
let input_filename = "_oasis.in" in
let output_filename = "_oasis" in
(* Extract the VERSION=x.y.z line from Makefile.in *)
let makefile_version_number =
let version_regex = Str.regexp "^VERSION[ \\t]*=\\([^ \\t]+\\)[ \\t]*$" in
let lines = File.lines_of "Makefile.in" in
let matching_line = Enum.find (fun line -> Str.string_match version_regex line 0) lines in
Str.matched_group 1 matching_line
in
(* Plug this version into the appropriate place in _oasis.in *)
let oasis_content =
let oasis_version_regex = Str.regexp "@WYRD_VERSION@" in
let oasis_template = File.with_file_in input_filename IO.read_all in
let replace_count = ref 0 in
let subst input =
let () = incr replace_count in
makefile_version_number
in
let result = Str.global_substitute oasis_version_regex subst oasis_template in
let () = assert (!replace_count = 1) in
result
in
let () = File.with_file_out output_filename (fun ch -> IO.nwrite ch oasis_content) in
Printf.printf "Wrote ./%s using version number \"%s\".\n" output_filename makefile_version_number;;