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
39
40
41
42
43
44
45
[def git-get-commit [λ [branch]
"Gets the commit hash of BRANCH"
[str/trim [file/read [".git/refs/heads/" branch]]]
]]
[def git-get-branch [λ []
"Returns the currently active branch"
[let [[cur-head [str/trim [file/read "./.git/HEAD"]]]]
[cond [[eq? [substr cur-head 0 4] "ref:"] [join [list-tail [split cur-head "/"] 2] "/"]]
[#t "UNKNOWN"]
]
]
]]
[def git-get-head [λ []
"Gets the current git head"
[git-get-commit [git-get-branch]]
]]
[def infogen-version [λ []
"Return the infogen version"
[cat [git-get-branch] "-" [strftime [time] "%Y-%m-%d"] "-" [str/uppercase [substr [git-get-head] 0 8]]]
]]
[def infogen-builddate [λ []
"Return the infogen builddate"
[strftime [time] "%Y-%m-%d %H:%M"]
]]
[def infogen-commit [λ []
"Return the infogen commit"
[str-up [git-get-head]]
]]
[def infogen-source [λ []
"Return the source part"
["const char *VERSION=\"" [infogen-version] "\";\n"
"const char *BUILDDATE=\"" [infogen-builddate] "\";\n"
"const char *COMMIT=\"" [infogen-commit] "\";\n\n"]
]]
[def infogen [λ [prefix]
"Generate build info and writes C source/header files PREFIX"
[file/write [cat prefix ".c"] [infogen-source]]
]]