diff options
Diffstat (limited to 'src/host/genversion.lua')
-rw-r--r-- | src/host/genversion.lua | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/host/genversion.lua b/src/host/genversion.lua new file mode 100644 index 00000000..a38cec56 --- /dev/null +++ b/src/host/genversion.lua | |||
@@ -0,0 +1,43 @@ | |||
1 | ---------------------------------------------------------------------------- | ||
2 | -- Lua script to embed the rolling release version in luajit.h. | ||
3 | ---------------------------------------------------------------------------- | ||
4 | -- Copyright (C) 2005-2023 Mike Pall. All rights reserved. | ||
5 | -- Released under the MIT license. See Copyright Notice in luajit.h | ||
6 | ---------------------------------------------------------------------------- | ||
7 | |||
8 | local FILE_INPUT_H = "luajit_rolling.h" | ||
9 | local FILE_INPUT_R = "luajit_relver.txt" | ||
10 | local FILE_OUTPUT_H = "luajit.h" | ||
11 | |||
12 | local function file_read(file) | ||
13 | local fp = assert(io.open(file, "rb"), "run from the wrong directory") | ||
14 | local data = assert(fp:read("*a")) | ||
15 | fp:close() | ||
16 | return data | ||
17 | end | ||
18 | |||
19 | local function file_write_mod(file, data) | ||
20 | local fp = io.open(file, "rb") | ||
21 | if fp then | ||
22 | local odata = assert(fp:read("*a")) | ||
23 | fp:close() | ||
24 | if odata == data then return end | ||
25 | end | ||
26 | fp = assert(io.open(file, "wb")) | ||
27 | assert(fp:write(data)) | ||
28 | assert(fp:close()) | ||
29 | end | ||
30 | |||
31 | local text = file_read(FILE_INPUT_H) | ||
32 | local relver = file_read(FILE_INPUT_R):match("(%d+)") | ||
33 | |||
34 | if relver then | ||
35 | text = text:gsub("ROLLING", relver) | ||
36 | else | ||
37 | io.stderr:write([[ | ||
38 | **** WARNING Cannot determine rolling release version from git log. | ||
39 | **** WARNING The 'git' command must be available during the build. | ||
40 | ]]) | ||
41 | end | ||
42 | |||
43 | file_write_mod(FILE_OUTPUT_H, text) | ||