]> git.lizzy.rs Git - metalua.git/blob - src/build-utils/precompile.lua
Merge remote branch 'origin/master'
[metalua.git] / src / build-utils / precompile.lua
1 -- Compile all files called *.mluam in a directory and its sub-directories,
2 -- into their *.luac counterpart.
3 --
4 -- This script is windows-only, Unices have half-decent shell script languages 
5 -- which let you do the same with a find and an xargs.
6
7 cfg = { }
8 for _, a in ipairs(arg) do
9    local var, val = a :match "^(.-)=(.*)"
10    if var then cfg[var] = val end
11 end
12
13 if not cfg.command or not cfg.directory then
14    error ("Usage: "..arg[0].." command=<metalua command> directory=<library root>")
15 end
16
17 -- List all files, recursively, from newest to oldest
18 local f = io.popen ("dir /S /b /o-D " .. cfg.directory)
19
20 local file_seen = { }
21 for src in f:lines() do
22    file_seen[src] = true
23    local base = src:match "^(.+)%.mlua$"
24    if base then
25       local target = base..".luac"
26       if file_seen[target] then 
27          -- the target file has been listed before the source ==> it's newer
28          print ("("..target.." up-to-date)")
29       else
30          local cmd = cfg.command.." "..src.." -o "..target
31          print (cmd)
32          os.execute (cmd)
33       end
34    end
35 end
36
37