diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-01 15:21:16 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-01 22:54:07 -0300 |
commit | 98d1f1da856ab59cf8355c1e2e11e3c0eb954fb2 (patch) | |
tree | aeb6d9e6f45423cf5698930aea2bc55a8d721fa9 /binary | |
parent | cc4c9f6321ebaaf71f8c9c26bd30967e93bd2cbb (diff) | |
download | luarocks-98d1f1da856ab59cf8355c1e2e11e3c0eb954fb2.tar.gz luarocks-98d1f1da856ab59cf8355c1e2e11e3c0eb954fb2.tar.bz2 luarocks-98d1f1da856ab59cf8355c1e2e11e3c0eb954fb2.zip |
Unix: new build system
* Reworked configure script
* Now passes shellcheck
* New Makefile for Unix
* Simplified `make` and `make install` targets
* Simplified `make bootstrap` target
* New targets `make binary` and `make install-binary`
build and install an all-in-one binary of LuaRocks
Diffstat (limited to 'binary')
-rwxr-xr-x | binary/all_in_one | 442 | ||||
-rw-r--r-- | binary/luaposix-34.0.4-1.rockspec | 55 | ||||
-rw-r--r-- | binary/luasec-0.7alpha-2.rockspec | 119 | ||||
-rwxr-xr-x | binary/static-gcc | 158 |
4 files changed, 774 insertions, 0 deletions
diff --git a/binary/all_in_one b/binary/all_in_one new file mode 100755 index 00000000..de545d04 --- /dev/null +++ b/binary/all_in_one | |||
@@ -0,0 +1,442 @@ | |||
1 | #!/usr/bin/env lua | ||
2 | --[[ | ||
3 | |||
4 | All-in-one packager for LuaRocks | ||
5 | * by Hisham Muhammad <hisham@gobolinux.org> | ||
6 | * licensed under the same terms as Lua (MIT license). | ||
7 | |||
8 | Based on: | ||
9 | |||
10 | * srlua.c - Lua interpreter for self-running programs | ||
11 | * by Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> | ||
12 | * 03 Nov 2014 15:31:43 | ||
13 | * srlua.c is placed in the public domain. | ||
14 | * bin2c.lua - converts a binary to a C string that can be embedded | ||
15 | * by Mark Edgar | ||
16 | * http://lua-users.org/wiki/BinTwoCee | ||
17 | * bin2c.lua is licensed under the same terms as Lua (MIT license). | ||
18 | * lua.c - Lua stand-alone interpreter | ||
19 | * by Luiz Henrique de Figueiredo, Waldemar Celes, Roberto Ierusalimschy | ||
20 | * lua.c is licensed under the same terms as Lua (MIT license). | ||
21 | * luastatic - builds a standalone executable from a Lua program | ||
22 | * by Eric R. Schulz | ||
23 | * https://github.com/ers35/luastatic | ||
24 | * luastatic is licensed under the CC0 1.0 Universal license | ||
25 | |||
26 | ]] | ||
27 | |||
28 | local MAIN_PROGRAM = arg[1] or "src/bin/luarocks" | ||
29 | local LUA_DIR = arg[2] or "/usr" | ||
30 | local EXCLUDE = arg[3] or "^src/luarocks/admin/" | ||
31 | local SYSCONFDIR = arg[4] or "/etc/luarocks" | ||
32 | local TARGET = arg[5] or "binary-build" | ||
33 | |||
34 | local LUA_MODULES = TARGET .. "/lua_modules" | ||
35 | local CONFIG_DIR = TARGET .. "/.luarocks" | ||
36 | |||
37 | package.path = "./src/?.lua;" .. package.path | ||
38 | |||
39 | local fs = require("luarocks.fs") | ||
40 | local cfg = require("luarocks.core.cfg") | ||
41 | local cmd = require("luarocks.cmd") | ||
42 | local deps = require("luarocks.deps") | ||
43 | local util = require("luarocks.util") | ||
44 | local path = require("luarocks.path") | ||
45 | local manif = require("luarocks.manif") | ||
46 | local queries = require("luarocks.queries") | ||
47 | local persist = require("luarocks.persist") | ||
48 | |||
49 | -------------------------------------------------------------------------------- | ||
50 | |||
51 | local function reindent_c(input) | ||
52 | local out = {} | ||
53 | local indent = 0 | ||
54 | local previous_is_blank = true | ||
55 | for line in input:gmatch("([^\n]*)") do | ||
56 | line = line:match("^[ \t]*(.-)[ \t]*$") | ||
57 | |||
58 | local is_blank = (#line == 0) | ||
59 | local do_print = | ||
60 | (not is_blank) or | ||
61 | (not previous_is_blank and indent == 0) | ||
62 | |||
63 | if line:match("^[})]") then | ||
64 | indent = indent - 1 | ||
65 | if indent < 0 then indent = 0 end | ||
66 | end | ||
67 | if do_print then | ||
68 | table.insert(out, string.rep(" ", indent)) | ||
69 | table.insert(out, line) | ||
70 | table.insert(out, "\n") | ||
71 | end | ||
72 | if line:match("[{(]$") then | ||
73 | indent = indent + 1 | ||
74 | end | ||
75 | |||
76 | previous_is_blank = is_blank | ||
77 | end | ||
78 | return table.concat(out) | ||
79 | end | ||
80 | |||
81 | local hexdump | ||
82 | do | ||
83 | local numtab = {} | ||
84 | for i = 0, 255 do | ||
85 | numtab[string.char(i)] = ("%-3d,"):format(i) | ||
86 | end | ||
87 | function hexdump(str) | ||
88 | return (str:gsub(".", numtab):gsub(("."):rep(80), "%0\n")) | ||
89 | end | ||
90 | end | ||
91 | |||
92 | local c_preamble = [[ | ||
93 | |||
94 | #include <lua.h> | ||
95 | #include <lualib.h> | ||
96 | #include <lauxlib.h> | ||
97 | #include <errno.h> | ||
98 | #include <stdio.h> | ||
99 | #include <stdlib.h> | ||
100 | |||
101 | /* portable alerts, from srlua */ | ||
102 | #ifdef _WIN32 | ||
103 | #include <windows.h> | ||
104 | #define alert(message) MessageBox(NULL, message, progname, MB_ICONERROR | MB_OK) | ||
105 | #define getprogname() char name[MAX_PATH]; argv[0]= GetModuleFileName(NULL,name,sizeof(name)) ? name : NULL; | ||
106 | #else | ||
107 | #define alert(message) fprintf(stderr,"%s: %s\n", progname, message) | ||
108 | #define getprogname() | ||
109 | #endif | ||
110 | |||
111 | static int registry_key; | ||
112 | |||
113 | ]] | ||
114 | |||
115 | local function bin2c_file(out, filename) | ||
116 | local content = string.dump(assert(loadfile(filename))) | ||
117 | table.insert(out, ("static const unsigned char code[] = {")) | ||
118 | table.insert(out, hexdump(content)) | ||
119 | table.insert(out, ("};")) | ||
120 | end | ||
121 | |||
122 | local function write_hardcoded_module(dir) | ||
123 | |||
124 | local system = util.popen_read("uname -s") | ||
125 | local processor = util.popen_read("uname -m") | ||
126 | |||
127 | if processor:match("i[%d]86") then | ||
128 | processor = "x86" | ||
129 | elseif processor:match("amd64") or processor:match("x86_64") then | ||
130 | processor = "x86_64" | ||
131 | elseif processor:match("Power Macintosh") then | ||
132 | processor = "powerpc" | ||
133 | end | ||
134 | |||
135 | local hardcoded = { | ||
136 | SYSTEM = system, | ||
137 | PROCESSOR = processor, | ||
138 | SYSCONFDIR = SYSCONFDIR, | ||
139 | LUA_DIR = cfg.variables.LUA_DIR, | ||
140 | LUA_BINDIR = cfg.variables.LUA_BINDIR, | ||
141 | LUA_INTERPRETER = cfg.lua_interpreter, | ||
142 | } | ||
143 | |||
144 | local name = dir .. "/luarocks/core/hardcoded.lua" | ||
145 | persist.save_as_module(name, hardcoded) | ||
146 | return name | ||
147 | end | ||
148 | |||
149 | local function declare_modules(out, dirs, skip) | ||
150 | skip = skip or {} | ||
151 | table.insert(out, [[ | ||
152 | static void declare_modules(lua_State* L) { | ||
153 | lua_settop(L, 0); /* */ | ||
154 | lua_newtable(L); /* modules */ | ||
155 | lua_pushlightuserdata(L, (void*) ®istry_key); /* modules registry_key */ | ||
156 | lua_pushvalue(L, 1); /* modules registry_key modules */ | ||
157 | lua_rawset(L, LUA_REGISTRYINDEX); /* modules */ | ||
158 | ]]) | ||
159 | for _, dir in ipairs(dirs) do | ||
160 | for _, name in ipairs(fs.find(dir)) do | ||
161 | local run = true | ||
162 | for _, pat in ipairs(skip) do | ||
163 | if name:match(pat) then | ||
164 | run = false | ||
165 | break | ||
166 | end | ||
167 | end | ||
168 | if run then | ||
169 | local filename = dir .. "/" .. name | ||
170 | if fs.is_file(filename) then | ||
171 | print(name) | ||
172 | local modname = name:gsub("%.lua$", ""):gsub("/", ".") | ||
173 | table.insert(out, ("/* %s */"):format(modname)) | ||
174 | table.insert(out, ("{")) | ||
175 | bin2c_file(out, filename) | ||
176 | table.insert(out, ("luaL_loadbuffer(L, code, sizeof(code), %q);"):format(filename)) | ||
177 | table.insert(out, ("lua_setfield(L, 1, %q);"):format(modname)) | ||
178 | table.insert(out, ("}")) | ||
179 | end | ||
180 | end | ||
181 | end | ||
182 | end | ||
183 | table.insert(out, [[ | ||
184 | lua_settop(L, 0); /* */ | ||
185 | } | ||
186 | ]]) | ||
187 | end | ||
188 | |||
189 | local function nm(filename) | ||
190 | local pd = io.popen("nm " .. filename) | ||
191 | local out = pd:read("*a") | ||
192 | pd:close() | ||
193 | return out | ||
194 | end | ||
195 | |||
196 | local function declare_libraries(out, dir) | ||
197 | local a_files = {} | ||
198 | local externs = {} | ||
199 | local fn = {} | ||
200 | table.insert(fn, [[ | ||
201 | static void declare_libraries(lua_State* L) { | ||
202 | lua_getglobal(L, "package"); /* package */ | ||
203 | lua_getfield(L, -1, "preload"); /* package package.preload */ | ||
204 | ]]) | ||
205 | for _, name in ipairs(fs.find(dir)) do | ||
206 | local filename = dir .. "/" .. name | ||
207 | if name:match("%.a$") then | ||
208 | table.insert(a_files, filename) | ||
209 | local nmout = nm(filename) | ||
210 | for luaopen in nmout:gmatch("[^dD] _?(luaopen_[%a%p%d]+)") do | ||
211 | |||
212 | -- FIXME what about module names with underscores? | ||
213 | local modname = luaopen:gsub("^_?luaopen_", ""):gsub("_", ".") | ||
214 | |||
215 | table.insert(externs, "extern int " .. luaopen .. "(lua_State* L);") | ||
216 | table.insert(fn, "lua_pushcfunction(L, " .. luaopen .. ");") | ||
217 | table.insert(fn, "lua_setfield(L, -2, \"" .. modname .. "\");") | ||
218 | end | ||
219 | end | ||
220 | end | ||
221 | local pd = io.popen("find " .. dir .. " -name '*.a'", "r") | ||
222 | for line in pd:lines() do | ||
223 | table.insert(a_files, line) | ||
224 | end | ||
225 | pd:close() | ||
226 | table.insert(fn, [[ | ||
227 | lua_settop(L, 0); /* */ | ||
228 | } | ||
229 | ]]) | ||
230 | |||
231 | table.insert(out, "\n") | ||
232 | for _, line in ipairs(externs) do | ||
233 | table.insert(out, line) | ||
234 | end | ||
235 | table.insert(out, "\n") | ||
236 | for _, line in ipairs(fn) do | ||
237 | table.insert(out, line) | ||
238 | end | ||
239 | table.insert(out, "\n") | ||
240 | |||
241 | return a_files | ||
242 | end | ||
243 | |||
244 | local function load_main(out, main_program, program_name) | ||
245 | table.insert(out, [[static void load_main(lua_State* L) {]]) | ||
246 | bin2c_file(out, main_program) | ||
247 | table.insert(out, ("luaL_loadbuffer(L, code, sizeof(code), %q);"):format(program_name)) | ||
248 | table.insert(out, [[}]]) | ||
249 | table.insert(out, [[]]) | ||
250 | end | ||
251 | |||
252 | local c_main = [[ | ||
253 | |||
254 | /* custom package loader */ | ||
255 | static int pkg_loader(lua_State* L) { | ||
256 | lua_pushlightuserdata(L, (void*) ®istry_key); /* modname ? registry_key */ | ||
257 | lua_rawget(L, LUA_REGISTRYINDEX); /* modname ? modules */ | ||
258 | lua_pushvalue(L, -1); /* modname ? modules modules */ | ||
259 | lua_pushvalue(L, 1); /* modname ? modules modules modname */ | ||
260 | lua_gettable(L, -2); /* modname ? modules mod */ | ||
261 | if (lua_type(L, -1) == LUA_TNIL) { | ||
262 | lua_pop(L, 1); /* modname ? modules */ | ||
263 | lua_pushvalue(L, 1); /* modname ? modules modname */ | ||
264 | lua_pushliteral(L, ".init"); /* modname ? modules modname ".init" */ | ||
265 | lua_concat(L, 2); /* modname ? modules modname .. ".init" */ | ||
266 | lua_gettable(L, -2); /* modname ? mod */ | ||
267 | } | ||
268 | return 1; | ||
269 | } | ||
270 | |||
271 | static void install_pkg_loader(lua_State* L) { | ||
272 | lua_settop(L, 0); /* */ | ||
273 | lua_getglobal(L, "table"); /* table */ | ||
274 | lua_getfield(L, -1, "insert"); /* table table.insert */ | ||
275 | lua_getglobal(L, "package"); /* table table.insert package */ | ||
276 | lua_getfield(L, -1, "searchers"); /* table table.insert package package.searchers */ | ||
277 | if (lua_type(L, -1) == LUA_TNIL) { | ||
278 | lua_pop(L, 1); | ||
279 | lua_getfield(L, -1, "loaders"); /* table table.insert package package.loaders */ | ||
280 | } | ||
281 | lua_copy(L, 4, 3); /* table table.insert package.searchers */ | ||
282 | lua_settop(L, 3); /* table table.insert package.searchers */ | ||
283 | lua_pushnumber(L, 1); /* table table.insert package.searchers 1 */ | ||
284 | lua_pushcfunction(L, pkg_loader); /* table table.insert package.searchers 1 pkg_loader */ | ||
285 | lua_call(L, 3, 0); /* table */ | ||
286 | lua_settop(L, 0); /* */ | ||
287 | } | ||
288 | |||
289 | /* main script launcher, from srlua */ | ||
290 | static int pmain(lua_State *L) { | ||
291 | int argc = lua_tointeger(L, 1); | ||
292 | char** argv = lua_touserdata(L, 2); | ||
293 | int i; | ||
294 | load_main(L); | ||
295 | lua_createtable(L, argc, 0); | ||
296 | for (i = 0; i < argc; i++) { | ||
297 | lua_pushstring(L, argv[i]); | ||
298 | lua_rawseti(L, -2, i); | ||
299 | } | ||
300 | lua_setglobal(L, "arg"); | ||
301 | luaL_checkstack(L, argc - 1, "too many arguments to script"); | ||
302 | for (i = 1; i < argc; i++) { | ||
303 | lua_pushstring(L, argv[i]); | ||
304 | } | ||
305 | lua_call(L, argc - 1, 0); | ||
306 | return 0; | ||
307 | } | ||
308 | |||
309 | /* fatal error, from srlua */ | ||
310 | static void fatal(const char* message) { | ||
311 | alert(message); | ||
312 | exit(EXIT_FAILURE); | ||
313 | } | ||
314 | |||
315 | /* error handler, from luac */ | ||
316 | static int msghandler (lua_State *L) { | ||
317 | /* is error object not a string? */ | ||
318 | const char *msg = lua_tostring(L, 1); | ||
319 | if (msg == NULL) { | ||
320 | /* does it have a metamethod that produces a string */ | ||
321 | if (luaL_callmeta(L, 1, "__tostring") && lua_type(L, -1) == LUA_TSTRING) { | ||
322 | /* then that is the message */ | ||
323 | return 1; | ||
324 | } else { | ||
325 | msg = lua_pushfstring(L, "(error object is a %s value)", luaL_typename(L, 1)); | ||
326 | } | ||
327 | } | ||
328 | /* append a standard traceback */ | ||
329 | luaL_traceback(L, L, msg, 1); | ||
330 | return 1; | ||
331 | } | ||
332 | |||
333 | /* main function, from srlua */ | ||
334 | int main(int argc, char** argv) { | ||
335 | lua_State* L; | ||
336 | getprogname(); | ||
337 | if (argv[0] == NULL) { | ||
338 | fatal("cannot locate this executable"); | ||
339 | } | ||
340 | L = luaL_newstate(); | ||
341 | if (L == NULL) { | ||
342 | fatal("not enough memory for state"); | ||
343 | } | ||
344 | luaL_openlibs(L); | ||
345 | install_pkg_loader(L); | ||
346 | declare_libraries(L); | ||
347 | declare_modules(L); | ||
348 | lua_pushcfunction(L, &msghandler); | ||
349 | lua_pushcfunction(L, &pmain); | ||
350 | lua_pushinteger(L, argc); | ||
351 | lua_pushlightuserdata(L, argv); | ||
352 | if (lua_pcall(L, 2, 0, -4) != 0) { | ||
353 | fatal(lua_tostring(L, -1)); | ||
354 | } | ||
355 | lua_close(L); | ||
356 | return EXIT_SUCCESS; | ||
357 | } | ||
358 | |||
359 | ]] | ||
360 | |||
361 | local function generate(main_program, dir, skip) | ||
362 | local program_name = main_program:gsub(".*/", "") | ||
363 | |||
364 | local hardcoded = write_hardcoded_module(dir) | ||
365 | |||
366 | local out = {} | ||
367 | table.insert(out, c_preamble) | ||
368 | table.insert(out, ([[static const char* progname = %q;]]):format(program_name)) | ||
369 | load_main(out, main_program, program_name) | ||
370 | local lua_modules = LUA_MODULES .. "/share/lua/" .. cfg.lua_version | ||
371 | declare_modules(out, { dir, lua_modules }, skip) | ||
372 | local a_files = declare_libraries(out, LUA_MODULES .. "/lib/lua/" .. cfg.lua_version) | ||
373 | table.insert(out, c_main) | ||
374 | |||
375 | os.remove(hardcoded) | ||
376 | |||
377 | local c_filename = TARGET .. "/" .. program_name .. ".exe.c" | ||
378 | local fd = io.open(c_filename, "w") | ||
379 | fd:write(reindent_c(table.concat(out, "\n"))) | ||
380 | fd:close() | ||
381 | |||
382 | cmd = table.concat({ | ||
383 | "gcc", "-o", TARGET .. "/" .. program_name .. ".exe", | ||
384 | "-I", cfg.variables.LUA_INCDIR, | ||
385 | "-rdynamic", | ||
386 | "-Os", | ||
387 | c_filename, | ||
388 | "-L", cfg.variables.LUA_LIBDIR, | ||
389 | table.concat(a_files, " "), | ||
390 | cfg.variables.LUA_LIBDIR .. "/" .. cfg.variables.LUALIB:gsub("%.so.*$", ".a"), | ||
391 | "-ldl", "-lm"}, " ") | ||
392 | print(cmd) | ||
393 | os.execute(cmd) | ||
394 | end | ||
395 | |||
396 | -------------------------------------------------------------------------------- | ||
397 | |||
398 | local function main() | ||
399 | |||
400 | cfg.init(cmd.find_lua(LUA_DIR)) | ||
401 | fs.init() | ||
402 | deps.check_lua(cfg.variables) | ||
403 | path.use_tree("./" .. LUA_MODULES) | ||
404 | |||
405 | local CONFIG_FILE = CONFIG_DIR .. "/config-" .. cfg.lua_version .. ".lua" | ||
406 | |||
407 | fs.make_dir(CONFIG_DIR) | ||
408 | local fd = io.open(CONFIG_FILE, "w") | ||
409 | fd:write([[ | ||
410 | lib_extension = "a" | ||
411 | external_lib_extension = "a" | ||
412 | variables = { | ||
413 | CC = "]] .. fs.current_dir() .. [[/static-gcc", | ||
414 | LD = "]] .. fs.current_dir() .. [[/static-gcc", | ||
415 | LIB_EXTENSION = "a", | ||
416 | LIBFLAG = "-static", | ||
417 | } | ||
418 | ]]) | ||
419 | fd:close() | ||
420 | |||
421 | local dependencies = { | ||
422 | md5 = "md5", | ||
423 | luazip = "luazip", | ||
424 | luasec = "./luasec-0.7alpha-2.rockspec", | ||
425 | luaposix = "./luaposix-34.0.4-1.rockspec", | ||
426 | luasocket = "luasocket", | ||
427 | ["lua-zlib"] = "lua-zlib", | ||
428 | luafilesystem = "luafilesystem", | ||
429 | } | ||
430 | |||
431 | fs.make_dir(LUA_MODULES) | ||
432 | for name, arg in pairs(dependencies) do | ||
433 | local vers = manif.get_versions(queries.from_dep_string(name), "one") | ||
434 | if not next(vers) then | ||
435 | os.execute("LUAROCKS_CONFIG='" .. CONFIG_FILE .. "' ./luarocks install '--tree=" .. LUA_MODULES .. "' " .. arg) | ||
436 | end | ||
437 | end | ||
438 | |||
439 | generate(MAIN_PROGRAM, "src", { EXCLUDE, "^bin/?" }) | ||
440 | end | ||
441 | |||
442 | main() | ||
diff --git a/binary/luaposix-34.0.4-1.rockspec b/binary/luaposix-34.0.4-1.rockspec new file mode 100644 index 00000000..490715d5 --- /dev/null +++ b/binary/luaposix-34.0.4-1.rockspec | |||
@@ -0,0 +1,55 @@ | |||
1 | local _MODREV, _SPECREV = '34.0.4', '-1' | ||
2 | |||
3 | package = 'luaposix' | ||
4 | version = _MODREV .. _SPECREV | ||
5 | |||
6 | description = { | ||
7 | summary = 'Lua bindings for POSIX', | ||
8 | detailed = [[ | ||
9 | A library binding various POSIX APIs. POSIX is the IEEE Portable | ||
10 | Operating System Interface standard. luaposix is based on lposix. | ||
11 | ]], | ||
12 | homepage = 'http://github.com/luaposix/luaposix/', | ||
13 | license = 'MIT/X11', | ||
14 | } | ||
15 | |||
16 | dependencies = { | ||
17 | 'bit32', | ||
18 | 'lua >= 5.1, < 5.4', | ||
19 | 'std.normalize', | ||
20 | } | ||
21 | |||
22 | source = { | ||
23 | url = 'http://github.com/luaposix/luaposix/archive/v' .. _MODREV .. '.zip', | ||
24 | dir = 'luaposix-' .. _MODREV, | ||
25 | } | ||
26 | |||
27 | build = { | ||
28 | type = 'command', | ||
29 | build_command = '$(LUA) build-aux/luke' | ||
30 | .. ' package="' .. package .. '"' | ||
31 | .. ' version="' .. _MODREV .. '"' | ||
32 | .. ' PREFIX="$(PREFIX)"' | ||
33 | .. ' LUA="$(LUA)"' | ||
34 | .. ' LUA_INCDIR="$(LUA_INCDIR)"' | ||
35 | .. ' CFLAGS="$(CFLAGS)"' | ||
36 | .. ' LIBFLAG="$(LIBFLAG)"' | ||
37 | .. ' LIB_EXTENSION="$(LIB_EXTENSION)"' | ||
38 | .. ' OBJ_EXTENSION="$(OBJ_EXTENSION)"' | ||
39 | .. ' INST_LIBDIR="$(LIBDIR)"' | ||
40 | .. ' INST_LUADIR="$(LUADIR)"' | ||
41 | , | ||
42 | install_command = '$(LUA) build-aux/luke install --quiet' | ||
43 | .. ' INST_LIBDIR="$(LIBDIR)"' | ||
44 | .. ' LIB_EXTENSION="$(LIB_EXTENSION)"' | ||
45 | .. ' INST_LUADIR="$(LUADIR)"' | ||
46 | , | ||
47 | } | ||
48 | |||
49 | if _MODREV == 'git' then | ||
50 | dependencies[#dependencies + 1] = 'ldoc' | ||
51 | |||
52 | source = { | ||
53 | url = 'git://github.com/luaposix/luaposix.git', | ||
54 | } | ||
55 | end | ||
diff --git a/binary/luasec-0.7alpha-2.rockspec b/binary/luasec-0.7alpha-2.rockspec new file mode 100644 index 00000000..2736ca15 --- /dev/null +++ b/binary/luasec-0.7alpha-2.rockspec | |||
@@ -0,0 +1,119 @@ | |||
1 | package = "LuaSec" | ||
2 | version = "0.7alpha-2" | ||
3 | source = { | ||
4 | url = "https://github.com/brunoos/luasec/archive/luasec-0.7alpha.tar.gz", | ||
5 | dir = "luasec-luasec-0.7alpha" | ||
6 | } | ||
7 | description = { | ||
8 | summary = "A binding for OpenSSL library to provide TLS/SSL communication over LuaSocket.", | ||
9 | detailed = "This version delegates to LuaSocket the TCP connection establishment between the client and server. Then LuaSec uses this connection to start a secure TLS/SSL session.", | ||
10 | homepage = "https://github.com/brunoos/luasec/wiki", | ||
11 | license = "MIT" | ||
12 | } | ||
13 | dependencies = { | ||
14 | "lua >= 5.1", "luasocket" | ||
15 | } | ||
16 | external_dependencies = { | ||
17 | platforms = { | ||
18 | unix = { | ||
19 | OPENSSL = { | ||
20 | header = "openssl/ssl.h", | ||
21 | library = "ssl" | ||
22 | } | ||
23 | }, | ||
24 | windows = { | ||
25 | OPENSSL = { | ||
26 | header = "openssl/ssl.h", | ||
27 | } | ||
28 | }, | ||
29 | } | ||
30 | } | ||
31 | build = { | ||
32 | type = "builtin", | ||
33 | copy_directories = { | ||
34 | "samples" | ||
35 | }, | ||
36 | platforms = { | ||
37 | unix = { | ||
38 | modules = { | ||
39 | ['ssl.https'] = "src/https.lua", | ||
40 | ['ssl.init'] = "src/ssl.lua", | ||
41 | ssl = { | ||
42 | defines = { | ||
43 | "WITH_LUASOCKET", "LUASOCKET_DEBUG", | ||
44 | }, | ||
45 | incdirs = { | ||
46 | "$(OPENSSL_INCDIR)", "src/", "src/luasocket", | ||
47 | }, | ||
48 | libdirs = { | ||
49 | "$(OPENSSL_LIBDIR)" | ||
50 | }, | ||
51 | libraries = { | ||
52 | "ssl", "crypto" | ||
53 | }, | ||
54 | sources = { | ||
55 | "src/config.c", "src/ec.c", | ||
56 | "src/x509.c", "src/context.c", "src/ssl.c", | ||
57 | "src/luasocket/buffer.c", "src/luasocket/io.c", | ||
58 | "src/luasocket/timeout.c", "src/luasocket/usocket.c" | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | }, | ||
63 | mingw = { | ||
64 | modules = { | ||
65 | ssl = { | ||
66 | libraries = { | ||
67 | "ssl", "crypto", | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | }, | ||
72 | windows = { | ||
73 | modules = { | ||
74 | ['ssl.https'] = "src/https.lua", | ||
75 | ['ssl.init'] = "src/ssl.lua", | ||
76 | ssl = { | ||
77 | defines = { | ||
78 | "WIN32", "NDEBUG", "_WINDOWS", "_USRDLL", "LSEC_EXPORTS", "BUFFER_DEBUG", "LSEC_API=__declspec(dllexport)", | ||
79 | "WITH_LUASOCKET", "LUASOCKET_DEBUG", | ||
80 | "LUASEC_INET_NTOP", "WINVER=0x0501", "_WIN32_WINNT=0x0501", "NTDDI_VERSION=0x05010300" | ||
81 | }, | ||
82 | libdirs = { | ||
83 | "$(OPENSSL_LIBDIR)", | ||
84 | "$(OPENSSL_BINDIR)", | ||
85 | }, | ||
86 | libraries = { | ||
87 | "libssl32MD", "libcrypto32MD", "ws2_32" | ||
88 | }, | ||
89 | incdirs = { | ||
90 | "$(OPENSSL_INCDIR)", "src/", "src/luasocket" | ||
91 | }, | ||
92 | sources = { | ||
93 | "src/config.c", "src/ec.c", | ||
94 | "src/x509.c", "src/context.c", "src/ssl.c", | ||
95 | "src/luasocket/buffer.c", "src/luasocket/io.c", | ||
96 | "src/luasocket/timeout.c", "src/luasocket/wsocket.c" | ||
97 | } | ||
98 | } | ||
99 | }, | ||
100 | patches = { | ||
101 | ["lowercase-winsock-h.diff"] = [[ | ||
102 | diff --git a/src/ssl.c b/src/ssl.c | ||
103 | index 95109c4..e5defa8 100644 | ||
104 | --- a/src/ssl.c | ||
105 | +++ b/src/ssl.c | ||
106 | @@ -11,7 +11,7 @@ | ||
107 | #include <string.h> | ||
108 | |||
109 | #if defined(WIN32) | ||
110 | -#include <Winsock2.h> | ||
111 | +#include <winsock2.h> | ||
112 | #endif | ||
113 | |||
114 | #include <openssl/ssl.h> | ||
115 | ]] | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | } | ||
diff --git a/binary/static-gcc b/binary/static-gcc new file mode 100755 index 00000000..a4d865d5 --- /dev/null +++ b/binary/static-gcc | |||
@@ -0,0 +1,158 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | DIR="$( cd "$( dirname "$0" )" && pwd )" | ||
4 | |||
5 | function log() { echo -- "$@" >> $DIR/log.txt; } | ||
6 | |||
7 | function runlog() { log "$@"; "$@"; } | ||
8 | |||
9 | log "---------------------------" | ||
10 | log INP "$@" | ||
11 | |||
12 | allargs=() | ||
13 | sources=() | ||
14 | objects=() | ||
15 | etc=() | ||
16 | libdirs=("/usr/lib") | ||
17 | incdirs=() | ||
18 | |||
19 | linking=0 | ||
20 | |||
21 | while [ "$1" ] | ||
22 | do | ||
23 | allargs+=("$1") | ||
24 | if [ "$next_libdir" = "1" ] | ||
25 | then | ||
26 | libdirs+=("$1") | ||
27 | next_libdir=0 | ||
28 | elif [ "$next_incdir" = "1" ] | ||
29 | then | ||
30 | incdirs+=("-I$1") | ||
31 | next_incdir=0 | ||
32 | elif [ "$next_lib" = "1" ] | ||
33 | then | ||
34 | libs+=("$1") | ||
35 | next_lib=0 | ||
36 | elif [ "$next_output" = "1" ] | ||
37 | then | ||
38 | output="$1" | ||
39 | next_output=0 | ||
40 | else | ||
41 | case "$1" in | ||
42 | -*) | ||
43 | case "$1" in | ||
44 | -shared) | ||
45 | linking=1 | ||
46 | ;; | ||
47 | -static) | ||
48 | linking=1 | ||
49 | ;; | ||
50 | -o) | ||
51 | next_output=1 | ||
52 | ;; | ||
53 | -c) | ||
54 | object=1 | ||
55 | etc+=("$1") | ||
56 | ;; | ||
57 | -L) | ||
58 | next_libdir=1 | ||
59 | ;; | ||
60 | -L*) | ||
61 | libdirs+=("${1:2}") | ||
62 | ;; | ||
63 | -I) | ||
64 | next_incdir=1 | ||
65 | ;; | ||
66 | -I*) | ||
67 | incdirs+=("$1") | ||
68 | ;; | ||
69 | -l) | ||
70 | next_lib=1 | ||
71 | ;; | ||
72 | -l*) | ||
73 | libs+=("${1:2}") | ||
74 | ;; | ||
75 | *) | ||
76 | etc+=("$1") | ||
77 | ;; | ||
78 | esac | ||
79 | ;; | ||
80 | *.c) | ||
81 | sources+=("$1") | ||
82 | ;; | ||
83 | *.o) | ||
84 | objects+=("$1") | ||
85 | ;; | ||
86 | *) | ||
87 | etc+=("$1") | ||
88 | ;; | ||
89 | esac | ||
90 | fi | ||
91 | shift | ||
92 | done | ||
93 | |||
94 | staticlibs=() | ||
95 | for lib in "${libs[@]}" | ||
96 | do | ||
97 | for libdir in "${libdirs[@]}" | ||
98 | do | ||
99 | staticlib="$libdir/lib$lib.a" | ||
100 | if [ -e "$staticlib" ] | ||
101 | then | ||
102 | staticlibs+=("$staticlib") | ||
103 | break | ||
104 | fi | ||
105 | done | ||
106 | done | ||
107 | |||
108 | oflag=() | ||
109 | if [ "$output" != "" ] | ||
110 | then | ||
111 | oflag=("-o" "$output") | ||
112 | fi | ||
113 | |||
114 | if [ "$linking" = "1" ] | ||
115 | then | ||
116 | log LINK | ||
117 | if [ "${#sources[@]}" -gt 0 ] | ||
118 | then | ||
119 | for source in "${sources[@]}" | ||
120 | do | ||
121 | object="${source%.c}.o" | ||
122 | runlog gcc "${incdirs[@]}" "${etc[@]}" -c -o "$object" "$source" | ||
123 | [ "$?" = 0 ] || runlog exit $? | ||
124 | objects+=("$object") | ||
125 | done | ||
126 | fi | ||
127 | |||
128 | # runlog ar rcu "${oflag[@]}" "${objects[@]}" "${staticlibs[@]}" | ||
129 | echo "CREATE $output" > ar.script | ||
130 | for o in "${objects[@]}" | ||
131 | do | ||
132 | echo "ADDMOD $o" >> ar.script | ||
133 | done | ||
134 | for o in "${staticlibs[@]}" | ||
135 | do | ||
136 | echo "ADDLIB $o" >> ar.script | ||
137 | done | ||
138 | echo "SAVE" >> ar.script | ||
139 | echo "END" >> ar.script | ||
140 | cat ar.script | ar -M | ||
141 | [ "$?" = 0 ] || runlog exit $? | ||
142 | |||
143 | [ -e "$output" ] || { | ||
144 | exit 1 | ||
145 | } | ||
146 | |||
147 | runlog ranlib "$output" | ||
148 | runlog exit $? | ||
149 | elif [ "$object" = 1 ] | ||
150 | then | ||
151 | log OBJECT | ||
152 | runlog gcc "${oflag[@]}" "${incdirs[@]}" "${etc[@]}" "${sources[@]}" | ||
153 | runlog exit $? | ||
154 | else | ||
155 | log EXECUTABLE | ||
156 | runlog gcc "${allargs[@]}" | ||
157 | runlog exit $? | ||
158 | fi | ||