-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbake.lua
More file actions
50 lines (38 loc) · 1.48 KB
/
bake.lua
File metadata and controls
50 lines (38 loc) · 1.48 KB
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
46
47
48
49
50
require("bake_stubs")
local target = "bake"
local ccflags = "-g"
local ldflags = "-g -llua5.3"
-- neat utility functions :P
local src = pantry.collect("src", ".c")
local obj = pantry.objects(src, "src/", "build/", ".c", ".o")
recipe("build/" .. target, obj, function(output, input)
local obj_str = table.concat(input, " ")
whisk("gcc " .. obj_str .. " " .. ldflags .. " -o " .. output).err(true)
end)
-- "ALWAYS" dependent targets will always get run, as long as they get referenced by something.
recipe("build", { "ALWAYS" }, function()
pantry.new_shelf("build")
end)
recipe("install", { "ALWAYS" }, function()
whisk("cp build/" .. target .. " /bin/" .. target).err(false)
local stub_file = "bake_stubs.lua"
local first_path = package.path:match("([^;]+)"):gsub("%?%.lua$", "")
print("Installing stub to: ", first_path)
if not pantry.is_shelf(first_path) then
error("First path is not a directory: " .. first_path)
end
local copy_stub = whisk("cp " .. stub_file .. " " .. first_path .. "/" .. stub_file)
copy_stub.err(false)
if copy_stub.return_code == 0 then
print("Stub installed successfully!")
end
end)
-- Bake supports wildcards, like Make!
recipe("build/%.o", { "src/%.c" }, function(output, input)
local timestr = os.date("%y_%m_%d:%H.%M")
whisk("gcc -D'VERSION=\"" .. timestr .. "\"' -c " .. input[1] .. " " .. ccflags .. " -o " .. output).err(true)
end)
recipe("clean", { "ALWAYS" }, function()
whisk("rm -rf build").err(false)
end)
bake({ "build", "build/" .. target })