forked from luarocks/luarocks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GNUmakefile
187 lines (145 loc) · 6.98 KB
/
GNUmakefile
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
-include config.unix
datarootdir = $(prefix)/share
bindir = $(prefix)/bin
INSTALL = install
INSTALL_DATA = $(INSTALL) -m 644
BINARY_PLATFORM = unix
SHEBANG = \#!$(LUA_BINDIR)/$(LUA_INTERPRETER)
LUA = $(LUA_BINDIR)/$(LUA_INTERPRETER)
luarocksconfdir = $(sysconfdir)/luarocks
luadir = $(datarootdir)/lua/$(LUA_VERSION)
builddir = ./build
buildbinarydir = ./build-binary
LUAROCKS_FILES = $(shell find src/luarocks/ -type f -name '*.lua')
all: build
# ----------------------------------------
# Base build
# ----------------------------------------
build: luarocks luarocks-admin $(builddir)/luarocks $(builddir)/luarocks-admin
config.unix:
@echo Please run the "./configure" script before building.
@echo
@exit 1
$(builddir)/config-$(LUA_VERSION).lua: config.unix
mkdir -p "$(@D)"
@printf -- '-- LuaRocks configuration\n\n'\
'rocks_trees = {\n'\
' { name = "user", root = home .. "/.luarocks" };\n'\
"$$([ "$(rocks_tree)" != "$(HOME)/.luarocks" ] && printf ' { name = "system", root = "'"$(rocks_tree)"'" };\\n')"\
'}\n'\
"$$([ -n "$(LUA_INTERPRETER)" ] && printf 'lua_interpreter = "%s";\\n' "$(LUA_INTERPRETER)")"\
'variables = {\n'\
"$$([ -n "$(LUA_DIR)" ] && printf ' LUA_DIR = "%s";\\n' "$(LUA_DIR)")"\
"$$([ -n "$(LUA_INCDIR)" ] && printf ' LUA_INCDIR = "%s";\\n' "$(LUA_INCDIR)")"\
"$$([ -n "$(LUA_BINDIR)" ] && printf ' LUA_BINDIR = "%s";\\n' "$(LUA_BINDIR)")"\
"$$([ -n "$(LUA_LIBDIR)" ] && printf ' LUA_LIBDIR = "%s";\\n' "$(LUA_LIBDIR)")"\
'}\n'\
> $@
luarocks: config.unix $(builddir)/config-$(LUA_VERSION).lua
mkdir -p .luarocks
cp $(builddir)/config-$(LUA_VERSION).lua .luarocks/config-$(LUA_VERSION).lua
rm -f src/luarocks/core/hardcoded.lua
echo "#!/bin/sh" > luarocks
echo "unset LUA_PATH LUA_PATH_5_2 LUA_PATH_5_3 LUA_PATH_5_4 LUA_CPATH LUA_CPATH_5_2 LUA_CPATH_5_3 LUA_CPATH_5_4" >> luarocks
echo 'LUAROCKS_SYSCONFDIR="$(luarocksconfdir)" LUA_PATH="$(CURDIR)/src/?.lua;;" exec "$(LUA)" "$(CURDIR)/src/bin/luarocks" --project-tree="$(CURDIR)/lua_modules" "$$@"' >> luarocks
chmod +rx ./luarocks
./luarocks init
luarocks-admin: config.unix
rm -f src/luarocks/core/hardcoded.lua
echo "#!/bin/sh" > luarocks-admin
echo "unset LUA_PATH LUA_PATH_5_2 LUA_PATH_5_3 LUA_PATH_5_4 LUA_CPATH LUA_CPATH_5_2 LUA_CPATH_5_3 LUA_CPATH_5_4" >> luarocks-admin
echo 'LUAROCKS_SYSCONFDIR="$(luarocksconfdir)" LUA_PATH="$(CURDIR)/src/?.lua;;" exec "$(LUA)" "$(CURDIR)/src/bin/luarocks-admin" --project-tree="$(CURDIR)/lua_modules" "$$@"' >> luarocks-admin
chmod +rx ./luarocks-admin
$(builddir)/luarocks: src/bin/luarocks config.unix
mkdir -p "$(@D)"
(printf '$(SHEBANG)\n'\
'package.loaded["luarocks.core.hardcoded"] = { '\
"$$([ -n "$(FORCE_CONFIG)" ] && printf 'FORCE_CONFIG = true, ')"\
'SYSCONFDIR = [[$(luarocksconfdir)]] }\n'\
'package.path=[[$(luadir)/?.lua;]] .. package.path\n'\
'local list = package.searchers or package.loaders; table.insert(list, 1, function(name) if name:match("^luarocks%%.") then return loadfile([[$(luadir)/]] .. name:gsub([[%%.]], [[/]]) .. [[.lua]]) end end)\n'; \
tail -n +2 src/bin/luarocks \
)> "$@"
$(builddir)/luarocks-admin: src/bin/luarocks-admin config.unix
mkdir -p "$(@D)"
(printf '$(SHEBANG)\n'\
'package.loaded["luarocks.core.hardcoded"] = { '\
"$$([ -n "$(FORCE_CONFIG)" ] && printf 'FORCE_CONFIG = true, ')"\
'SYSCONFDIR = [[$(luarocksconfdir)]] }\n'\
'package.path=[[$(luadir)/?.lua;]] .. package.path\n'\
'local list = package.searchers or package.loaders; table.insert(list, 1, function(name) if name:match("^luarocks%%.") then return loadfile([[$(luadir)/]] .. name:gsub([[%%.]], [[/]]) .. [[.lua]]) end end)\n'; \
tail -n +2 src/bin/luarocks-admin \
)> "$@"
# ----------------------------------------
# Base build
# ----------------------------------------
binary: luarocks $(buildbinarydir)/luarocks.exe $(buildbinarydir)/luarocks-admin.exe
$(buildbinarydir)/luarocks.exe: src/bin/luarocks $(LUAROCKS_FILES)
(unset $(LUA_ENV_VARS); \
"$(LUA)" binary/all_in_one "$<" "$(LUA_DIR)" "^src/luarocks/admin/" "$(luarocksconfdir)" "$(@D)" "$(FORCE_CONFIG)" $(BINARY_PLATFORM) $(CC) $(NM) $(BINARY_SYSROOT))
$(buildbinarydir)/luarocks-admin.exe: src/bin/luarocks-admin $(LUAROCKS_FILES)
(unset $(LUA_ENV_VARS); \
"$(LUA)" binary/all_in_one "$<" "$(LUA_DIR)" "^src/luarocks/cmd/" "$(luarocksconfdir)" "$(@D)" "$(FORCE_CONFIG)" $(BINARY_PLATFORM) $(CC) $(NM) $(BINARY_SYSROOT))
# ----------------------------------------
# Regular install
# ----------------------------------------
INSTALL_FILES = $(DESTDIR)$(bindir)/luarocks \
$(DESTDIR)$(bindir)/luarocks-admin \
$(DESTDIR)$(luarocksconfdir)/config-$(LUA_VERSION).lua \
$(patsubst src/%, $(DESTDIR)$(luadir)/%, $(LUAROCKS_FILES))
install: $(INSTALL_FILES)
install-config: $(DESTDIR)$(luarocksconfdir)/config-$(LUA_VERSION).lua
$(DESTDIR)$(bindir)/luarocks: $(builddir)/luarocks
mkdir -p "$(@D)"
$(INSTALL) "$<" "$@"
$(DESTDIR)$(bindir)/luarocks-admin: $(builddir)/luarocks-admin
mkdir -p "$(@D)"
$(INSTALL) "$<" "$@"
$(DESTDIR)$(luadir)/luarocks/%.lua: src/luarocks/%.lua
mkdir -p "$(@D)"
$(INSTALL_DATA) "$<" "$@"
$(DESTDIR)$(luarocksconfdir)/config-$(LUA_VERSION).lua: $(builddir)/config-$(LUA_VERSION).lua
mkdir -p "$(@D)"
$(INSTALL_DATA) "$<" "$@"
uninstall:
rm -rf $(INSTALL_FILES)
# ----------------------------------------
# Binary install
# ----------------------------------------
LUAROCKS_CORE_FILES = $(wildcard src/luarocks/core/* src/luarocks/loader.lua)
INSTALL_BINARY_FILES = $(patsubst src/%, $(DESTDIR)$(luadir)/%, $(LUAROCKS_CORE_FILES)) \
$(DESTDIR)$(luarocksconfdir)/config-$(LUA_VERSION).lua
install-binary: $(INSTALL_BINARY_FILES)
mkdir -p "$(buildbinarydir)"
$(INSTALL) "$(buildbinarydir)/luarocks.exe" "$(DESTDIR)$(bindir)/luarocks"
$(INSTALL) "$(buildbinarydir)/luarocks-admin.exe" "$(DESTDIR)$(bindir)/luarocks-admin"
# ----------------------------------------
# Bootstrap install
# ----------------------------------------
bootstrap: luarocks $(DESTDIR)$(luarocksconfdir)/config-$(LUA_VERSION).lua
./luarocks make --tree="$(DESTDIR)$(rocks_tree)"
# ----------------------------------------
# Windows binary build
# ----------------------------------------
windows-binary: windows-binary-32 windows-binary-64
windows-clean: windows-clean-32 windows-clean-64
windows-binary-32: luarocks
$(MAKE) -f binary/Makefile.windows windows-binary MINGW_PREFIX=i686-w64-mingw32 OPENSSL_PLATFORM=mingw
windows-clean-32:
$(MAKE) -f binary/Makefile.windows windows-clean MINGW_PREFIX=i686-w64-mingw32 OPENSSL_PLATFORM=mingw
windows-binary-64: luarocks
$(MAKE) -f binary/Makefile.windows windows-binary MINGW_PREFIX=x86_64-w64-mingw32 OPENSSL_PLATFORM=mingw64
windows-clean-64:
$(MAKE) -f binary/Makefile.windows windows-clean MINGW_PREFIX=x86_64-w64-mingw32 OPENSSL_PLATFORM=mingw64
# ----------------------------------------
# Clean
# ----------------------------------------
clean: windows-clean
rm -rf ./config.unix \
./luarocks \
./luarocks-admin \
$(builddir)/ \
$(buildbinarydir)/ \
./.luarocks \
./lua_modules
.PHONY: all build install binary install-binary bootstrap clean windows-binary windows-clean