File: make_oasis.ml

package info (click to toggle)
wyrd 1.4.6-4
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 1,820 kB
  • ctags: 1,969
  • sloc: ml: 11,059; sh: 5,531; ansic: 760; makefile: 304; python: 44
file content (38 lines) | stat: -rwxr-xr-x 1,204 bytes parent folder | download | duplicates (3)
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
38
#!/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;;