diff options
Diffstat (limited to 'GNUmakefile')
-rw-r--r-- | GNUmakefile | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 00000000..d365454a --- /dev/null +++ b/GNUmakefile | |||
@@ -0,0 +1,170 @@ | |||
1 | |||
2 | -include config.unix | ||
3 | |||
4 | # See https://www.gnu.org/software/make/manual/html_node/Makefile-Conventions.html | ||
5 | prefix ?= /usr/local | ||
6 | datarootdir ?= $(prefix)/share | ||
7 | bindir ?= $(prefix)/bin | ||
8 | sysconfdir ?= $(prefix)/etc | ||
9 | INSTALL ?= install | ||
10 | INSTALL_DATA ?= $(INSTALL) -m 644 | ||
11 | |||
12 | LUA_INTERPRETER ?= lua | ||
13 | ifdef LUA_BINDIR | ||
14 | LUA = $(LUA_BINDIR)/$(LUA_INTERPRETER) | ||
15 | SHEBANG = \#!$(LUA_BINDIR)/$(LUA_INTERPRETER) | ||
16 | else | ||
17 | LUA = $(LUA_INTERPRETER) | ||
18 | SHEBANG = \#!/usr/bin/env $(LUA_INTERPRETER) | ||
19 | endif | ||
20 | LUA_VERSION ?= $(shell $(LUA) -e 'print(_VERSION:match(" (5%.[1234])$$"))') | ||
21 | rocks_tree ?= $(prefix) | ||
22 | luarocksconfdir ?= $(sysconfdir)/luarocks | ||
23 | luadir ?= $(datarootdir)/lua/$(LUA_VERSION) | ||
24 | |||
25 | |||
26 | LUAROCKS_FILES = $(shell find src/luarocks/ -type f -name '*.lua') | ||
27 | |||
28 | all: build | ||
29 | |||
30 | # ---------------------------------------- | ||
31 | # Base build | ||
32 | # ---------------------------------------- | ||
33 | |||
34 | build: luarocks luarocks-admin ./build/luarocks ./build/luarocks-admin | ||
35 | |||
36 | config.unix: | ||
37 | @echo Please run the "./configure" script before building. | ||
38 | @echo | ||
39 | @exit 1 | ||
40 | |||
41 | config-$(LUA_VERSION).lua.in: config.unix | ||
42 | @printf -- '-- LuaRocks configuration\n\n'\ | ||
43 | 'rocks_trees = {\n'\ | ||
44 | ' { name = "user", root = home .. "/.luarocks" };\n'\ | ||
45 | ' { name = "system", root = "'"$(rocks_tree)"'" };\n'\ | ||
46 | '}\n'\ | ||
47 | "$$([ -n "$(LUA_INTERPRETER)" ] && printf 'lua_interpreter = "%s";\\n' "$(LUA_INTERPRETER)")"\ | ||
48 | 'variables = {\n'\ | ||
49 | "$$([ -n "$(LUA_DIR)" ] && printf ' LUA_DIR = "%s";\\n' "$(LUA_DIR)")"\ | ||
50 | "$$([ -n "$(LUA_INCDIR)" ] && printf ' LUA_INCDIR = "%s";\\n' "$(LUA_INCDIR)")"\ | ||
51 | "$$([ -n "$(LUA_BINDIR)" ] && printf ' LUA_BINDIR = "%s";\\n' "$(LUA_BINDIR)")"\ | ||
52 | "$$([ -n "$(LUA_LIBDIR)" ] && printf ' LUA_LIBDIR = "%s";\\n' "$(LUA_LIBDIR)")"\ | ||
53 | '}\n'\ | ||
54 | > $@ | ||
55 | |||
56 | luarocks: config.unix config-$(LUA_VERSION).lua.in | ||
57 | rm -f src/luarocks/core/hardcoded.lua | ||
58 | echo "#!/bin/sh" > luarocks | ||
59 | echo "unset LUA_PATH LUA_PATH_5_2 LUA_PATH_5_3 LUA_PATH_5_4" >> luarocks | ||
60 | echo 'LUAROCKS_SYSCONFDIR="$(luarocksconfdir)" LUA_PATH="$(CURDIR)/src/?.lua;;" exec "$(LUA_BINDIR)/$(LUA_INTERPRETER)" "$(CURDIR)/src/bin/luarocks" --project-tree="$(CURDIR)/lua_modules" "$$@"' >> luarocks | ||
61 | chmod +rx ./luarocks | ||
62 | ./luarocks init | ||
63 | cp config-$(LUA_VERSION).lua.in .luarocks/config-$(LUA_VERSION).lua | ||
64 | |||
65 | luarocks-admin: config.unix | ||
66 | rm -f src/luarocks/core/hardcoded.lua | ||
67 | echo "#!/bin/sh" > luarocks-admin | ||
68 | echo "unset LUA_PATH LUA_PATH_5_2 LUA_PATH_5_3 LUA_PATH_5_4" >> luarocks-admin | ||
69 | echo 'LUAROCKS_SYSCONFDIR="$(luarocksconfdir)" LUA_PATH="$(CURDIR)/src/?.lua;;" exec "$(LUA_BINDIR)/$(LUA_INTERPRETER)" "$(CURDIR)/src/bin/luarocks-admin" --project-tree="$(CURDIR)/lua_modules" "$$@"' >> luarocks-admin | ||
70 | chmod +rx ./luarocks-admin | ||
71 | |||
72 | ./build/luarocks: src/bin/luarocks config.unix | ||
73 | mkdir -p "$(@D)" | ||
74 | (printf '$(SHEBANG)\n'\ | ||
75 | 'package.loaded["luarocks.core.hardcoded"] = { SYSCONFDIR = [[$(luarocksconfdir)]] }\n'\ | ||
76 | 'package.path=[[$(luadir)/?.lua;]] .. package.path\n'; \ | ||
77 | tail -n +2 src/bin/luarocks \ | ||
78 | )> "$@" | ||
79 | |||
80 | ./build/luarocks-admin: src/bin/luarocks-admin config.unix | ||
81 | mkdir -p "$(@D)" | ||
82 | (printf '$(SHEBANG)\n'\ | ||
83 | 'package.loaded["luarocks.core.hardcoded"] = { SYSCONFDIR = [[$(luarocksconfdir)]] }\n'\ | ||
84 | 'package.path=[[$(luadir)/?.lua;]] .. package.path\n'; \ | ||
85 | tail -n +2 src/bin/luarocks-admin \ | ||
86 | )> "$@" | ||
87 | |||
88 | # ---------------------------------------- | ||
89 | # Regular install | ||
90 | # ---------------------------------------- | ||
91 | |||
92 | INSTALL_FILES = $(DESTDIR)$(bindir)/luarocks \ | ||
93 | $(DESTDIR)$(bindir)/luarocks-admin \ | ||
94 | $(DESTDIR)$(luarocksconfdir)/config-$(LUA_VERSION).lua \ | ||
95 | $(patsubst src/%, $(DESTDIR)$(luadir)/%, $(LUAROCKS_FILES)) | ||
96 | |||
97 | install: $(INSTALL_FILES) | ||
98 | |||
99 | $(DESTDIR)$(bindir)/luarocks: ./build/luarocks | ||
100 | $(INSTALL) -D "$<" "$@" | ||
101 | |||
102 | $(DESTDIR)$(bindir)/luarocks-admin: ./build/luarocks-admin | ||
103 | $(INSTALL) -D "$<" "$@" | ||
104 | |||
105 | $(DESTDIR)$(luadir)/luarocks/%.lua: src/luarocks/%.lua | ||
106 | $(INSTALL_DATA) -D "$<" "$@" | ||
107 | |||
108 | $(DESTDIR)$(luarocksconfdir)/config-$(LUA_VERSION).lua: config-$(LUA_VERSION).lua.in | ||
109 | $(INSTALL_DATA) -D "$<" "$@" | ||
110 | |||
111 | uninstall: | ||
112 | rm -rf $(INSTALL_FILES) | ||
113 | |||
114 | # ---------------------------------------- | ||
115 | # Binary build | ||
116 | # ---------------------------------------- | ||
117 | |||
118 | binary: build-binary/luarocks.exe build-binary/luarocks-admin.exe | ||
119 | |||
120 | build-binary/luarocks.exe: luarocks | ||
121 | LUA_PATH="$(CURDIR)/src/?.lua;;" "$(LUA_BINDIR)/$(LUA_INTERPRETER)" binary/all_in_one "src/bin/luarocks" "$(LUA_DIR)" "^src/luarocks/admin/" "$(luarocksconfdir)" build-binary $(BINARY_PLATFORM) $(BINARY_CC) $(BINARY_NM) $(BINARY_SYSROOT) | ||
122 | |||
123 | build-binary/luarocks-admin.exe: luarocks | ||
124 | LUA_PATH="$(CURDIR)/src/?.lua;;" "$(LUA_BINDIR)/$(LUA_INTERPRETER)" binary/all_in_one "src/bin/luarocks-admin" "$(LUA_DIR)" "^src/luarocks/cmd/" "$(luarocksconfdir)" build-binary $(BINARY_PLATFORM) $(BINARY_CC) $(BINARY_NM) $(BINARY_SYSROOT) | ||
125 | |||
126 | # ---------------------------------------- | ||
127 | # Binary install | ||
128 | # ---------------------------------------- | ||
129 | |||
130 | install-binary: build-binary/luarocks.exe build-binary/luarocks-admin.exe | ||
131 | mkdir -p "$(DESTDIR)$(bindir)" | ||
132 | cp build-binary/luarocks.exe "$(DESTDIR)$(bindir)/luarocks" | ||
133 | chmod +rx "$(DESTDIR)$(bindir)/luarocks" | ||
134 | cp build-binary/luarocks-admin.exe "$(DESTDIR)$(bindir)/luarocks-admin" | ||
135 | chmod +rx "$(DESTDIR)$(bindir)/luarocks-admin" | ||
136 | mkdir -p "$(DESTDIR)$(luadir)/luarocks/core" | ||
137 | cp -a src/luarocks/core/* "$(DESTDIR)$(luadir)/luarocks/core" | ||
138 | cp -a src/luarocks/loader.lua "$(DESTDIR)$(luadir)/luarocks/" | ||
139 | |||
140 | # ---------------------------------------- | ||
141 | # Bootstrap install | ||
142 | # ---------------------------------------- | ||
143 | |||
144 | bootstrap: luarocks $(DESTDIR)$(luarocksconfdir)/config-$(LUA_VERSION).lua | ||
145 | ./luarocks make --tree="$(DESTDIR)$(rocks_tree)" | ||
146 | |||
147 | # ---------------------------------------- | ||
148 | # Windows binary build | ||
149 | # ---------------------------------------- | ||
150 | |||
151 | windows-binary: luarocks | ||
152 | make -f binary/Makefile.windows windows-binary | ||
153 | |||
154 | windows-clean: | ||
155 | make -f binary/Makefile.windows windows-clean | ||
156 | |||
157 | # ---------------------------------------- | ||
158 | # Clean | ||
159 | # ---------------------------------------- | ||
160 | |||
161 | clean: | ||
162 | rm -rf ./config.unix \ | ||
163 | ./luarocks \ | ||
164 | ./luarocks-admin \ | ||
165 | ./build/ \ | ||
166 | build-binary \ | ||
167 | ./.luarocks \ | ||
168 | ./lua_modules | ||
169 | |||
170 | .PHONY: all build install binary install-binary bootstrap clean windows-binary windows-clean | ||