aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Mascarenhas <mascarenhas@lambda-2.local>2010-01-21 15:12:31 -0200
committerFabio Mascarenhas <mascarenhas@lambda-2.local>2010-01-21 15:12:31 -0200
commit47fea74335776d0d05de6225fcb3a8baa33e7f01 (patch)
treecd4d7896bc6b87ae8e6148007a753e86dc430b9b
parent208f150e363188b617123d4d0e1406ced5d93ba3 (diff)
downloadluarocks-47fea74335776d0d05de6225fcb3a8baa33e7f01.tar.gz
luarocks-47fea74335776d0d05de6225fcb3a8baa33e7f01.tar.bz2
luarocks-47fea74335776d0d05de6225fcb3a8baa33e7f01.zip
mingw32 build target
-rw-r--r--install.bat21
-rw-r--r--src/bin/rclauncher.c118
-rw-r--r--src/luarocks/build/builtin.lua32
-rw-r--r--src/luarocks/cfg.lua37
4 files changed, 201 insertions, 7 deletions
diff --git a/install.bat b/install.bat
index f957e7a9..5644fa2a 100644
--- a/install.bat
+++ b/install.bat
@@ -43,12 +43,14 @@ IF [%1]==[/?] (
43 ECHO /LIB [dir] Location of Lua libraries -e.g. c:\lua\5.1\lib 43 ECHO /LIB [dir] Location of Lua libraries -e.g. c:\lua\5.1\lib
44 ECHO /BIN [dir] Location of Lua executables - e.g. c:\lua\5.1\bin 44 ECHO /BIN [dir] Location of Lua executables - e.g. c:\lua\5.1\bin
45 ECHO. 45 ECHO.
46 ECHO /FORCECONFIG Use a single config location. Do not use the 46 ECHO /MW Use mingw as build system instead of MSVC
47 ECHO LUAROCKS_CONFIG variable or the user's home directory.
48 ECHO Useful to avoid conflicts when LuaRocks
49 ECHO is embedded within an application.
50 ECHO. 47 ECHO.
51 ECHO /F Remove installation directory if it already exists. 48 ECHO /FORCECONFIG Use a single config location. Do not use the
49 ECHO LUAROCKS_CONFIG variable or the user's home directory.
50 ECHO Useful to avoid conflicts when LuaRocks
51 ECHO is embedded within an application.
52 ECHO.
53 ECHO /F Remove installation directory if it already exists.
52 ECHO. 54 ECHO.
53 GOTO QUIT 55 GOTO QUIT
54) 56)
@@ -81,6 +83,11 @@ IF /I [%1]==[/L] (
81 SHIFT /1 83 SHIFT /1
82 GOTO PARSE_LOOP 84 GOTO PARSE_LOOP
83) 85)
86IF /I [%1]==[/MW] (
87 SET USE_MINGW=ON
88 SHIFT /1
89 GOTO PARSE_LOOP
90)
84IF /I [%1]==[/LUA] ( 91IF /I [%1]==[/LUA] (
85 SET LUA_PREFIX=%2 92 SET LUA_PREFIX=%2
86 SHIFT /1 93 SHIFT /1
@@ -262,7 +269,11 @@ ECHO LUA_INCDIR=[[%LUA_INCDIR%]]>> "%LUADIR%\luarocks\config.lua"
262ECHO LUA_LIBDIR=[[%LUA_LIBDIR%]]>> "%LUADIR%\luarocks\config.lua" 269ECHO LUA_LIBDIR=[[%LUA_LIBDIR%]]>> "%LUADIR%\luarocks\config.lua"
263ECHO LUA_BINDIR=[[%LUA_BINDIR%]]>> "%LUADIR%\luarocks\config.lua" 270ECHO LUA_BINDIR=[[%LUA_BINDIR%]]>> "%LUADIR%\luarocks\config.lua"
264ECHO LUA_INTERPRETER=[[%LUA_INTERPRETER%]]>> "%LUADIR%\luarocks\config.lua" 271ECHO LUA_INTERPRETER=[[%LUA_INTERPRETER%]]>> "%LUADIR%\luarocks\config.lua"
272IF [%USE_MINGW%]==[ON] (
273ECHO LUAROCKS_UNAME_S=[[MINGW]]>> "%LUADIR%\luarocks\config.lua"
274) ELSE (
265ECHO LUAROCKS_UNAME_S=[[WindowsNT]]>> "%LUADIR%\luarocks\config.lua" 275ECHO LUAROCKS_UNAME_S=[[WindowsNT]]>> "%LUADIR%\luarocks\config.lua"
276)
266ECHO LUAROCKS_UNAME_M=[[x86]]>> "%LUADIR%\luarocks\config.lua" 277ECHO LUAROCKS_UNAME_M=[[x86]]>> "%LUADIR%\luarocks\config.lua"
267ECHO LUAROCKS_SYSCONFIG=[[%SYSCONFDIR%/config.lua]]>> "%LUADIR%\luarocks\config.lua" 278ECHO LUAROCKS_SYSCONFIG=[[%SYSCONFDIR%/config.lua]]>> "%LUADIR%\luarocks\config.lua"
268ECHO LUAROCKS_ROCKS_TREE=[[%ROCKS_TREE%]]>> "%LUADIR%\luarocks\config.lua" 279ECHO LUAROCKS_ROCKS_TREE=[[%ROCKS_TREE%]]>> "%LUADIR%\luarocks\config.lua"
diff --git a/src/bin/rclauncher.c b/src/bin/rclauncher.c
new file mode 100644
index 00000000..4ff23e4a
--- /dev/null
+++ b/src/bin/rclauncher.c
@@ -0,0 +1,118 @@
1
2/*
3** Simple Lua interpreter.
4** This program is used to run a Lua file embedded as a resource.
5** It creates a Lua state, opens all its standard libraries, and run
6** the Lua file in a protected environment just to redirect the error
7** messages to stdout and stderr.
8**
9** $Id: rclauncher.c,v 1.1 2008/06/30 14:29:59 carregal Exp $
10*/
11
12#include <string.h>
13#include <stdlib.h>
14
15#include "lua.h"
16#include "lauxlib.h"
17#include "lualib.h"
18#include <windows.h>
19#include <io.h>
20#include <fcntl.h>
21
22/*
23** Report error message.
24** Assumes that the error message is on top of the stack.
25*/
26static int report (lua_State *L) {
27 fprintf (stderr, "lua: fatal error: `%s'\n", lua_tostring (L, -1));
28 fflush (stderr);
29 printf ("Content-type: text/plain\n\nConfiguration fatal error: see error log!\n");
30 printf ("%s", lua_tostring(L, -1));
31 return 1;
32}
33
34static int runlua (lua_State *L, const char *lua_string, int argc, char *argv[]) {
35 int err_func;
36 int err;
37
38 lua_pushliteral(L, "debug");
39 lua_rawget(L, LUA_GLOBALSINDEX); /* get traceback function */
40 lua_pushliteral(L, "traceback");
41 lua_gettable(L, -2);
42 err_func = lua_gettop (L);
43 err = luaL_loadstring (L, lua_string);
44 if(!err) {
45 int i;
46 for(i = 1; i < argc; i++)
47 lua_pushstring(L, argv[i]);
48 return lua_pcall (L, argc - 1, LUA_MULTRET, err_func);
49 } else return err;
50}
51
52static DWORD GetModulePath( HINSTANCE hInst, LPTSTR pszBuffer, DWORD dwSize )
53//
54// Return the size of the path in bytes.
55{
56 DWORD dwLength = GetModuleFileName( hInst, pszBuffer, dwSize );
57 if( dwLength )
58 {
59 while( dwLength && pszBuffer[ dwLength ] != '.' )
60 {
61 dwLength--;
62 }
63
64 if( dwLength )
65 pszBuffer[ dwLength ] = '\000';
66 }
67 return dwLength;
68}
69
70
71/*
72** MAIN
73*/
74int main (int argc, char *argv[]) {
75 char name[ MAX_PATH ];
76 DWORD dwLength;
77 int size;
78 luaL_Buffer b;
79 int i;
80#ifdef UNICODE
81 TCHAR lua_wstring[4098];
82#endif
83 char lua_string[4098];
84 lua_State *L = lua_open();
85 (void)argc; /* avoid "unused parameter" warning */
86 luaL_openlibs(L);
87 dwLength = GetModulePath( NULL, name, MAX_PATH );
88 if(dwLength) { /* Optional bootstrap */
89 strcat(name, ".lua");
90 if(!luaL_loadfile (L, name)) {
91 if(lua_pcall (L, 0, LUA_MULTRET, 0)) {
92 report (L);
93 lua_close (L);
94 return EXIT_FAILURE;
95 }
96 }
97 }
98 luaL_buffinit(L, &b);
99 for(i = 1; ; i++) {
100#ifdef UNICODE
101 size = LoadString(GetModuleHandle(NULL), i, lua_wstring,
102 sizeof(lua_string)/sizeof(TCHAR));
103 if(size > 0) wcstombs(lua_string, lua_wstring, size + 1);
104#else
105 size = LoadString(GetModuleHandle(NULL), i, lua_string,
106 sizeof(lua_string)/sizeof(char));
107#endif
108 if(size) luaL_addlstring(&b, lua_string, size); else break;
109 }
110 luaL_pushresult(&b);
111 if (runlua (L, lua_tostring(L, -1), argc, argv)) {
112 report (L);
113 lua_close (L);
114 return EXIT_FAILURE;
115 }
116 lua_close (L);
117 return EXIT_SUCCESS;
118}
diff --git a/src/luarocks/build/builtin.lua b/src/luarocks/build/builtin.lua
index b874b82d..dacaad0a 100644
--- a/src/luarocks/build/builtin.lua
+++ b/src/luarocks/build/builtin.lua
@@ -76,7 +76,37 @@ function run(rockspec)
76 end 76 end
77 end 77 end
78 78
79 if is_platform("win32") then 79 if is_platform("mingw32") then
80 compile_object = function(object, source, defines, incdirs)
81 local extras = {}
82 add_flags(extras, "-D%s", defines)
83 add_flags(extras, "-I%s", incdirs)
84 return execute(variables.CC.." "..variables.CFLAGS, "-c", "-o", object, "-I"..variables.LUA_INCDIR, source, unpack(extras))
85 end
86 compile_library = function(library, objects, libraries, libdirs, name)
87 local extras = { unpack(objects) }
88 add_flags(extras, "-L%s", libdirs)
89 add_flags(extras, "-l%s", libraries)
90 extras[#extras+1] = "-L" .. variables.LUA_LIBDIR
91 extras[#extras+1] = "-llua51"
92 extras[#extras+1] = "-lmsvcrt"
93 local ok = execute(variables.LD.." "..variables.LIBFLAG, "-o", library, unpack(extras))
94 return ok
95 end
96 compile_wrapper_binary = function(fullname, name)
97 local fullbasename = fullname:gsub("%.lua$", ""):gsub("/", "\\")
98 local basename = name:gsub("%.lua$", ""):gsub("/", "\\")
99 local rcname = basename..".rc"
100 local resname = basename..".o"
101 local wrapname = basename..".exe"
102 make_rc(fullname, fullbasename..".rc")
103 local ok = execute(variables.RC, "-o", resname, rcname)
104 if not ok then return ok end
105 ok = execute(variables.LD, "-o", wrapname, resname, variables.WRAPPER,
106 "-L"..variables.LUA_LIBDIR, "-llua51", "-lmsvcrt", "-luser32")
107 return ok, wrapname
108 end
109 elseif is_platform("win32") then
80 compile_object = function(object, source, defines, incdirs) 110 compile_object = function(object, source, defines, incdirs)
81 local extras = {} 111 local extras = {}
82 add_flags(extras, "-D%s", defines) 112 add_flags(extras, "-D%s", defines)
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 220e7b29..5ec87bf5 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -74,6 +74,8 @@ elseif system and system:match("^CYGWIN") then
74 detected.cygwin = true 74 detected.cygwin = true
75elseif system and system:match("^Windows") then 75elseif system and system:match("^Windows") then
76 detected.windows = true 76 detected.windows = true
77elseif system and system:match("^MINGW") then
78 detected.mingw32 = true
77else 79else
78 detected.unix = true 80 detected.unix = true
79 -- Fall back to Unix in unknown systems. 81 -- Fall back to Unix in unknown systems.
@@ -82,7 +84,7 @@ end
82-- Path configuration: 84-- Path configuration:
83 85
84local sys_config_file, home_config_file, home_tree 86local sys_config_file, home_config_file, home_tree
85if detected.windows then 87if detected.windows or detected.mingw32 then
86 home = os.getenv("APPDATA") or "c:" 88 home = os.getenv("APPDATA") or "c:"
87 sys_config_file = "c:/luarocks/config.lua" 89 sys_config_file = "c:/luarocks/config.lua"
88 home_config_file = home.."/luarocks/config.lua" 90 home_config_file = home.."/luarocks/config.lua"
@@ -185,6 +187,39 @@ if detected.windows then
185 defaults.local_cache = home.."/cache/luarocks" 187 defaults.local_cache = home.."/cache/luarocks"
186end 188end
187 189
190if detected.mingw32 then
191 home_config_file = home_config_file:gsub("\\","/")
192 defaults.arch = "mingw32-"..proc
193 defaults.platforms = { "win32", "mingw32" }
194 defaults.lib_extension = "dll"
195 defaults.external_lib_extension = "dll"
196 defaults.obj_extension = "o"
197 defaults.external_deps_dirs = { "c:/external/" }
198 defaults.variables.LUA_BINDIR = config.LUA_BINDIR and config.LUA_BINDIR:gsub("\\", "/") or "c:/lua5.1/bin"
199 defaults.variables.LUA_INCDIR = config.LUA_INCDIR and config.LUA_INCDIR:gsub("\\", "/") or "c:/lua5.1/include"
200 defaults.variables.LUA_LIBDIR = config.LUA_LIBDIR and config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua5.1/lib"
201 defaults.cmake_generator = "MinGW Makefiles"
202 defaults.make = "mingw32-make" -- TODO: Split Windows flavors between mingw and msvc
203 defaults.makefile = "Makefile.win"
204 defaults.variables.CC = "gcc"
205 defaults.variables.RC = "windres"
206 defaults.variables.WRAPPER = config.LUAROCKS_PREFIX .. "\\2.0\\rclauncher.o"
207 defaults.variables.LD = "gcc"
208 defaults.variables.CFLAGS = "-O2"
209 defaults.variables.LIBFLAG = "-shared --dll --export-all-symbols"
210 defaults.external_deps_patterns = {
211 bin = { "?.exe", "?.bat" },
212 lib = { "lib?.a", "?.dll", "lib?.dll" },
213 include = { "?.h" }
214 }
215 defaults.runtime_external_deps_patterns = {
216 bin = { "?.exe", "?.bat" },
217 lib = { "?.dll", "lib?.dll" },
218 include = { "?.h" }
219 }
220 defaults.local_cache = home.."/cache/luarocks"
221end
222
188if detected.unix then 223if detected.unix then
189 defaults.lib_extension = "so" 224 defaults.lib_extension = "so"
190 defaults.external_lib_extension = "so" 225 defaults.external_lib_extension = "so"