-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
96 lines (86 loc) · 3.8 KB
/
Makefile
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Does the following things, in order:
#
# 1) Builds the Lua interpreter, compiler, and library from source.
#
# 2) Compiles all cubuild Lua source files into a single precompiled Lua
# binary (code.luac).
#
# 3) Shoves the binary (code.luac) into a chunk of bytes in a C source
# file (code.c).
#
# 4) Builds a wrapper C program that just copies its arguments into a Lua
# table and runs the embedded binary script.
#
# Cleaning removes all generated code, including the built Lua binaries.
# Name of the output binary.
BIN = cubuild
# Directory where source files live.
SRC_DIR = src
# Directory where utility tools live.
TOOLS_DIR = tools
# Directory where generated code goes.
GEN_DIR = gen
# List of the Lua source files.
LUA_SRCS = $(SRC_DIR)/globals.lua \
$(GEN_DIR)/build_info.lua \
$(SRC_DIR)/cmd_args.lua \
$(SRC_DIR)/primitives.lua \
$(SRC_DIR)/files.lua \
$(SRC_DIR)/compile.lua \
$(SRC_DIR)/link.lua \
$(SRC_DIR)/clean.lua \
$(SRC_DIR)/cubuild.lua
# Source files for Lua modules to build into the binary.
MODULE_SRCS = $(SRC_DIR)/luafilesystem-1.5.0/lfs.c
# Directory where the Lua source code lives.
LUA_DIR = $(SRC_DIR)/lua-5.1.4
all:
@echo "======================================================================"
@echo " Generating build info..."
@echo "======================================================================"
echo "BUILD_DATE = [[" > $(GEN_DIR)/build_info.lua
date >> $(GEN_DIR)/build_info.lua
echo "]]" >> $(GEN_DIR)/build_info.lua
echo "BUILD_MACHINE = [[" >> $(GEN_DIR)/build_info.lua
uname -n >> $(GEN_DIR)/build_info.lua
echo "]]" >> $(GEN_DIR)/build_info.lua
echo "BUILD_ARCH = [[" >> $(GEN_DIR)/build_info.lua
uname -m >> $(GEN_DIR)/build_info.lua
echo "]]" >> $(GEN_DIR)/build_info.lua
echo "GIT_COMMIT = [[" >> $(GEN_DIR)/build_info.lua
git rev-parse HEAD >> $(GEN_DIR)/build_info.lua
echo "]]" >> $(GEN_DIR)/build_info.lua
@echo ""
@echo "======================================================================"
@echo " Building Lua from source..."
@echo "======================================================================"
make -C $(LUA_DIR) posix
@echo ""
@echo "======================================================================"
@echo " Compiling Lua scripts to bytecode..."
@echo "======================================================================"
$(LUA_DIR)/src/luac -o $(GEN_DIR)/code.luac $(LUA_SRCS)
$(LUA_DIR)/src/lua $(TOOLS_DIR)/bin2c.lua -b -n script_code -o $(GEN_DIR)/code.c $(GEN_DIR)/code.luac
@echo ""
@echo "======================================================================"
@echo " Building wrapper executable..."
@echo "======================================================================"
gcc -O2 -Wall -I$(LUA_DIR)/src -I$(SRC_DIR) -I$(GEN_DIR) -lm -o $(BIN) $(SRC_DIR)/main.c $(MODULE_SRCS) $(LUA_DIR)/src/liblua.a
@echo ""
@echo "======================================================================"
@echo " All done, $(BIN) has been built successfully."
@echo "======================================================================"
clean:
@echo "======================================================================"
@echo " Cleaning Lua source..."
@echo "======================================================================"
make -C $(LUA_DIR) clean
@echo ""
@echo "======================================================================"
@echo " Removing generated code and binaries..."
@echo "======================================================================"
rm -f $(GEN_DIR)/code.luac $(GEN_DIR)/code.c $(BIN)
@echo ""
@echo "======================================================================"
@echo " Clean complete."
@echo "======================================================================"