aboutsummaryrefslogtreecommitdiff
path: root/GNUmakefile
diff options
context:
space:
mode:
Diffstat (limited to 'GNUmakefile')
-rw-r--r--GNUmakefile170
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
5prefix ?= /usr/local
6datarootdir ?= $(prefix)/share
7bindir ?= $(prefix)/bin
8sysconfdir ?= $(prefix)/etc
9INSTALL ?= install
10INSTALL_DATA ?= $(INSTALL) -m 644
11
12LUA_INTERPRETER ?= lua
13ifdef LUA_BINDIR
14LUA = $(LUA_BINDIR)/$(LUA_INTERPRETER)
15SHEBANG = \#!$(LUA_BINDIR)/$(LUA_INTERPRETER)
16else
17LUA = $(LUA_INTERPRETER)
18SHEBANG = \#!/usr/bin/env $(LUA_INTERPRETER)
19endif
20LUA_VERSION ?= $(shell $(LUA) -e 'print(_VERSION:match(" (5%.[1234])$$"))')
21rocks_tree ?= $(prefix)
22luarocksconfdir ?= $(sysconfdir)/luarocks
23luadir ?= $(datarootdir)/lua/$(LUA_VERSION)
24
25
26LUAROCKS_FILES = $(shell find src/luarocks/ -type f -name '*.lua')
27
28all: build
29
30# ----------------------------------------
31# Base build
32# ----------------------------------------
33
34build: luarocks luarocks-admin ./build/luarocks ./build/luarocks-admin
35
36config.unix:
37 @echo Please run the "./configure" script before building.
38 @echo
39 @exit 1
40
41config-$(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
56luarocks: 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
65luarocks-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
92INSTALL_FILES = $(DESTDIR)$(bindir)/luarocks \
93 $(DESTDIR)$(bindir)/luarocks-admin \
94 $(DESTDIR)$(luarocksconfdir)/config-$(LUA_VERSION).lua \
95 $(patsubst src/%, $(DESTDIR)$(luadir)/%, $(LUAROCKS_FILES))
96
97install: $(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
111uninstall:
112 rm -rf $(INSTALL_FILES)
113
114# ----------------------------------------
115# Binary build
116# ----------------------------------------
117
118binary: build-binary/luarocks.exe build-binary/luarocks-admin.exe
119
120build-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
123build-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
130install-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
144bootstrap: luarocks $(DESTDIR)$(luarocksconfdir)/config-$(LUA_VERSION).lua
145 ./luarocks make --tree="$(DESTDIR)$(rocks_tree)"
146
147# ----------------------------------------
148# Windows binary build
149# ----------------------------------------
150
151windows-binary: luarocks
152 make -f binary/Makefile.windows windows-binary
153
154windows-clean:
155 make -f binary/Makefile.windows windows-clean
156
157# ----------------------------------------
158# Clean
159# ----------------------------------------
160
161clean:
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