lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

I recently faced the problem of building and installing luasocket-2.0.2-5
using luarocks-2.0.12 with a TDM/MinGW build system. The attached patch adds
the missing "mingw32" build platform support to the original
luasocket-2.0.2-5.rockspec. 

In order to apply this patch, you have to download and unpack
luasocket-2.0.2-5 from your rock-server using the following command "#>
luarocks unpack luasocket 2.0.2-5". The patch must be applied against the
original luasocket-2.0.2-5/luasocket-2.0.2-5.rockspec file.

The patched rock can be built and installed as usual using the command: 
"#> cd luasocket-2.0.2-5/luasocket-2.0.2 && luarocks.bat make
../luasocket-2.0.2-5.rockspec"

If you are using (like me) a recent luarocks version which has been build
with "/MW" (mingw32 build system) switch, then the "mingw32" build settings
from the patch will be used to compile and link luasocket. In particular,
the build process for mingw32 platforms will not use the makefile mechanism
but the "builtin" build mode of luarocks. This feature avoids a former build
error caused by a "missing Makefile.win" in luasocket rock archive. The
installation directories for LUA scripts, DLLs, etc. will be the same as
before.
  
One problem I have encountered when building the patched luasocket rock was
a link error concerning the external ws2_32 library. Unfortunately, the
"builtin" build mode of my luarocks version includes the "ws32_2" library
from the rockspec's build.platforms.mingw32.socket.core.libraries table as
"ws2_32.lib" in the linker commandline. However, for use with TDM/MinGW the
linker command must be "-lw32_2". To overcome this problem I have manually
changed the mingw32-specific "compile_library" function from file
<luarocks>\lua\luarocks\build\builtin.lua. The corresponding patch is also
attached to this post.     

Cheers,
Kai

--- D:\Temp\luasocket_orig\luasocket-2.0.2-5\luasocket-2.0.2-5.rockspec
2012-03-10 00:12:00.000000000 +-0100
+++ D:\Temp\luasocket_patch\luasocket-2.0.2-5\luasocket-2.0.2-5.rockspec
2013-01-03 17:06:24.000000000 +-0100
@@ -57,10 +57,42 @@
                ["socket.http"] = "src/http.lua",
                ["socket.smtp"] = "src/smtp.lua",
                ["socket.tp"] = "src/tp.lua",
                ["socket.url"] = "src/url.lua",               
             }
          }
-      }
+      },
+      mingw32 = {
+		type = "builtin",
+		modules = {
+		
+			-- LUA modules
+			socket = "src/socket.lua",
+			mime = "src/mime.lua",
+			ltn12 = "src/ltn12.lua",
+			
+			-- LUA submodules
+			["socket.ftp"] = "src/ftp.lua",
+            ["socket.http"] = "src/http.lua",
+            ["socket.smtp"] = "src/smtp.lua",
+            ["socket.tp"] = "src/tp.lua",
+            ["socket.url"] = "src/url.lua", 
+			
+			-- C module socket.core
+			["socket.core"] = {
+				sources = {"src/luasocket.c",
"src/timeout.c", "src/buffer.c", "src/io.c", 
+						   "src/auxiliar.c",
"src/options.c", "src/inet.c", "src/tcp.c", "src/udp.c", 
+						   "src/except.c",
"src/select.c", "src/wsocket.c"},
+				defines = {"WIN32", "LUASOCKET_DEBUG",
"LUASOCKET_API=__declspec(dllexport)"},
+				libraries = {"ws2_32"}
+			},
+			
+			-- C module mime.core
+			["mime.core"] = {
+				sources = {"src/mime.c"},
+				defines = {"WIN32",
"LUASOCKET_API=__declspec(dllexport)"}
+			}
+		}
+     }
    },
    copy_directories = { "doc", "samples", "etc", "test" }
 }

///////////////////////////////////////////////

--- D:\Temp\luarocks-2.02-1_customized\src\luarocks\build\builtin.lua
2013-01-03 20:06:28.000000000 +-0100
+++ D:\Devtools\luarocks\2.0\lua\luarocks\build\builtin.lua	2013-01-03
19:52:17.000000000 +-0100
@@ -70,15 +70,16 @@
          add_flags(extras, "-I%s", incdirs)
          return execute(variables.CC.." "..variables.CFLAGS, "-c", "-o",
object, "-I"..variables.LUA_INCDIR, source, unpack(extras))
       end
       compile_library = function(library, objects, libraries, libdirs,
name)
          local extras = { unpack(objects) }
          add_flags(extras, "-L%s", libdirs)
-         add_flags(extras, "%s.lib", libraries)
+         -- add_flags(extras, "%s.lib", libraries)
+         add_flags(extras, "-l%s", libraries)
          extras[#extras+1] = dir.path(variables.LUA_LIBDIR,
variables.LUALIB)
-         extras[#extras+1] = "-l" .. (variables.MSVCRT or "msvcr80")
+         -- extras[#extras+1] = "-l" .. (variables.MSVCRT or "msvcr80")
          local ok = execute(variables.LD.." "..variables.LIBFLAG, "-o",
library, unpack(extras))
          return ok
       end
       compile_wrapper_binary = function(fullname, name)
          local fullbasename = fullname:gsub("%.lua$", ""):gsub("/", "\\")
          local basename = name:gsub("%.lua$", ""):gsub("/", "\\")

///////////////////////////////////////////////