From 736fa98402202f74160e0bd7cfe7745e34b307ab Mon Sep 17 00:00:00 2001 From: Fabio Mascarenhas Date: Fri, 12 Apr 2013 17:05:40 -0300 Subject: compile rclauncher binary wrapper on windows on every build --- Makefile | 2 +- lfw/luarocks_config.lua | 2 +- makedist | 2 +- src/luarocks/build/builtin.lua | 12 ++- src/luarocks/cfg.lua | 18 ++--- win32/bin/rclauncher.c | 174 ++++++++++++++++++++--------------------- 6 files changed, 108 insertions(+), 102 deletions(-) diff --git a/Makefile b/Makefile index 79bd64f7..dc37529b 100644 --- a/Makefile +++ b/Makefile @@ -97,7 +97,7 @@ luadoc: check_makefile: clean echo $(BIN_FILES) | tr " " "\n" | sort > makefile_list.txt - ( cd src/bin && ls -d * ) | grep -v "rclauncher.c" | sort > luarocks_dir.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 diff --git a/lfw/luarocks_config.lua b/lfw/luarocks_config.lua index 9fd0aebd..557890f4 100644 --- a/lfw/luarocks_config.lua +++ b/lfw/luarocks_config.lua @@ -7,4 +7,4 @@ rocks_trees = { bin_dir = LFW_ROOT, lua_dir = LFW_ROOT..[[\lua]], lib_dir = LFW_ROOT..[[\clibs]] } } -variables.WRAPPER = LFW_ROOT..[[\rclauncher.obj]] +variables.WRAPPER = LFW_ROOT..[[\rclauncher.c]] diff --git a/makedist b/makedist index ac77696c..77db33db 100755 --- a/makedist +++ b/makedist @@ -61,7 +61,7 @@ mkdir "release-windows" mv "$out" "release-windows/$out-win32" cd "release-unix/$out" -rm -rf makedist install.bat COPYING.lua COPYING.7z win32 lfw src/bin/rclauncher.c +rm -rf makedist install.bat COPYING.lua COPYING.7z win32 lfw cd .. tar czvpf ../"$out.tar.gz" "$out" cd .. diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua index 96ce35a6..f9cc0302 100644 --- a/src/luarocks/build/builtin.lua +++ b/src/luarocks/build/builtin.lua @@ -88,8 +88,10 @@ function run(rockspec) make_rc(fullname, fullbasename..".rc") local ok = execute(variables.RC, "-o", resname, rcname) if not ok then return ok end - ok = execute(variables.LD, "-o", wrapname, resname, variables.WRAPPER, - dir.path(variables.LUA_LIBDIR, variables.LUALIB), "-l" .. (variables.MSVCRT or "m"), "-luser32") + ok = execute(variables.CC.." "..variables.CFLAGS, "-I"..variables.LUA_INCDIR, + "-o", wrapname, resname, variables.WRAPPER, + dir.path(variables.LUA_LIBDIR, variables.LUALIB), + "-l" .. (variables.MSVCRT or "m"), "-luser32") return ok, wrapname end elseif cfg.is_platform("win32") then @@ -119,13 +121,17 @@ function run(rockspec) compile_wrapper_binary = function(fullname, name) local fullbasename = fullname:gsub("%.lua$", ""):gsub("/", "\\") local basename = name:gsub("%.lua$", ""):gsub("/", "\\") + local object = basename..".obj" local rcname = basename..".rc" local resname = basename..".res" local wrapname = basename..".exe" make_rc(fullname, fullbasename..".rc") local ok = execute(variables.RC, "-r", "-fo"..resname, rcname) if not ok then return ok end - ok = execute(variables.LD, "-out:"..wrapname, resname, variables.WRAPPER, + ok = execute(variables.CC.." "..variables.CFLAGS, "-c", "-Fo"..object, + "-I"..variables.LUA_INCDIR, variables.WRAPPER) + if not ok then return ok end + ok = execute(variables.LD, "-out:"..wrapname, resname, object, dir.path(variables.LUA_LIBDIR, variables.LUALIB), "user32.lib") local manifestfile = wrapname..".manifest" if ok and fs.exists(manifestfile) then diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua index e16079f4..12a477a0 100644 --- a/src/luarocks/cfg.lua +++ b/src/luarocks/cfg.lua @@ -193,18 +193,18 @@ local defaults = { MAKE = "make", CC = "cc", LD = "ld", - + CVS = "cvs", GIT = "git", SSCM = "sscm", SVN = "svn", HG = "hg", - + RSYNC = "rsync", WGET = "wget", SCP = "scp", CURL = "curl", - + PWD = "pwd", MKDIR = "mkdir", RMDIR = "rmdir", @@ -221,18 +221,18 @@ local defaults = { GUNZIP = "gunzip", BUNZIP2 = "bunzip2", TAR = "tar", - + MD5SUM = "md5sum", OPENSSL = "openssl", MD5 = "md5", STAT = "stat", - + CMAKE = "cmake", SEVENZ = "7z", - + STATFLAG = "-c '%a'", }, - + external_deps_subdirs = { bin = "bin", lib = "lib", @@ -262,7 +262,7 @@ if detected.windows then defaults.variables.MAKE = "nmake" defaults.variables.CC = "cl" defaults.variables.RC = "rc" - defaults.variables.WRAPPER = site_config.LUAROCKS_PREFIX .. "\\2.0\\rclauncher.obj" + defaults.variables.WRAPPER = site_config.LUAROCKS_PREFIX .. "\\2.0\\rclauncher.c" defaults.variables.LD = "link" defaults.variables.MT = "mt" defaults.variables.LUALIB = "lua"..lua_version..".lib" @@ -293,7 +293,7 @@ if detected.mingw32 then defaults.variables.MAKE = "mingw32-make" defaults.variables.CC = "mingw32-gcc" defaults.variables.RC = "windres" - defaults.variables.WRAPPER = site_config.LUAROCKS_PREFIX .. "\\2.0\\rclauncher.o" + defaults.variables.WRAPPER = site_config.LUAROCKS_PREFIX .. "\\2.0\\rclauncher.c" defaults.variables.LD = "mingw32-gcc" defaults.variables.CFLAGS = "-O2" defaults.variables.LIBFLAG = "-shared" diff --git a/win32/bin/rclauncher.c b/win32/bin/rclauncher.c index 60284638..77459f46 100644 --- a/win32/bin/rclauncher.c +++ b/win32/bin/rclauncher.c @@ -24,55 +24,55 @@ ** Assumes that the error message is on top of the stack. */ static int report (lua_State *L) { - fprintf (stderr, "lua: fatal error: `%s'\n", lua_tostring (L, -1)); - fflush (stderr); - printf ("Content-type: text/plain\n\nConfiguration fatal error: see error log!\n"); - printf ("%s", lua_tostring(L, -1)); - return 1; + fprintf (stderr, "lua: fatal error: `%s'\n", lua_tostring (L, -1)); + fflush (stderr); + printf ("Content-type: text/plain\n\nConfiguration fatal error: see error log!\n"); + printf ("%s", lua_tostring(L, -1)); + return 1; } static int runlua (lua_State *L, const char *lua_string, int argc, char *argv[]) { - int err_func; - int err; + int err_func; + int err; - lua_getglobal(L, "debug"); + lua_getglobal(L, "debug"); lua_pushliteral(L, "traceback"); lua_gettable(L, -2); - err_func = lua_gettop (L); - err = luaL_loadstring (L, lua_string); - if(!err) { - // fill global arg table - lua_getglobal(L, "arg"); - int i; - for(i = 1; i < argc; i++) - { - lua_pushstring(L, argv[i]); - lua_rawseti(L, -2, i); - } - lua_pop(L, 1); - // fill parameters (in vararg '...') - for(i = 1; i < argc; i++) - lua_pushstring(L, argv[i]); - return lua_pcall (L, argc - 1, LUA_MULTRET, err_func); - } else return err; + err_func = lua_gettop (L); + err = luaL_loadstring (L, lua_string); + if(!err) { + int i; + // fill global arg table + lua_getglobal(L, "arg"); + for(i = 1; i < argc; i++) + { + lua_pushstring(L, argv[i]); + lua_rawseti(L, -2, i); + } + lua_pop(L, 1); + // fill parameters (in vararg '...') + for(i = 1; i < argc; i++) + lua_pushstring(L, argv[i]); + return lua_pcall (L, argc - 1, LUA_MULTRET, err_func); + } else return err; } static DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize ) // -// Return the size of the path in bytes. +// Return the size of the path in bytes. { - DWORD dwLength = GetModuleFileName( hInst, pszBuffer, dwSize ); - if( dwLength ) - { - while( dwLength && pszBuffer[ dwLength ] != '.' ) - { - dwLength--; - } + DWORD dwLength = GetModuleFileName( hInst, pszBuffer, dwSize ); + if( dwLength ) + { + while( dwLength && pszBuffer[ dwLength ] != '.' ) + { + dwLength--; + } - if( dwLength ) - pszBuffer[ dwLength ] = '\000'; - } - return dwLength; + if( dwLength ) + pszBuffer[ dwLength ] = '\000'; + } + return dwLength; } @@ -80,60 +80,60 @@ static DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize ) ** MAIN */ int main (int argc, char *argv[]) { - char name[ MAX_PATH ]; - DWORD dwLength; - int size; - luaL_Buffer b; - int i; + char name[ MAX_PATH ]; + DWORD dwLength; + int size; + luaL_Buffer b; + int i; #ifdef UNICODE - TCHAR lua_wstring[4098]; + TCHAR lua_wstring[4098]; #endif - char lua_string[4098]; - lua_State *L = luaL_newstate(); - (void)argc; /* avoid "unused parameter" warning */ - luaL_openlibs(L); - lua_newtable(L); // create arg table - lua_pushstring(L, argv[0]); // add interpreter to arg table - lua_rawseti(L, -2, -1); - dwLength = GetModulePath( NULL, name, MAX_PATH ); - if(dwLength) { /* Optional bootstrap */ - strcat(name, ".lua"); - lua_pushstring(L, name); // add lua script to arg table - lua_rawseti(L, -2, 0); - lua_setglobal(L,"arg"); // set global arg table - if(!luaL_loadfile (L, name)) { - if(lua_pcall (L, 0, LUA_MULTRET, 0)) { - report (L); - lua_close (L); - return EXIT_FAILURE; - } - } - } - else - { - lua_pushstring(L, argv[0]); // no lua script, so add interpreter again, now as lua script - lua_rawseti(L, -2, 0); - lua_setglobal(L,"arg"); // set global arg table - } + char lua_string[4098]; + lua_State *L = luaL_newstate(); + (void)argc; /* avoid "unused parameter" warning */ + luaL_openlibs(L); + lua_newtable(L); // create arg table + lua_pushstring(L, argv[0]); // add interpreter to arg table + lua_rawseti(L, -2, -1); + dwLength = GetModulePath( NULL, name, MAX_PATH ); + if(dwLength) { /* Optional bootstrap */ + strcat(name, ".lua"); + lua_pushstring(L, name); // add lua script to arg table + lua_rawseti(L, -2, 0); + lua_setglobal(L,"arg"); // set global arg table + if(!luaL_loadfile (L, name)) { + if(lua_pcall (L, 0, LUA_MULTRET, 0)) { + report (L); + lua_close (L); + return EXIT_FAILURE; + } + } + } + else + { + lua_pushstring(L, argv[0]); // no lua script, so add interpreter again, now as lua script + lua_rawseti(L, -2, 0); + lua_setglobal(L,"arg"); // set global arg table + } - luaL_buffinit(L, &b); - for(i = 1; ; i++) { + luaL_buffinit(L, &b); + for(i = 1; ; i++) { #ifdef UNICODE - size = LoadString(GetModuleHandle(NULL), i, lua_wstring, - sizeof(lua_string)/sizeof(TCHAR)); - if(size > 0) wcstombs(lua_string, lua_wstring, size + 1); + size = LoadString(GetModuleHandle(NULL), i, lua_wstring, + sizeof(lua_string)/sizeof(TCHAR)); + if(size > 0) wcstombs(lua_string, lua_wstring, size + 1); #else - size = LoadString(GetModuleHandle(NULL), i, lua_string, - sizeof(lua_string)/sizeof(char)); + size = LoadString(GetModuleHandle(NULL), i, lua_string, + sizeof(lua_string)/sizeof(char)); #endif - if(size) luaL_addlstring(&b, lua_string, size); else break; - } - luaL_pushresult(&b); - if (runlua (L, lua_tostring(L, -1), argc, argv)) { - report (L); - lua_close (L); - return EXIT_FAILURE; - } - lua_close (L); - return EXIT_SUCCESS; + if(size) luaL_addlstring(&b, lua_string, size); else break; + } + luaL_pushresult(&b); + if (runlua (L, lua_tostring(L, -1), argc, argv)) { + report (L); + lua_close (L); + return EXIT_FAILURE; + } + lua_close (L); + return EXIT_SUCCESS; } -- cgit v1.2.3-55-g6feb