From 98d1f1da856ab59cf8355c1e2e11e3c0eb954fb2 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Sun, 1 Jul 2018 15:21:16 -0300 Subject: 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 --- .gitignore | 2 +- .travis.yml | 3 +- Makefile | 246 ++++++--------- Makefile.install.inc | 23 -- Makefile.luarocks | 16 - Makefile.setup.inc | 27 -- binary/all_in_one | 442 ++++++++++++++++++++++++++ binary/luaposix-34.0.4-1.rockspec | 55 ++++ binary/luasec-0.7alpha-2.rockspec | 119 +++++++ binary/static-gcc | 158 ++++++++++ configure | 633 ++++++++++++++++++-------------------- luarocks-dev-1.rockspec | 36 +++ makedist | 45 +-- rockspec | 38 --- 14 files changed, 1230 insertions(+), 613 deletions(-) delete mode 100644 Makefile.install.inc delete mode 100644 Makefile.luarocks delete mode 100644 Makefile.setup.inc create mode 100755 binary/all_in_one create mode 100644 binary/luaposix-34.0.4-1.rockspec create mode 100644 binary/luasec-0.7alpha-2.rockspec create mode 100755 binary/static-gcc create mode 100644 luarocks-dev-1.rockspec delete mode 100644 rockspec diff --git a/.gitignore b/.gitignore index bee8dfb1..f1481cfc 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ /test/testing_* /test/luacov.* # Stuff that pops up during development but shouldn't be in the repo (helps clean up `git status`) -/*.rockspec +/build-binary /*.rock /*.tar.gz /*.zip diff --git a/.travis.yml b/.travis.yml index dab724b2..64d3347a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,9 @@ unit_script: &unit_script integration_script: &integration_script - lua -v + - if [ "$TRAVIS_OS_NAME" = "linux" ]; then shellcheck ./configure; fi - ./configure --with-lua=lua_install - - ./makedist scm + - ./makedist dev - busted -o gtest --exclude-tags=git,unit --verbose -Xhelper "lua_dir=$PWD/lua_install,travis" - busted -o gtest --exclude-tags=git,unit --verbose -Xhelper "lua_dir=$PWD/lua_install,travis,env=full" diff --git a/Makefile b/Makefile index 80b872eb..4e528db8 100644 --- a/Makefile +++ b/Makefile @@ -1,150 +1,108 @@ -include config.unix +-include config.unix -.PHONY: all build dev build_bins luadoc check_makefile cleanup_bins clean \ - install_site_config write_sysconfig install bootstrap install_rock \ - run_luarocks +all: ./luarocks ./luarocks-admin -ROCKS_TREE ?= $(PREFIX) -SYSCONFDIR ?= $(PREFIX)/etc/luarocks -LUA_DIR ?= /usr/local -LUA_BINDIR ?= $(LUA_DIR)/bin +# ---------------------------------------- +# Base build +# ---------------------------------------- -CONFIG_FILE = $(SYSCONFDIR)/config-$(LUA_VERSION).lua +build: all -SAFEPWD=`echo "$$PWD" | sed -e 's/\([][]\)\1/]]..'\''\1\1'\''..[[/g'` - -all: - @echo "- Type 'make build' and 'make install':" - @echo " to install to $(PREFIX) as usual." - @echo "- Type 'make bootstrap':" - @echo " to install LuaRocks in $(PREFIX) as a rock." - @echo - -include Makefile.setup.inc -include Makefile.install.inc - -build: $(SITE_CONFIG) build_bins - @echo - @echo "Done. Type 'make install' to install into $(PREFIX)." +config.unix: + @echo Please run the "./configure" script before building. @echo - -$(SITE_CONFIG): config.unix - rm -f $(SITE_CONFIG) - echo 'local site_config = {}' >> $(SITE_CONFIG) - if [ -n "$(PREFIX)" ] ;\ - then \ - echo "site_config.LUAROCKS_PREFIX=[[$(PREFIX)]]" >> $(SITE_CONFIG) ;\ - fi - if [ -n "$(LUA_INCDIR)" ] ;\ - then \ - echo "site_config.LUA_INCDIR=[[$(LUA_INCDIR)]]" >> $(SITE_CONFIG) ;\ - fi - if [ -n "$(LUA_LIBDIR)" ] ;\ - then \ - echo "site_config.LUA_LIBDIR=[[$(LUA_LIBDIR)]]" >> $(SITE_CONFIG) ;\ - fi - if [ -n "$(LUA_BINDIR)" ] ;\ - then \ - echo "site_config.LUA_BINDIR=[[$(LUA_BINDIR)]]" >> $(SITE_CONFIG) ;\ - fi - if [ -n "$(LUA_SUFFIX)" ] ;\ - then \ - echo "site_config.LUA_INTERPRETER=[[lua$(LUA_SUFFIX)]]" >> $(SITE_CONFIG) ;\ - fi - if [ -n "$(SYSCONFDIR)" ] ;\ - then \ - echo "site_config.LUAROCKS_SYSCONFDIR=[[$(SYSCONFDIR)]]" >> $(SITE_CONFIG) ;\ - fi - if [ -n "$(ROCKS_TREE)" ] ;\ - then \ - echo "site_config.LUAROCKS_ROCKS_TREE=[[$(ROCKS_TREE)]]" >> $(SITE_CONFIG) ;\ - fi - if [ -n "$(FORCE_CONFIG)" ] ;\ - then \ - echo "site_config.LUAROCKS_FORCE_CONFIG=true" >> $(SITE_CONFIG) ;\ - fi - if [ "$(LUA_DIR_SET)" = "yes" ] ;\ - then \ - echo "site_config.LUA_DIR_SET=true" >> $(SITE_CONFIG) ;\ - fi - echo "site_config.LUAROCKS_UNAME_S=[[$(LUAROCKS_UNAME_S)]]" >> $(SITE_CONFIG) - echo "site_config.LUAROCKS_UNAME_M=[[$(LUAROCKS_UNAME_M)]]" >> $(SITE_CONFIG) - echo "site_config.LUAROCKS_DOWNLOADER=[[$(LUAROCKS_DOWNLOADER)]]" >> $(SITE_CONFIG) - echo "site_config.LUAROCKS_MD5CHECKER=[[$(LUAROCKS_MD5CHECKER)]]" >> $(SITE_CONFIG) - if [ -n "$(MULTIARCH_SUBDIR)" ] ;\ - then \ - echo 'site_config.LUAROCKS_EXTERNAL_DEPS_SUBDIRS={ bin="bin", lib={ "lib", [[$(MULTIARCH_SUBDIR)]] }, include="include" }' >> $(SITE_CONFIG) ;\ - echo 'site_config.LUAROCKS_RUNTIME_EXTERNAL_DEPS_SUBDIRS={ bin="bin", lib={ "lib", [[$(MULTIARCH_SUBDIR)]] }, include="include" }' >> $(SITE_CONFIG) ;\ - fi - echo "return site_config" >> $(SITE_CONFIG) - -dev: - $(MAKE) build_bins LUADIR=$(PWD)/src - -build_bins: cleanup_bins - for f in $(BIN_FILES) ;\ - do \ - sed "1d" src/bin/$$f > src/bin/$$f.bak ;\ - echo "#!$(LUA_BINDIR)/lua$(LUA_SUFFIX)" > src/bin/$$f ;\ - echo "package.path = [[$(LUADIR)/?.lua;]]..package.path" | sed "s,//,/,g" >> src/bin/$$f ;\ - cat src/bin/$$f.bak >> src/bin/$$f ;\ - chmod +rx src/bin/$$f ;\ - rm -f src/bin/$$f.bak ;\ - done - -luadoc: - rm -rf doc/luadoc - mkdir -p doc/luadoc - cd src && luadoc -d ../doc/luadoc --nofiles luarocks/*.lua - -check_makefile: clean - echo $(BIN_FILES) | tr " " "\n" | sort > makefile_list.txt - ( cd src/bin && ls -d * ) | sort > luarocks_dir.txt - echo $(LUAROCKS_FILES) | tr " " "\n" | sort >> makefile_list.txt - ( cd src/luarocks && find * -name "*.lua" ) | sort >> luarocks_dir.txt - diff makefile_list.txt luarocks_dir.txt - rm -f makefile_list.txt luarocks_dir.txt - @echo - @echo "Makefile is sane." - @echo - -cleanup_bins: - for f in $(BIN_FILES) ;\ - do \ - mv src/bin/$$f src/bin/$$f.bak ;\ - sed "s,^#!.*lua.*,#!/usr/bin/env lua,;/^package.path/d" < src/bin/$$f.bak > src/bin/$$f ;\ - chmod +rx src/bin/$$f ;\ - rm -f src/bin/$$f.bak ;\ - done - -clean: cleanup_bins - rm -f $(SITE_CONFIG) - -run_luarocks: - '$(LUA_BINDIR)/lua$(LUA_SUFFIX)' -e "package.path=[[$(SAFEPWD)/src/?.lua;]]..package.path" src/bin/luarocks make rockspec --tree="$(PREFIX)" - -install_site_config: $(SITE_CONFIG) - mkdir -p "$(DESTDIR)$(LUADIR)/luarocks/core" - cp $(SITE_CONFIG) "$(DESTDIR)$(LUADIR)/luarocks/core" - -write_sysconfig: - mkdir -p "$(DESTDIR)$(ROCKS_TREE)" - if [ ! -f "$(DESTDIR)$(CONFIG_FILE)" ] ;\ - then \ - mkdir -p `dirname "$(DESTDIR)$(CONFIG_FILE)"` ;\ - echo 'rocks_trees = {' >> "$(DESTDIR)$(CONFIG_FILE)" ;\ - if [ ! -n "$(FORCE_CONFIG)" ] ;\ - then \ - echo ' { name = [[user]], root = home..[[/.luarocks]] },' >> "$(DESTDIR)$(CONFIG_FILE)" ;\ - fi ;\ - echo ' { name = [[system]], root = [[$(ROCKS_TREE)]] }' >> "$(DESTDIR)$(CONFIG_FILE)" ;\ - echo '}' >> "$(DESTDIR)$(CONFIG_FILE)" ;\ - fi - -install: build install_bins install_luas install_site_config write_sysconfig - -bootstrap: $(SITE_CONFIG) run_luarocks install_site_config write_sysconfig cleanup_bins - -install_rock: install_bins install_luas - + @exit 1 + +config-$(LUA_VERSION).lua.in: config.unix + +./luarocks: config.unix config-$(LUA_VERSION).lua.in + 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" >> luarocks + echo 'LUAROCKS_SYSCONFDIR="$(SYSCONFDIR)" LUA_PATH="$(PWD)/src/?.lua;;" exec "$(LUA_BINDIR)/$(LUA_INTERPRETER)" "src/bin/luarocks" --project-tree="$(PWD)/lua_modules" "$$@"' >> luarocks + chmod +rx ./luarocks + ./luarocks init + cp config-$(LUA_VERSION).lua.in .luarocks/config-$(LUA_VERSION).lua + +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" >> luarocks-admin + echo 'LUAROCKS_SYSCONFDIR="$(SYSCONFDIR)" LUA_PATH="$(PWD)/src/?.lua;;" exec "$(LUA_BINDIR)/$(LUA_INTERPRETER)" "src/bin/luarocks-admin" --project-tree="$(PWD)/lua_modules" "$$@"' >> luarocks-admin + chmod +rx ./luarocks-admin + +# ---------------------------------------- +# Regular install +# ---------------------------------------- + +install: all $(PREFIX)/bin/luarocks $(PREFIX)/bin/luarocks-admin $(SYSCONFDIR)/config-$(LUA_VERSION).lua + mkdir -p "$(PREFIX)/share/lua/$(LUA_VERSION)/luarocks" + cp -a src/luarocks/* "$(PREFIX)/share/lua/$(LUA_VERSION)/luarocks" + +$(PREFIX)/bin/luarocks: src/bin/luarocks config.unix + mkdir -p "$(PREFIX)/bin" + echo "#!$(LUA_BINDIR)/$(LUA_INTERPRETER)" > $@ + echo "package.loaded['luarocks.core.hardcoded'] = { SYSCONFDIR = [[$(SYSCONFDIR)]] }" >> $@ + echo "package.path=[[$(PREFIX)/share/lua/$(LUA_VERSION)/?.lua;]] .. package.path" >> $@ + tail -n +2 src/bin/luarocks >> $@ + chmod +rx $@ + +$(PREFIX)/bin/luarocks-admin: src/bin/luarocks-admin config.unix + mkdir -p "$(PREFIX)/bin" + echo "#!$(LUA_BINDIR)/$(LUA_INTERPRETER)" > $@ + echo "package.loaded['luarocks.core.hardcoded'] = { SYSCONFDIR = [[$(SYSCONFDIR)]] }" >> $@ + echo "package.path=[[$(PREFIX)/share/lua/$(LUA_VERSION)/?.lua;]] .. package.path" >> $@ + tail -n +2 src/bin/luarocks-admin >> $@ + chmod +rx $@ + +$(SYSCONFDIR)/config-$(LUA_VERSION).lua: config-$(LUA_VERSION).lua.in + mkdir -p "$(SYSCONFDIR)" + cp config-$(LUA_VERSION).lua.in "$(SYSCONFDIR)/config-$(LUA_VERSION).lua" + +# ---------------------------------------- +# Binary build +# ---------------------------------------- + +binary: build-binary/luarocks.exe build-binary/luarocks-admin.exe + +build-binary/luarocks.exe: ./luarocks + LUA_PATH="$(PWD)/src/?.lua;;" "$(LUA_BINDIR)/$(LUA_INTERPRETER)" ./all_in_one "src/bin/luarocks" "$(LUA_DIR)" "^src/luarocks/admin/" "$(SYSCONFDIR)" "build-binary" + +build-binary/luarocks-admin.exe: ./luarocks + LUA_PATH="$(PWD)/src/?.lua;;" "$(LUA_BINDIR)/$(LUA_INTERPRETER)" ./all_in_one "src/bin/luarocks-admin" "$(LUA_DIR)" "^src/luarocks/cmd/" "$(SYSCONFDIR)" "build-binary" + +# ---------------------------------------- +# Binary install +# ---------------------------------------- + +install-binary: build-binary/luarocks.exe build-binary/luarocks-admin.exe + mkdir -p "$(PREFIX)/bin" + cp build-binary/luarocks.exe "$(PREFIX)/bin/luarocks" + chmod +rx "$(PREFIX)/bin/luarocks" + cp build-binary/luarocks-admin.exe "$(PREFIX)/bin/luarocks-admin" + chmod +rx "$(PREFIX)/bin/luarocks-admin" + mkdir -p "$(PREFIX)/share/lua/$(LUA_VERSION)/luarocks/core" + cp -a src/luarocks/core/* "$(PREFIX)/share/lua/$(LUA_VERSION)/luarocks/core" + cp -a src/luarocks/loader.lua "$(PREFIX)/share/lua/$(LUA_VERSION)/luarocks/" + +# ---------------------------------------- +# Bootstrap install +# ---------------------------------------- + +bootstrap: ./luarocks $(SYSCONFDIR)/config-$(LUA_VERSION).lua + ./luarocks make --tree="$(ROCKS_TREE)" + +# ---------------------------------------- +# Clean +# ---------------------------------------- + +clean: + rm -f ./config.unix + rm -f ./luarocks + rm -f ./luarocks-admin + rm -rf build-binary + rm -rf ./.luarocks + rm -rf ./lua_modules + +.PHONY: all build install binary install-binary bootstrap clean diff --git a/Makefile.install.inc b/Makefile.install.inc deleted file mode 100644 index 621d7cb2..00000000 --- a/Makefile.install.inc +++ /dev/null @@ -1,23 +0,0 @@ - -.PHONY: install_bins install_luas - -install_bins: - mkdir -p "$(DESTDIR)$(BINDIR)" - cd src/bin && \ - luaver="$(LUA_VERSION)" && [ -n "$$luaver" ] || luaver=`$(LUA) -e 'print(_VERSION:sub(5))'`; \ - for f in $(BIN_FILES); \ - do \ - cp "$$f" "$(DESTDIR)$(BINDIR)/$$f-$$luaver"; \ - chmod +rx "$(DESTDIR)$(BINDIR)/$$f-$$luaver"; \ - ln -nfs "$$f-$$luaver" "$(DESTDIR)$(BINDIR)/$$f"; \ - done - -install_luas: - mkdir -p "$(DESTDIR)$(LUADIR)/luarocks" - cd src/luarocks && for f in $(LUAROCKS_FILES); \ - do \ - d="$(DESTDIR)$(LUADIR)/luarocks"/`dirname "$$f"` && \ - mkdir -p "$$d" && \ - cp "$$f" "$$d" || exit 1; \ - done - diff --git a/Makefile.luarocks b/Makefile.luarocks deleted file mode 100644 index f0652891..00000000 --- a/Makefile.luarocks +++ /dev/null @@ -1,16 +0,0 @@ - -include Makefile.setup.inc -include Makefile.install.inc - -.PHONY: all install copy_site_config - -all: - @echo This Makefile is used by the LuaRocks rockspec for upgrading itself. - -install: install_bins install_luas copy_site_config - -copy_site_config: - luaver="$(LUA_VERSION)" && [ -n "$$luaver" ] || luaver=`$(LUA) -e 'print(_VERSION:sub(5))'`; \ - mkdir -p "$(DESTDIR)$(LUADIR)/luarocks"; \ - site_config="site_config_$(echo "$luaver" | sed 's,\.,_,').lua" - lprefix=$(echo "$(LUADIR)" | sed 's,/lib/luarocks/.*,,'); sed "s,LUAROCKS_PREFIX=.*,LUAROCKS_PREFIX=[[$$lprefix]],g" "$(LUAROCKS_PREFIX)/share/lua/$$luaver/luarocks/core/$$site_config" > "$(DESTDIR)$(LUADIR)/luarocks/core/$$site_config" diff --git a/Makefile.setup.inc b/Makefile.setup.inc deleted file mode 100644 index f53686d0..00000000 --- a/Makefile.setup.inc +++ /dev/null @@ -1,27 +0,0 @@ - -DESTDIR = -PREFIX ?= /usr/local -BINDIR ?= $(PREFIX)/bin -LUADIR ?= $(PREFIX)/share/lua/$(LUA_VERSION) - -BIN_FILES = luarocks luarocks-admin -LUAROCKS_FILES = fs.lua dir.lua repos.lua cmd.lua upload/api.lua upload/multipart.lua \ -admin/index.lua build.lua search.lua fs/win32.lua fs/win32/tools.lua fs/win32/pe-parser.lua \ -fs/unix/tools.lua fs/lua.lua fs/tools.lua fs/unix.lua loader.lua cmd/help.lua \ -cmd/unpack.lua cmd/upload.lua cmd/lint.lua cmd/purge.lua cmd/install.lua \ -cmd/config.lua cmd/write_rockspec.lua cmd/build.lua cmd/search.lua cmd/test.lua \ -cmd/make.lua cmd/list.lua cmd/show.lua cmd/path.lua cmd/new_version.lua \ -cmd/pack.lua cmd/download.lua cmd/doc.lua cmd/remove.lua tools/patch.lua \ -tools/zip.lua tools/tar.lua manif/writer.lua build/cmake.lua build/make.lua \ -build/command.lua build/builtin.lua fetch.lua path.lua util.lua deps.lua \ -pack.lua download.lua core/dir.lua core/path.lua core/util.lua \ -core/cfg.lua core/persist.lua core/manif.lua \ -type_check.lua persist.lua require.lua manif.lua admin/cache.lua \ -admin/cmd/make_manifest.lua admin/cmd/add.lua admin/cmd/remove.lua \ -admin/cmd/refresh_cache.lua remove.lua fetch/git_file.lua fetch/sscm.lua \ -fetch/cvs.lua fetch/git_https.lua fetch/git_ssh.lua fetch/hg_http.lua \ -fetch/git_http.lua fetch/svn.lua fetch/git.lua fetch/hg_ssh.lua \ -fetch/hg_https.lua fetch/hg.lua core/vers.lua cmd/which.lua \ -fun.lua type/manifest.lua type/rockspec.lua queries.lua results.lua \ -test/busted.lua test/command.lua cmd/init.lua rockspecs.lua - 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 @@ +#!/usr/bin/env lua +--[[ + +All-in-one packager for LuaRocks + * by Hisham Muhammad + * licensed under the same terms as Lua (MIT license). + +Based on: + +* srlua.c - Lua interpreter for self-running programs + * by Luiz Henrique de Figueiredo + * 03 Nov 2014 15:31:43 + * srlua.c is placed in the public domain. +* bin2c.lua - converts a binary to a C string that can be embedded + * by Mark Edgar + * http://lua-users.org/wiki/BinTwoCee + * bin2c.lua is licensed under the same terms as Lua (MIT license). +* lua.c - Lua stand-alone interpreter + * by Luiz Henrique de Figueiredo, Waldemar Celes, Roberto Ierusalimschy + * lua.c is licensed under the same terms as Lua (MIT license). +* luastatic - builds a standalone executable from a Lua program + * by Eric R. Schulz + * https://github.com/ers35/luastatic + * luastatic is licensed under the CC0 1.0 Universal license + +]] + +local MAIN_PROGRAM = arg[1] or "src/bin/luarocks" +local LUA_DIR = arg[2] or "/usr" +local EXCLUDE = arg[3] or "^src/luarocks/admin/" +local SYSCONFDIR = arg[4] or "/etc/luarocks" +local TARGET = arg[5] or "binary-build" + +local LUA_MODULES = TARGET .. "/lua_modules" +local CONFIG_DIR = TARGET .. "/.luarocks" + +package.path = "./src/?.lua;" .. package.path + +local fs = require("luarocks.fs") +local cfg = require("luarocks.core.cfg") +local cmd = require("luarocks.cmd") +local deps = require("luarocks.deps") +local util = require("luarocks.util") +local path = require("luarocks.path") +local manif = require("luarocks.manif") +local queries = require("luarocks.queries") +local persist = require("luarocks.persist") + +-------------------------------------------------------------------------------- + +local function reindent_c(input) + local out = {} + local indent = 0 + local previous_is_blank = true + for line in input:gmatch("([^\n]*)") do + line = line:match("^[ \t]*(.-)[ \t]*$") + + local is_blank = (#line == 0) + local do_print = + (not is_blank) or + (not previous_is_blank and indent == 0) + + if line:match("^[})]") then + indent = indent - 1 + if indent < 0 then indent = 0 end + end + if do_print then + table.insert(out, string.rep(" ", indent)) + table.insert(out, line) + table.insert(out, "\n") + end + if line:match("[{(]$") then + indent = indent + 1 + end + + previous_is_blank = is_blank + end + return table.concat(out) +end + +local hexdump +do + local numtab = {} + for i = 0, 255 do + numtab[string.char(i)] = ("%-3d,"):format(i) + end + function hexdump(str) + return (str:gsub(".", numtab):gsub(("."):rep(80), "%0\n")) + end +end + +local c_preamble = [[ + +#include +#include +#include +#include +#include +#include + +/* portable alerts, from srlua */ +#ifdef _WIN32 +#include +#define alert(message) MessageBox(NULL, message, progname, MB_ICONERROR | MB_OK) +#define getprogname() char name[MAX_PATH]; argv[0]= GetModuleFileName(NULL,name,sizeof(name)) ? name : NULL; +#else +#define alert(message) fprintf(stderr,"%s: %s\n", progname, message) +#define getprogname() +#endif + +static int registry_key; + +]] + +local function bin2c_file(out, filename) + local content = string.dump(assert(loadfile(filename))) + table.insert(out, ("static const unsigned char code[] = {")) + table.insert(out, hexdump(content)) + table.insert(out, ("};")) +end + +local function write_hardcoded_module(dir) + + local system = util.popen_read("uname -s") + local processor = util.popen_read("uname -m") + + if processor:match("i[%d]86") then + processor = "x86" + elseif processor:match("amd64") or processor:match("x86_64") then + processor = "x86_64" + elseif processor:match("Power Macintosh") then + processor = "powerpc" + end + + local hardcoded = { + SYSTEM = system, + PROCESSOR = processor, + SYSCONFDIR = SYSCONFDIR, + LUA_DIR = cfg.variables.LUA_DIR, + LUA_BINDIR = cfg.variables.LUA_BINDIR, + LUA_INTERPRETER = cfg.lua_interpreter, + } + + local name = dir .. "/luarocks/core/hardcoded.lua" + persist.save_as_module(name, hardcoded) + return name +end + +local function declare_modules(out, dirs, skip) + skip = skip or {} + table.insert(out, [[ + static void declare_modules(lua_State* L) { + lua_settop(L, 0); /* */ + lua_newtable(L); /* modules */ + lua_pushlightuserdata(L, (void*) ®istry_key); /* modules registry_key */ + lua_pushvalue(L, 1); /* modules registry_key modules */ + lua_rawset(L, LUA_REGISTRYINDEX); /* modules */ + ]]) + for _, dir in ipairs(dirs) do + for _, name in ipairs(fs.find(dir)) do + local run = true + for _, pat in ipairs(skip) do + if name:match(pat) then + run = false + break + end + end + if run then + local filename = dir .. "/" .. name + if fs.is_file(filename) then + print(name) + local modname = name:gsub("%.lua$", ""):gsub("/", ".") + table.insert(out, ("/* %s */"):format(modname)) + table.insert(out, ("{")) + bin2c_file(out, filename) + table.insert(out, ("luaL_loadbuffer(L, code, sizeof(code), %q);"):format(filename)) + table.insert(out, ("lua_setfield(L, 1, %q);"):format(modname)) + table.insert(out, ("}")) + end + end + end + end + table.insert(out, [[ + lua_settop(L, 0); /* */ + } + ]]) +end + +local function nm(filename) + local pd = io.popen("nm " .. filename) + local out = pd:read("*a") + pd:close() + return out +end + +local function declare_libraries(out, dir) + local a_files = {} + local externs = {} + local fn = {} + table.insert(fn, [[ + static void declare_libraries(lua_State* L) { + lua_getglobal(L, "package"); /* package */ + lua_getfield(L, -1, "preload"); /* package package.preload */ + ]]) + for _, name in ipairs(fs.find(dir)) do + local filename = dir .. "/" .. name + if name:match("%.a$") then + table.insert(a_files, filename) + local nmout = nm(filename) + for luaopen in nmout:gmatch("[^dD] _?(luaopen_[%a%p%d]+)") do + + -- FIXME what about module names with underscores? + local modname = luaopen:gsub("^_?luaopen_", ""):gsub("_", ".") + + table.insert(externs, "extern int " .. luaopen .. "(lua_State* L);") + table.insert(fn, "lua_pushcfunction(L, " .. luaopen .. ");") + table.insert(fn, "lua_setfield(L, -2, \"" .. modname .. "\");") + end + end + end + local pd = io.popen("find " .. dir .. " -name '*.a'", "r") + for line in pd:lines() do + table.insert(a_files, line) + end + pd:close() + table.insert(fn, [[ + lua_settop(L, 0); /* */ + } + ]]) + + table.insert(out, "\n") + for _, line in ipairs(externs) do + table.insert(out, line) + end + table.insert(out, "\n") + for _, line in ipairs(fn) do + table.insert(out, line) + end + table.insert(out, "\n") + + return a_files +end + +local function load_main(out, main_program, program_name) + table.insert(out, [[static void load_main(lua_State* L) {]]) + bin2c_file(out, main_program) + table.insert(out, ("luaL_loadbuffer(L, code, sizeof(code), %q);"):format(program_name)) + table.insert(out, [[}]]) + table.insert(out, [[]]) +end + +local c_main = [[ + +/* custom package loader */ +static int pkg_loader(lua_State* L) { + lua_pushlightuserdata(L, (void*) ®istry_key); /* modname ? registry_key */ + lua_rawget(L, LUA_REGISTRYINDEX); /* modname ? modules */ + lua_pushvalue(L, -1); /* modname ? modules modules */ + lua_pushvalue(L, 1); /* modname ? modules modules modname */ + lua_gettable(L, -2); /* modname ? modules mod */ + if (lua_type(L, -1) == LUA_TNIL) { + lua_pop(L, 1); /* modname ? modules */ + lua_pushvalue(L, 1); /* modname ? modules modname */ + lua_pushliteral(L, ".init"); /* modname ? modules modname ".init" */ + lua_concat(L, 2); /* modname ? modules modname .. ".init" */ + lua_gettable(L, -2); /* modname ? mod */ + } + return 1; +} + +static void install_pkg_loader(lua_State* L) { + lua_settop(L, 0); /* */ + lua_getglobal(L, "table"); /* table */ + lua_getfield(L, -1, "insert"); /* table table.insert */ + lua_getglobal(L, "package"); /* table table.insert package */ + lua_getfield(L, -1, "searchers"); /* table table.insert package package.searchers */ + if (lua_type(L, -1) == LUA_TNIL) { + lua_pop(L, 1); + lua_getfield(L, -1, "loaders"); /* table table.insert package package.loaders */ + } + lua_copy(L, 4, 3); /* table table.insert package.searchers */ + lua_settop(L, 3); /* table table.insert package.searchers */ + lua_pushnumber(L, 1); /* table table.insert package.searchers 1 */ + lua_pushcfunction(L, pkg_loader); /* table table.insert package.searchers 1 pkg_loader */ + lua_call(L, 3, 0); /* table */ + lua_settop(L, 0); /* */ +} + +/* main script launcher, from srlua */ +static int pmain(lua_State *L) { + int argc = lua_tointeger(L, 1); + char** argv = lua_touserdata(L, 2); + int i; + load_main(L); + lua_createtable(L, argc, 0); + for (i = 0; i < argc; i++) { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i); + } + lua_setglobal(L, "arg"); + luaL_checkstack(L, argc - 1, "too many arguments to script"); + for (i = 1; i < argc; i++) { + lua_pushstring(L, argv[i]); + } + lua_call(L, argc - 1, 0); + return 0; +} + +/* fatal error, from srlua */ +static void fatal(const char* message) { + alert(message); + exit(EXIT_FAILURE); +} + +/* error handler, from luac */ +static int msghandler (lua_State *L) { + /* is error object not a string? */ + const char *msg = lua_tostring(L, 1); + if (msg == NULL) { + /* does it have a metamethod that produces a string */ + if (luaL_callmeta(L, 1, "__tostring") && lua_type(L, -1) == LUA_TSTRING) { + /* then that is the message */ + return 1; + } else { + msg = lua_pushfstring(L, "(error object is a %s value)", luaL_typename(L, 1)); + } + } + /* append a standard traceback */ + luaL_traceback(L, L, msg, 1); + return 1; +} + +/* main function, from srlua */ +int main(int argc, char** argv) { + lua_State* L; + getprogname(); + if (argv[0] == NULL) { + fatal("cannot locate this executable"); + } + L = luaL_newstate(); + if (L == NULL) { + fatal("not enough memory for state"); + } + luaL_openlibs(L); + install_pkg_loader(L); + declare_libraries(L); + declare_modules(L); + lua_pushcfunction(L, &msghandler); + lua_pushcfunction(L, &pmain); + lua_pushinteger(L, argc); + lua_pushlightuserdata(L, argv); + if (lua_pcall(L, 2, 0, -4) != 0) { + fatal(lua_tostring(L, -1)); + } + lua_close(L); + return EXIT_SUCCESS; +} + +]] + +local function generate(main_program, dir, skip) + local program_name = main_program:gsub(".*/", "") + + local hardcoded = write_hardcoded_module(dir) + + local out = {} + table.insert(out, c_preamble) + table.insert(out, ([[static const char* progname = %q;]]):format(program_name)) + load_main(out, main_program, program_name) + local lua_modules = LUA_MODULES .. "/share/lua/" .. cfg.lua_version + declare_modules(out, { dir, lua_modules }, skip) + local a_files = declare_libraries(out, LUA_MODULES .. "/lib/lua/" .. cfg.lua_version) + table.insert(out, c_main) + + os.remove(hardcoded) + + local c_filename = TARGET .. "/" .. program_name .. ".exe.c" + local fd = io.open(c_filename, "w") + fd:write(reindent_c(table.concat(out, "\n"))) + fd:close() + + cmd = table.concat({ + "gcc", "-o", TARGET .. "/" .. program_name .. ".exe", + "-I", cfg.variables.LUA_INCDIR, + "-rdynamic", + "-Os", + c_filename, + "-L", cfg.variables.LUA_LIBDIR, + table.concat(a_files, " "), + cfg.variables.LUA_LIBDIR .. "/" .. cfg.variables.LUALIB:gsub("%.so.*$", ".a"), + "-ldl", "-lm"}, " ") + print(cmd) + os.execute(cmd) +end + +-------------------------------------------------------------------------------- + +local function main() + + cfg.init(cmd.find_lua(LUA_DIR)) + fs.init() + deps.check_lua(cfg.variables) + path.use_tree("./" .. LUA_MODULES) + + local CONFIG_FILE = CONFIG_DIR .. "/config-" .. cfg.lua_version .. ".lua" + + fs.make_dir(CONFIG_DIR) + local fd = io.open(CONFIG_FILE, "w") + fd:write([[ + lib_extension = "a" + external_lib_extension = "a" + variables = { + CC = "]] .. fs.current_dir() .. [[/static-gcc", + LD = "]] .. fs.current_dir() .. [[/static-gcc", + LIB_EXTENSION = "a", + LIBFLAG = "-static", + } + ]]) + fd:close() + + local dependencies = { + md5 = "md5", + luazip = "luazip", + luasec = "./luasec-0.7alpha-2.rockspec", + luaposix = "./luaposix-34.0.4-1.rockspec", + luasocket = "luasocket", + ["lua-zlib"] = "lua-zlib", + luafilesystem = "luafilesystem", + } + + fs.make_dir(LUA_MODULES) + for name, arg in pairs(dependencies) do + local vers = manif.get_versions(queries.from_dep_string(name), "one") + if not next(vers) then + os.execute("LUAROCKS_CONFIG='" .. CONFIG_FILE .. "' ./luarocks install '--tree=" .. LUA_MODULES .. "' " .. arg) + end + end + + generate(MAIN_PROGRAM, "src", { EXCLUDE, "^bin/?" }) +end + +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 @@ +local _MODREV, _SPECREV = '34.0.4', '-1' + +package = 'luaposix' +version = _MODREV .. _SPECREV + +description = { + summary = 'Lua bindings for POSIX', + detailed = [[ + A library binding various POSIX APIs. POSIX is the IEEE Portable + Operating System Interface standard. luaposix is based on lposix. + ]], + homepage = 'http://github.com/luaposix/luaposix/', + license = 'MIT/X11', +} + +dependencies = { + 'bit32', + 'lua >= 5.1, < 5.4', + 'std.normalize', +} + +source = { + url = 'http://github.com/luaposix/luaposix/archive/v' .. _MODREV .. '.zip', + dir = 'luaposix-' .. _MODREV, +} + +build = { + type = 'command', + build_command = '$(LUA) build-aux/luke' + .. ' package="' .. package .. '"' + .. ' version="' .. _MODREV .. '"' + .. ' PREFIX="$(PREFIX)"' + .. ' LUA="$(LUA)"' + .. ' LUA_INCDIR="$(LUA_INCDIR)"' + .. ' CFLAGS="$(CFLAGS)"' + .. ' LIBFLAG="$(LIBFLAG)"' + .. ' LIB_EXTENSION="$(LIB_EXTENSION)"' + .. ' OBJ_EXTENSION="$(OBJ_EXTENSION)"' + .. ' INST_LIBDIR="$(LIBDIR)"' + .. ' INST_LUADIR="$(LUADIR)"' + , + install_command = '$(LUA) build-aux/luke install --quiet' + .. ' INST_LIBDIR="$(LIBDIR)"' + .. ' LIB_EXTENSION="$(LIB_EXTENSION)"' + .. ' INST_LUADIR="$(LUADIR)"' + , +} + +if _MODREV == 'git' then + dependencies[#dependencies + 1] = 'ldoc' + + source = { + url = 'git://github.com/luaposix/luaposix.git', + } +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 @@ +package = "LuaSec" +version = "0.7alpha-2" +source = { + url = "https://github.com/brunoos/luasec/archive/luasec-0.7alpha.tar.gz", + dir = "luasec-luasec-0.7alpha" +} +description = { + summary = "A binding for OpenSSL library to provide TLS/SSL communication over LuaSocket.", + 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.", + homepage = "https://github.com/brunoos/luasec/wiki", + license = "MIT" +} +dependencies = { + "lua >= 5.1", "luasocket" +} +external_dependencies = { + platforms = { + unix = { + OPENSSL = { + header = "openssl/ssl.h", + library = "ssl" + } + }, + windows = { + OPENSSL = { + header = "openssl/ssl.h", + } + }, + } +} +build = { + type = "builtin", + copy_directories = { + "samples" + }, + platforms = { + unix = { + modules = { + ['ssl.https'] = "src/https.lua", + ['ssl.init'] = "src/ssl.lua", + ssl = { + defines = { + "WITH_LUASOCKET", "LUASOCKET_DEBUG", + }, + incdirs = { + "$(OPENSSL_INCDIR)", "src/", "src/luasocket", + }, + libdirs = { + "$(OPENSSL_LIBDIR)" + }, + libraries = { + "ssl", "crypto" + }, + sources = { + "src/config.c", "src/ec.c", + "src/x509.c", "src/context.c", "src/ssl.c", + "src/luasocket/buffer.c", "src/luasocket/io.c", + "src/luasocket/timeout.c", "src/luasocket/usocket.c" + } + } + } + }, + mingw = { + modules = { + ssl = { + libraries = { + "ssl", "crypto", + } + } + } + }, + windows = { + modules = { + ['ssl.https'] = "src/https.lua", + ['ssl.init'] = "src/ssl.lua", + ssl = { + defines = { + "WIN32", "NDEBUG", "_WINDOWS", "_USRDLL", "LSEC_EXPORTS", "BUFFER_DEBUG", "LSEC_API=__declspec(dllexport)", + "WITH_LUASOCKET", "LUASOCKET_DEBUG", + "LUASEC_INET_NTOP", "WINVER=0x0501", "_WIN32_WINNT=0x0501", "NTDDI_VERSION=0x05010300" + }, + libdirs = { + "$(OPENSSL_LIBDIR)", + "$(OPENSSL_BINDIR)", + }, + libraries = { + "libssl32MD", "libcrypto32MD", "ws2_32" + }, + incdirs = { + "$(OPENSSL_INCDIR)", "src/", "src/luasocket" + }, + sources = { + "src/config.c", "src/ec.c", + "src/x509.c", "src/context.c", "src/ssl.c", + "src/luasocket/buffer.c", "src/luasocket/io.c", + "src/luasocket/timeout.c", "src/luasocket/wsocket.c" + } + } + }, + patches = { +["lowercase-winsock-h.diff"] = [[ +diff --git a/src/ssl.c b/src/ssl.c +index 95109c4..e5defa8 100644 +--- a/src/ssl.c ++++ b/src/ssl.c +@@ -11,7 +11,7 @@ + #include + + #if defined(WIN32) +-#include ++#include + #endif + + #include +]] + } + } + } +} 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 @@ +#!/usr/bin/env bash + +DIR="$( cd "$( dirname "$0" )" && pwd )" + +function log() { echo -- "$@" >> $DIR/log.txt; } + +function runlog() { log "$@"; "$@"; } + +log "---------------------------" +log INP "$@" + +allargs=() +sources=() +objects=() +etc=() +libdirs=("/usr/lib") +incdirs=() + +linking=0 + +while [ "$1" ] +do + allargs+=("$1") + if [ "$next_libdir" = "1" ] + then + libdirs+=("$1") + next_libdir=0 + elif [ "$next_incdir" = "1" ] + then + incdirs+=("-I$1") + next_incdir=0 + elif [ "$next_lib" = "1" ] + then + libs+=("$1") + next_lib=0 + elif [ "$next_output" = "1" ] + then + output="$1" + next_output=0 + else + case "$1" in + -*) + case "$1" in + -shared) + linking=1 + ;; + -static) + linking=1 + ;; + -o) + next_output=1 + ;; + -c) + object=1 + etc+=("$1") + ;; + -L) + next_libdir=1 + ;; + -L*) + libdirs+=("${1:2}") + ;; + -I) + next_incdir=1 + ;; + -I*) + incdirs+=("$1") + ;; + -l) + next_lib=1 + ;; + -l*) + libs+=("${1:2}") + ;; + *) + etc+=("$1") + ;; + esac + ;; + *.c) + sources+=("$1") + ;; + *.o) + objects+=("$1") + ;; + *) + etc+=("$1") + ;; + esac + fi + shift +done + +staticlibs=() +for lib in "${libs[@]}" +do + for libdir in "${libdirs[@]}" + do + staticlib="$libdir/lib$lib.a" + if [ -e "$staticlib" ] + then + staticlibs+=("$staticlib") + break + fi + done +done + +oflag=() +if [ "$output" != "" ] +then + oflag=("-o" "$output") +fi + +if [ "$linking" = "1" ] +then + log LINK + if [ "${#sources[@]}" -gt 0 ] + then + for source in "${sources[@]}" + do + object="${source%.c}.o" + runlog gcc "${incdirs[@]}" "${etc[@]}" -c -o "$object" "$source" + [ "$?" = 0 ] || runlog exit $? + objects+=("$object") + done + fi + + # runlog ar rcu "${oflag[@]}" "${objects[@]}" "${staticlibs[@]}" + echo "CREATE $output" > ar.script + for o in "${objects[@]}" + do + echo "ADDMOD $o" >> ar.script + done + for o in "${staticlibs[@]}" + do + echo "ADDLIB $o" >> ar.script + done + echo "SAVE" >> ar.script + echo "END" >> ar.script + cat ar.script | ar -M + [ "$?" = 0 ] || runlog exit $? + + [ -e "$output" ] || { + exit 1 + } + + runlog ranlib "$output" + runlog exit $? +elif [ "$object" = 1 ] +then + log OBJECT + runlog gcc "${oflag[@]}" "${incdirs[@]}" "${etc[@]}" "${sources[@]}" + runlog exit $? +else + log EXECUTABLE + runlog gcc "${allargs[@]}" + runlog exit $? +fi diff --git a/configure b/configure index 7bc5bced..209f0c44 100755 --- a/configure +++ b/configure @@ -1,74 +1,44 @@ #!/bin/sh -# A basic configure script for LuaRocks. -# Not doing any fancy shell stuff here to keep good compatibility. - # Defaults PREFIX="/usr/local" SYSCONFDIR="$PREFIX/etc/luarocks" ROCKS_TREE="$PREFIX" -LUA_SUFFIX="" -LUA_DIR="/usr" -LUA_BINDIR="/usr/bin" -LUA_INCDIR="/usr/include" -LUA_LIBDIR="/usr/lib" -LUA_VERSION="5.1" -MULTIARCH_SUBDIR="" # ---------------------------------------------------------------------------- # FUNCTION DEFINITIONS # ---------------------------------------------------------------------------- -# Help +# Utility functions +# ----------------- -show_help() { -cat </dev/null 2>&1 + then + echo "$PWD" + else + echo "$1" + fi + else + if cd "$(dirname "$1")" >/dev/null 2>&1 + then + echo "$PWD/$(basename "$1")" + else + echo "$1" + fi + fi + cd "$oldpwd" >/dev/null 2>&1 || return } -# Helper functions - find_program() { - prog=`command -v "$1" 2>/dev/null` + prog=$(command -v "$1" 2>/dev/null) if [ -n "$prog" ] then dirname "$prog" @@ -78,37 +48,154 @@ find_program() { die() { echo "$*" echo - echo "configure failed." + RED "configure failed." + echo echo exit 1 } -find_helper() { - explanation="$1" - shift - tried="$*" - while [ -n "$1" ] - do - found=`find_program "$1"` - if [ -n "$found" ] +echo_n() { + printf "%s" "$*" +} + +bold='\033[1m' +red='\033[1;31m' +green='\033[1;32m' +blue='\033[1;36m' +reset='\033[0m' + +BOLD() { + printf "$bold%s$reset" "$*" +} + +RED() { + printf "$red%s$reset" "$*" +} + +GREEN() { + printf "$green%s$reset" "$*" +} + +BLUE() { + printf "$blue%s$reset" "$*" +} + +# Help +# ---- + +show_help() { +cat < /dev/null) + if [ "$detected_lua" != "nil" ] + then + if [ "$LUA_VERSION_SET" != "yes" ] then - echo "$1 found at $found" - HELPER=$1 - return + echo "Lua version detected: $(GREEN "$detected_lua")" + LUA_VERSION=$detected_lua + return 0 + elif [ "$LUA_VERSION" = "$detected_lua" ] + then + return 0 fi - shift - done - echo "Could not find $explanation. Tried: $tried." - die "Make sure one of them is installed and available in your PATH." + fi + return 1 } -case `echo -n x` in --n*) echo_n_flag='';; -*) echo_n_flag='-n';; -esac - -echo_n() { - echo $echo_n_flag "$*" +search_interpreter() { + suffix="$1" + lua_at="" + if [ "$LUA_BINDIR_SET" = "yes" ] + then + lua_at="$LUA_BINDIR" + elif [ "$LUA_DIR_SET" = "yes" ] + then + LUA_BINDIR="$LUA_DIR/bin" + if [ -f "$LUA_BINDIR/lua$suffix" ] + then + lua_at="$LUA_BINDIR" + fi + else + lua_at=$(find_program "lua$suffix") + fi + if [ -n "$lua_at" ] && [ -x "$lua_at/lua$suffix" ] + then + if detect_lua_version "$lua_at/lua$suffix" + then + echo "Lua interpreter found: $(GREEN "$lua_at/lua$suffix")" + if [ "$LUA_BINDIR_SET" != "yes" ] + then + LUA_BINDIR="$lua_at" + fi + if [ "$LUA_DIR_SET" != "yes" ] + then + LUA_DIR=$(dirname "$lua_at") + fi + LUA_INTERPRETER="lua$suffix" + return 0 + fi + fi + return 1 } # ---------------------------------------------------------------------------- @@ -119,89 +206,97 @@ echo_n() { while [ -n "$1" ] do - value="`echo $1 | sed 's/[^=]*.\(.*\)/\1/'`" - key="`echo $1 | sed 's/=.*//'`" - if `echo "$value" | grep "~" >/dev/null 2>/dev/null` + value="$(echo "$1" | sed 's/[^=]*.\(.*\)/\1/')" + key="$(echo "$1" | sed 's/=.*//')" + if echo "$value" | grep "~" >/dev/null 2>/dev/null then echo - echo '*WARNING*: the "~" sign is not expanded in flags.' - echo 'If you mean the home directory, use $HOME instead.' + echo "$(RED WARNING:) the '~' sign is not expanded in flags." + echo "If you mean the home directory, use \$HOME instead." echo fi case "$key" in + + # Help + # ---- --help) show_help exit 0 ;; + + # Where to install LuaRocks: + # -------------------------- --prefix) [ -n "$value" ] || die "Missing value in flag $key." - PREFIX="$value" + PREFIX="$(canonicalpath "$value")" PREFIX_SET=yes ;; --sysconfdir) [ -n "$value" ] || die "Missing value in flag $key." - SYSCONFDIR="$value" + SYSCONFDIR="$(canonicalpath "$value")" SYSCONFDIR_SET=yes ;; + + + # Where to install files provided by rocks: + # ----------------------------------------- --rocks-tree) [ -n "$value" ] || die "Missing value in flag $key." - ROCKS_TREE="$value" + ROCKS_TREE="$(canonicalpath "$value")" ROCKS_TREE_SET=yes ;; - --force-config) - FORCE_CONFIG=yes - ;; - --versioned-rocks-dir) - echo "--versioned-rocks-dir is no longer necessary." - echo "The rocks tree in LuaRocks 3.0 is always versioned." - ;; - --lua-suffix) - [ -n "$value" ] || die "Missing value in flag $key." - LUA_SUFFIX="$value" - LUA_SUFFIX_SET=yes - ;; + + # Where is your Lua interpreter: + # ------------------------------ --lua-version|--with-lua-version) [ -n "$value" ] || die "Missing value in flag $key." LUA_VERSION="$value" - [ "$LUA_VERSION" = "5.1" -o "$LUA_VERSION" = "5.2" -o "$LUA_VERSION" = "5.3" -o "$LUA_VERSION" = "5.4" ] || die "Invalid Lua version in flag $key." + case "$LUA_VERSION" in + 5.1|5.2|5.3|5.4) ;; + *) die "Invalid Lua version in flag $key." + esac LUA_VERSION_SET=yes ;; --with-lua) [ -n "$value" ] || die "Missing value in flag $key." - LUA_DIR="$value" + LUA_DIR="$(canonicalpath "$value")" + [ -d "$LUA_DIR" ] || die "Bad value for --with-lua: $LUA_DIR is not a valid directory." LUA_DIR_SET=yes ;; --with-lua-bin) [ -n "$value" ] || die "Missing value in flag $key." - LUA_BINDIR="$value" + LUA_BINDIR="$(canonicalpath "$value")" + [ -d "$LUA_BINDIR" ] || die "Bad value for --with-lua-bin: $LUA_BINDIR is not a valid directory." LUA_BINDIR_SET=yes ;; --with-lua-include) [ -n "$value" ] || die "Missing value in flag $key." - LUA_INCDIR="$value" - LUA_INCDIR_SET=yes + LUA_INCDIR="$(canonicalpath "$value")" + [ -d "$LUA_INCDIR" ] || die "Bad value for --with-lua-include: $LUA_INCDIR is not a valid directory." ;; --with-lua-lib) [ -n "$value" ] || die "Missing value in flag $key." - LUA_LIBDIR="$value" - LUA_LIBDIR_SET=yes + LUA_LIBDIR="$(canonicalpath "$value")" + [ -d "$LUA_LIBDIR" ] || die "Bad value for --with-lua-lib: $LUA_LIBDIR is not a valid directory." ;; - --with-downloader) - [ -n "$value" ] || die "Missing value in flag $key." - case "$value" in - wget|curl) LUAROCKS_DOWNLOADER="$value" ;; - *) die "Invalid option: $value. See --help." ;; - esac - LUAROCKS_DOWNLOADER_SET=yes + + # For specialized uses of LuaRocks: + # --------------------------------- + --force-config) + FORCE_CONFIG=yes ;; - --with-md5-checker) - [ -n "$value" ] || die "Missing value in flag $key." - case "$value" in - md5sum|openssl|md5) LUAROCKS_MD5CHECKER="$value" ;; - *) die "Invalid option: $value. See --help." ;; - esac - LUAROCKS_MD5CHECKER_SET=yes + + # Old options that no longer apply + # -------------------------------- + --versioned-rocks-dir) + echo "--versioned-rocks-dir is no longer necessary." + echo "The rocks tree in LuaRocks 3.0 is always versioned." ;; + --lua-suffix) + echo "--lua-suffix is no longer necessary." + echo "The suffix is automatically detected." + ;; + *) die "Error: Unknown flag: $1" ;; @@ -209,7 +304,16 @@ do shift done -if [ "$PREFIX_SET" = "yes" -a ! "$SYSCONFDIR_SET" = "yes" ] +echo +BLUE "Configuring LuaRocks..." +echo +echo + +# ---------------------------------------- +# Derive options from the ones given +# ---------------------------------------- + +if [ "$PREFIX_SET" = "yes" ] && [ ! "$SYSCONFDIR_SET" = "yes" ] then if [ "$PREFIX" = "/usr" ] then SYSCONFDIR=/etc/luarocks @@ -217,260 +321,129 @@ then fi fi - -if [ "$PREFIX_SET" = "yes" -a ! "$ROCKS_TREE_SET" = "yes" ] +if [ "$PREFIX_SET" = "yes" ] && [ ! "$ROCKS_TREE_SET" = "yes" ] then ROCKS_TREE=$PREFIX fi -detect_lua_version() { - detected_lua=`$1 -e 'print(_VERSION:match(" (5%.[1234])$"))' 2> /dev/null` - if [ "$detected_lua" != "nil" ] - then - if [ "$LUA_VERSION_SET" != "yes" ] - then - echo "Lua version detected: $detected_lua" - LUA_VERSION=$detected_lua - return 0 - elif [ "$LUA_VERSION" = "$detected_lua" ] - then - return 0 - fi - fi - return 1 -} - -search_interpreter() { - suffix="$1" - if [ "$LUA_BINDIR_SET" = "yes" ] - then - find_lua="$LUA_BINDIR" - elif [ "$LUA_DIR_SET" = "yes" ] - then - LUA_BINDIR="$LUA_DIR/bin" - if [ -f "$LUA_BINDIR/lua$suffix" ] - then - find_lua="$LUA_BINDIR" - fi - else - find_lua=`find_program lua$suffix` - fi - if [ -n "$find_lua" -a -x "$find_lua/lua$suffix" ] - then - if detect_lua_version "$find_lua/lua$suffix" - then - echo "Lua interpreter found: $find_lua/lua$suffix..." - if [ "$LUA_BINDIR_SET" != "yes" ] - then - LUA_BINDIR="$find_lua" - fi - if [ "$LUA_DIR_SET" != "yes" ] - then - LUA_DIR=`dirname "$find_lua"` - fi - LUA_SUFFIX="$suffix" - return 0 - fi - fi - return 1 -} +# ---------------------------------------- +# Search for Lua +# ---------------------------------------- lua_interp_found=no -if [ "$LUA_SUFFIX_SET" != "yes" ] -then - if [ "$LUA_VERSION_SET" = "yes" -a "$LUA_VERSION" = "5.1" ] - then - suffixes="5.1 51 -5.1 -51" - elif [ "$LUA_VERSION_SET" = "yes" -a "$LUA_VERSION" = "5.2" ] - then - suffixes="5.2 52 -5.2 -52" - elif [ "$LUA_VERSION_SET" = "yes" -a "$LUA_VERSION" = "5.3" ] - then - suffixes="5.4 54 -5.4 -54" - elif [ "$LUA_VERSION_SET" = "yes" -a "$LUA_VERSION" = "5.4" ] - then - suffixes="5.3 53 -5.3 -53" - else - suffixes="5.4 54 -5.4 -54 5.3 53 -5.3 -53 5.2 52 -5.2 -52 5.1 51 -5.1 -51" - fi - for suffix in `echo $suffixes` "" - do - search_interpreter "$suffix" && { - lua_interp_found=yes - break - } - done -else - search_interpreter "$LUA_SUFFIX" && { + +case "$LUA_VERSION" in +5.1) + suffixes="5.1 51 -5.1 -51 jit" + ;; +5.2) + suffixes="5.2 52 -5.2 -52" + ;; +5.3) + suffixes="5.3 53 -5.3 -53" + ;; +5.4) + suffixes="5.4 54 -5.4 -54" + ;; +*) + suffixes="5.4 54 -5.4 -54 5.3 53 -5.3 -53 5.2 52 -5.2 -52 5.1 51 -5.1 -51 jit" + ;; +esac + +for suffix in $suffixes "" +do + search_interpreter "$suffix" && { lua_interp_found=yes + break } -fi +done if [ "$lua_interp_found" != "yes" ] then - [ "$LUA_VERSION_SET" ] && { interp="Lua $LUA_VERSION" ;} || { interp="Lua" ;} - [ "$LUA_DIR_SET" -o "$LUA_BINDIR_SET" ] && { where="$LUA_BINDIR" ;} || { where="\$PATH" ;} - echo "$interp interpreter not found in $where" - die "You may want to use the flags --with-lua, --with-lua-bin and/or --lua-suffix. See --help." -fi - -if [ "$LUA_VERSION_SET" = "yes" ] -then - echo_n "Checking if $LUA_BINDIR/lua$LUA_SUFFIX is Lua version $LUA_VERSION... " - if detect_lua_version "$LUA_BINDIR/lua$LUA_SUFFIX" + if [ "$LUA_VERSION_SET" ] then - echo "yes" + interp="Lua $LUA_VERSION" else - echo "no" - die "You may want to use the flags --with-lua, --with-lua-bin and/or --lua-suffix. See --help." + interp="Lua" fi -fi - -if [ "$LUA_INCDIR_SET" != "yes" ] -then - LUA_INCDIR="$LUA_DIR/include" -fi - -if [ "$LUA_LIBDIR_SET" != "yes" ] -then - LUA_LIBDIR="$LUA_DIR/lib" -fi - -echo_n "Checking Lua includes... " -lua_h="$LUA_INCDIR/lua.h" -if [ -f "$lua_h" ] -then - echo "lua.h found in $lua_h" -else - v_dir="$LUA_INCDIR/lua/$LUA_VERSION" - lua_h="$v_dir/lua.h" - if [ -f "$lua_h" ] + if [ "$LUA_DIR_SET" ] || [ "$LUA_BINDIR_SET" ] then - echo "lua.h found in $lua_h" - LUA_INCDIR="$v_dir" + where="$LUA_BINDIR" else - d_dir="$LUA_INCDIR/lua$LUA_VERSION" - lua_h="$d_dir/lua.h" - if [ -f "$lua_h" ] - then - echo "lua.h found in $lua_h (Debian/Ubuntu)" - LUA_INCDIR="$d_dir" - else - echo "lua.h not found (looked in $LUA_INCDIR, $v_dir, $d_dir)" - die "You may want to use the flag --with-lua or --with-lua-include. See --help." - fi + where="\$PATH" fi + echo "$(RED $interp interpreter not found) in $where" + echo "You may want to use the flags $(BOLD --with-lua), $(BOLD --with-lua-bin) and/or $(BOLD --lua-version)" + die "Run $(BOLD ./configure --help) for details." fi -echo_n "Checking if Lua header version matches that of the interpreter... " -header_version=$(sed -n 's/.*LUA_VERSION_NUM.*5.\(.\).*/5.\1/p' "$lua_h") -if [ "$header_version" = "$LUA_VERSION" ] -then - echo "yes" -else - echo "no" - echo "lua.h version mismatch (interpreter: $LUA_VERSION; lua.h: $header_version)." - die "You may want to use the flag --with-lua or --with-lua-include. See --help." -fi - - -if [ "$LUAROCKS_DOWNLOADER_SET" != "yes" ] -then - find_helper "a downloader helper program" curl wget fetch - LUAROCKS_DOWNLOADER=$HELPER -fi - -if [ "$LUAROCKS_MD5CHECKER_SET" != "yes" ] -then - find_helper "a MD5 checksum calculator" md5sum openssl md5 - LUAROCKS_MD5CHECKER=$HELPER -fi - -find_helper "an 'unzip' program" unzip - -echo_n "Configuring for system... " -if uname -s -then - LUAROCKS_UNAME_S=`uname -s` -else - die "Could not determine operating system. 'uname -s' failed." -fi -echo_n "Configuring for architecture... " -if uname -m -then - LUAROCKS_UNAME_M=`uname -m` -else - die "Could not determine processor architecture. 'uname -m' failed." -fi - -for v in 5.1 5.2 5.3 5.4; do - if [ "$v" != "$LUA_VERSION" ]; then - if [ -e "$PREFIX/share/lua/$v/luarocks/site_config.lua" ]; then - LUA_OTHER_VERSION="$v" - break - fi - fi -done - -if [ "$LUAROCKS_UNAME_S" = Linux ] +if [ "$LUA_VERSION_SET" = "yes" ] then - GCC_ARCH=`gcc -print-multiarch 2>/dev/null` - if [ -n "$GCC_ARCH" -a -d "/usr/lib/$GCC_ARCH" ] - then - MULTIARCH_SUBDIR="lib/$GCC_ARCH" - elif [ -d "/usr/lib64" ] + echo_n "Checking if $LUA_BINDIR/$LUA_INTERPRETER is Lua version $LUA_VERSION... " + if detect_lua_version "$LUA_BINDIR/$LUA_INTERPRETER" then - # Useful for Fedora systems - MULTIARCH_SUBDIR="lib64" + echo "yes" + else + echo "no" + die "You may want to use the flags --with-lua, --with-lua-bin and/or --lua-version. See --help." fi fi -if [ -f config.unix ]; then - rm -f config.unix +unzip_found=$(find_program "unzip") +if [ -n "$unzip_found" ] +then + echo "unzip found in PATH: $(GREEN "$unzip_found")" +else + RED "Could not find 'unzip'." + die "Make sure it is installed and available in your PATH." fi -SITE_CONFIG=src/luarocks/core/site_config_$(echo "$LUA_VERSION" | sed 's,\.,_,').lua - # Write config -echo "Writing configuration..." -echo +make clean > /dev/null 2> /dev/null rm -f built cat < config.unix # This file was automatically generated by the configure script. # Run "./configure --help" for details. -LUA_VERSION=$LUA_VERSION -SITE_CONFIG=$SITE_CONFIG PREFIX=$PREFIX SYSCONFDIR=$SYSCONFDIR ROCKS_TREE=$ROCKS_TREE -LUA_SUFFIX=$LUA_SUFFIX +LUA_VERSION=$LUA_VERSION +LUA_INTERPRETER=$LUA_INTERPRETER LUA_DIR=$LUA_DIR -LUA_DIR_SET=$LUA_DIR_SET +LUA_BINDIR=$LUA_BINDIR LUA_INCDIR=$LUA_INCDIR LUA_LIBDIR=$LUA_LIBDIR -LUA_BINDIR=$LUA_BINDIR FORCE_CONFIG=$FORCE_CONFIG -LUAROCKS_UNAME_M=$LUAROCKS_UNAME_M -LUAROCKS_UNAME_S=$LUAROCKS_UNAME_S -LUAROCKS_DOWNLOADER=$LUAROCKS_DOWNLOADER -LUAROCKS_MD5CHECKER=$LUAROCKS_MD5CHECKER -MULTIARCH_SUBDIR=$MULTIARCH_SUBDIR - EOF -echo "Installation prefix: $PREFIX" -echo "LuaRocks configuration directory: $SYSCONFDIR" -echo "Using Lua from: $LUA_DIR" - -make clean > /dev/null 2> /dev/null +{ + echo '-- LuaRocks configuration' + echo + echo 'rocks_trees = {' + echo ' { name = "user", root = home .. "/.luarocks" },' + echo ' { name = "system", root = "'"$ROCKS_TREE"'" },' + echo '}' + if [ -n "$LUA_INTERPRETER" ]; then echo 'lua_interpreter = "'"$LUA_INTERPRETER"'"' ; fi + if [ -n "$LUA_DIR" ]; then echo 'variables.LUA_DIR = "'"$LUA_DIR"'"' ; fi + if [ -n "$LUA_INCDIR" ]; then echo 'variables.LUA_INCDIR = "'"$LUA_INCDIR"'"' ; fi + if [ -n "$LUA_BINDIR" ]; then echo 'variables.LUA_BINDIR = "'"$LUA_BINDIR"'"' ; fi + if [ -n "$LUA_LIBDIR" ]; then echo 'variables.LUA_LIBDIR = "'"$LUA_LIBDIR"'"' ; fi +} > "config-$LUA_VERSION.lua.in" echo -echo "Done configuring." -echo "- Type 'make build' and 'make install':" +BLUE "Done configuring." +echo +echo +echo "LuaRocks will be installed at......: $(GREEN "$PREFIX")" +echo "LuaRocks will install rocks at.....: $(GREEN "$ROCKS_TREE")" +echo "LuaRocks configuration directory...: $(GREEN "$SYSCONFDIR")" +echo "Using Lua from.....................: $(GREEN "$LUA_DIR")" +echo +echo "* Type $(BOLD make build) and $(BOLD make install):" echo " to install to $PREFIX as usual." -echo "- Type 'make bootstrap':" -echo " to install LuaRocks in $PREFIX as a rock." +echo "* Type $(BOLD make bootstrap):" +echo " to install LuaRocks into $ROCKS_TREE as a rock." echo diff --git a/luarocks-dev-1.rockspec b/luarocks-dev-1.rockspec new file mode 100644 index 00000000..bc19e3ff --- /dev/null +++ b/luarocks-dev-1.rockspec @@ -0,0 +1,36 @@ +rockspec_format = "3.0" +package = "luarocks" +version = "dev-1" +source = { + url = "git+https://github.com/luarocks/luarocks" +} +description = { + summary = "A package manager for Lua modules.", + detailed = [[ + LuaRocks allows you to install Lua modules as self-contained + packages called "rocks", which also contain version dependency + information. This information is used both during installation, + so that when one rock is requested all rocks it depends on are + installed as well, and at run time, so that when a module is + required, the correct version is loaded. LuaRocks supports both + local and remote repositories, and multiple local rocks trees. + ]], + homepage = "http://www.luarocks.org", + issues_url = "https://github.com/luarocks/luarocks/issues", + maintainer = "Hisham Muhammad", + license = "MIT", +} +test_dependencies = { + "luacov", +} +test = { + type = "busted", + platforms = { + windows = { + flags = { "--exclude-tags=ssh,git,unix" } + }, + unix = { + flags = { "--exclude-tags=ssh,git" } + } + } +} diff --git a/makedist b/makedist index 02ba9e03..08feb4c1 100755 --- a/makedist +++ b/makedist @@ -8,16 +8,23 @@ fi if ! [ -d ".git" ] then - echo "Should be run inside a git repo dir." + echo "Should be run from the LuaRocks git repo dir." exit 1 fi make clean || exit 1 -if [ "$1" != "scm" ] +if [ "$1" != "dev" ] then -grep -q "\"$1\"" rockspec || { +ROCKSPEC="luarocks-$1-1.rockspec" + +[ -e "$ROCKSPEC" ] || { + echo + echo "$ROCKSPEC is missing. Please check rockspec version is correct." +} + +grep -q "\"$1-1\"" "$ROCKSPEC" || { echo echo "version in rockspec is incorrect. Please fix it." exit 1 @@ -61,7 +68,7 @@ fi out="luarocks-$1" rm -rf "$out" mkdir "$out" -rm -f "missing_ref" + git ls-files | while read i do if [ -f "$i" ] @@ -69,36 +76,8 @@ do dir=`dirname $i` mkdir -p "$out/$dir" cp "$i" "$out/$dir" - if echo "$i" | grep -v "/bin/" | grep -q "^src/" - then - grep -qw `basename "$i"` Makefile.setup.inc || { - echo "Missing ref in Makefile.setup.inc: $i" - touch "missing_ref" - exit 1 - } - fi - fi -done -if [ -e "missing_ref" ] -then - rm -f "missing_ref" - exit 1 -fi - -cat Makefile.setup.inc | tr ' \\' '\n\n' | grep 'lua$' | while read i -do - if [ ! -e src/luarocks/$i ] - then - echo "Ref in Makefile.setup.inc for file that no longer exists: $i" - touch "outdated_ref" - exit 1 fi done -if [ -e "outdated_ref" ] -then - rm -f "outdated_ref" - exit 1 -fi rm -rf "release-unix" "release-windows" "$out.tar.gz" "$out-win32.zip" @@ -115,7 +94,7 @@ cd .. rm -rf "release-unix" cd "release-windows/$out-win32" -rm -rf makedist Makefile* configure .travis.yml .gitignore test appveyor* .appveyor +rm -rf makedist Makefile configure .travis.yml .gitignore test appveyor* .appveyor cd .. zip -r ../"$out-win32.zip" "$out-win32" cd .. diff --git a/rockspec b/rockspec deleted file mode 100644 index bb7645f9..00000000 --- a/rockspec +++ /dev/null @@ -1,38 +0,0 @@ -package = "LuaRocks" -local VER = "scm" -version = VER .. "-1" - -source = { - url = "--this rockspec is used by `make bootstrap` only--", -} - -description = { - summary = "A deployment and management system for Lua modules.", - detailed = [[ - LuaRocks allows you to install Lua modules as self-contained - packages called "rocks", which also contain version dependency - information. This information is used both during installation, - so that when one rock is requested all rocks it depends on are - installed as well, and at run time, so that when a module is - required, the correct version is loaded. LuaRocks supports both - local and remote repositories, and multiple local rocks trees. - ]], - license = "MIT/X11", - homepage = "http://www.luarocks.org", - maintainer = "Hisham Muhammad" -} - -dependencies = { - "lua >= 5.1" -} - -build = { - type = "make", - install_target = "install_rock", - build_pass=false, - install_variables = { - BINDIR="$(BINDIR)", - LUADIR="$(LUADIR)", - LUA="$(LUA)", - } -} -- cgit v1.2.3-55-g6feb