Mercurial > repo
comparison share/lua/5.2/luarocks/cfg.lua @ 1132:d137f631bad5
<GreyKnight> (cd luabuild/luarocks-2.0.12; make install)
author | HackBot |
---|---|
date | Fri, 14 Dec 2012 22:24:27 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1131:ff65dfb63263 | 1132:d137f631bad5 |
---|---|
1 --- Configuration for LuaRocks. | |
2 -- Tries to load the user's configuration file and | |
3 -- defines defaults for unset values. See the | |
4 -- <a href="http://luarocks.org/en/Config_file_format">config | |
5 -- file format documentation</a> for details. | |
6 -- | |
7 -- End-users shouldn't edit this file. They can override any defaults | |
8 -- set in this file using their system-wide $LUAROCKS_SYSCONFIG file | |
9 -- (see luarocks.site_config) or their user-specific configuration file | |
10 -- (~/.luarocks/config.lua on Unix or %APPDATA%/luarocks/config.lua on | |
11 -- Windows). | |
12 | |
13 local rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION = | |
14 rawset, next, table, pairs, require, io, os, setmetatable, pcall, ipairs, package, tonumber, type, assert, _VERSION | |
15 | |
16 module("luarocks.cfg") | |
17 | |
18 -- Load site-local global configurations | |
19 local ok, site_config = pcall(require, "luarocks.site_config") | |
20 if not ok then | |
21 io.stderr:write("Site-local luarocks/site_config.lua file not found. Incomplete installation?\n") | |
22 site_config = {} | |
23 end | |
24 | |
25 _M.site_config = site_config | |
26 | |
27 lua_version = _VERSION:sub(5) | |
28 program_version = "2.0.12" | |
29 | |
30 local persist = require("luarocks.persist") | |
31 | |
32 local popen_ok, popen_result = pcall(io.popen, "") | |
33 if popen_ok then | |
34 if popen_result then | |
35 popen_result:close() | |
36 end | |
37 else | |
38 io.stderr:write("Your version of Lua does not support io.popen,\n") | |
39 io.stderr:write("which is required by LuaRocks. Please check your Lua installation.\n") | |
40 os.exit(1) | |
41 end | |
42 | |
43 -- System detection: | |
44 | |
45 local detected = {} | |
46 local system,proc | |
47 | |
48 -- A proper installation of LuaRocks will hardcode the system | |
49 -- and proc values with site_config.LUAROCKS_UNAME_S and site_config.LUAROCKS_UNAME_M, | |
50 -- so that this detection does not run every time. When it is | |
51 -- performed, we use the Unix way to identify the system, | |
52 -- even on Windows (assuming UnxUtils or Cygwin). | |
53 system = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l") | |
54 proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l") | |
55 if proc:match("i[%d]86") then | |
56 proc = "x86" | |
57 elseif proc:match("amd64") or proc:match("x86_64") then | |
58 proc = "x86_64" | |
59 elseif proc:match("Power Macintosh") then | |
60 proc = "powerpc" | |
61 end | |
62 | |
63 if system == "FreeBSD" then | |
64 detected.unix = true | |
65 detected.freebsd = true | |
66 detected.bsd = true | |
67 elseif system == "OpenBSD" then | |
68 detected.unix = true | |
69 detected.openbsd = true | |
70 detected.bsd = true | |
71 elseif system == "NetBSD" then | |
72 detected.unix = true | |
73 detected.netbsd = true | |
74 detected.bsd = true | |
75 elseif system == "Darwin" then | |
76 detected.unix = true | |
77 detected.macosx = true | |
78 detected.bsd = true | |
79 elseif system == "Linux" then | |
80 detected.unix = true | |
81 detected.linux = true | |
82 elseif system == "SunOS" then | |
83 detected.unix = true | |
84 detected.solaris = true | |
85 elseif system and system:match("^CYGWIN") then | |
86 detected.unix = true | |
87 detected.cygwin = true | |
88 elseif system and system:match("^Windows") then | |
89 detected.windows = true | |
90 elseif system and system:match("^MINGW") then | |
91 detected.windows = true | |
92 detected.mingw32 = true | |
93 else | |
94 detected.unix = true | |
95 -- Fall back to Unix in unknown systems. | |
96 end | |
97 | |
98 -- Path configuration: | |
99 | |
100 local version_suffix = lua_version:gsub ("%.", "_") | |
101 local sys_config_file, home_config_file | |
102 local sys_config_ok, home_config_ok = false, false | |
103 sys_config_file = site_config["LUAROCKS_SYSCONFIG_" .. version_suffix] or site_config.LUAROCKS_SYSCONFIG | |
104 if detected.windows then | |
105 home = os.getenv("APPDATA") or "c:" | |
106 sys_config_file = sys_config_file or "c:/luarocks/config.lua" | |
107 home_config_file = home.."/luarocks/config.lua" | |
108 home_tree = home.."/luarocks/" | |
109 else | |
110 home = os.getenv("HOME") or "" | |
111 sys_config_file = sys_config_file or "/etc/luarocks/config.lua" | |
112 home_config_file = home.."/.luarocks/config.lua" | |
113 home_tree = home.."/.luarocks/" | |
114 end | |
115 | |
116 variables = {} | |
117 rocks_trees = {} | |
118 | |
119 local ok, err = persist.load_into_table(sys_config_file, _M) | |
120 if ok then | |
121 sys_config_ok = true | |
122 else -- nil or false | |
123 sys_config_ok = ok | |
124 if err and ok == nil then | |
125 io.stderr:write(err.."\n") | |
126 end | |
127 end | |
128 | |
129 if not site_config.LUAROCKS_FORCE_CONFIG then | |
130 home_config_file = os.getenv("LUAROCKS_CONFIG_" .. version_suffix) or os.getenv("LUAROCKS_CONFIG") or home_config_file | |
131 local home_overrides, err = persist.load_into_table(home_config_file, { home = home }) | |
132 if home_overrides then | |
133 home_config_ok = true | |
134 local util = require("luarocks.util") | |
135 if home_overrides.rocks_trees then | |
136 _M.rocks_trees = nil | |
137 end | |
138 if home_overrides.rocks_servers then | |
139 _M.rocks_servers = nil | |
140 end | |
141 util.deep_merge(_M, home_overrides) | |
142 else -- nil or false | |
143 home_config_ok = home_overrides | |
144 if err and home_config_ok == nil then | |
145 io.stderr:write(err.."\n") | |
146 end | |
147 end | |
148 end | |
149 | |
150 if not next(rocks_trees) then | |
151 if home_tree then | |
152 table.insert(rocks_trees, home_tree) | |
153 end | |
154 if site_config.LUAROCKS_ROCKS_TREE then | |
155 table.insert(rocks_trees, site_config.LUAROCKS_ROCKS_TREE) | |
156 end | |
157 end | |
158 | |
159 -- Configure defaults: | |
160 | |
161 local root = rocks_trees[#rocks_trees] | |
162 local defaults = { | |
163 | |
164 local_by_default = false, | |
165 use_extensions = false, | |
166 accept_unknown_fields = false, | |
167 fs_use_modules = true, | |
168 deps_mode = "one", | |
169 | |
170 lua_modules_path = "/share/lua/"..lua_version, | |
171 lib_modules_path = "/lib/lua/"..lua_version, | |
172 | |
173 arch = "unknown", | |
174 lib_extension = "unknown", | |
175 obj_extension = "unknown", | |
176 | |
177 rocks_servers = { | |
178 { | |
179 "http://www.luarocks.org/repositories/rocks", | |
180 "http://luarocks.giga.puc-rio.br/", | |
181 "http://luafr.org/luarocks/rocks", | |
182 "http://liblua.so/luarocks/repositories/rocks", | |
183 "http://luarocks.logiceditor.com/rocks", | |
184 } | |
185 }, | |
186 | |
187 lua_extension = "lua", | |
188 lua_interpreter = site_config.LUA_INTERPRETER or "lua", | |
189 downloader = site_config.LUAROCKS_DOWNLOADER or "wget", | |
190 md5checker = site_config.LUAROCKS_MD5CHECKER or "md5sum", | |
191 | |
192 variables = { | |
193 MAKE = "make", | |
194 CC = "cc", | |
195 LD = "ld", | |
196 | |
197 CVS = "cvs", | |
198 GIT = "git", | |
199 SSCM = "sscm", | |
200 SVN = "svn", | |
201 HG = "hg", | |
202 | |
203 RSYNC = "rsync", | |
204 WGET = "wget", | |
205 SCP = "scp", | |
206 CURL = "curl", | |
207 | |
208 PWD = "pwd", | |
209 MKDIR = "mkdir", | |
210 RMDIR = "rmdir", | |
211 CP = "cp", | |
212 LS = "ls", | |
213 RM = "rm", | |
214 FIND = "find", | |
215 TEST = "test", | |
216 CHMOD = "chmod", | |
217 PATCH = "patch", | |
218 | |
219 ZIP = "zip", | |
220 UNZIP = "unzip", | |
221 GUNZIP = "gunzip", | |
222 BUNZIP2 = "bunzip2", | |
223 TAR = "tar", | |
224 | |
225 MD5SUM = "md5sum", | |
226 OPENSSL = "openssl", | |
227 MD5 = "md5", | |
228 STAT = "stat", | |
229 | |
230 CMAKE = "cmake", | |
231 SEVENZ = "7z", | |
232 | |
233 STATFLAG = "-c '%a'", | |
234 }, | |
235 | |
236 external_deps_subdirs = { | |
237 bin = "bin", | |
238 lib = "lib", | |
239 include = "include" | |
240 }, | |
241 runtime_external_deps_subdirs = { | |
242 bin = "bin", | |
243 lib = "lib", | |
244 include = "include" | |
245 }, | |
246 } | |
247 | |
248 if detected.windows then | |
249 home_config_file = home_config_file:gsub("\\","/") | |
250 defaults.fs_use_modules = false | |
251 defaults.arch = "win32-"..proc | |
252 defaults.platforms = {"win32", "windows" } | |
253 defaults.lib_extension = "dll" | |
254 defaults.external_lib_extension = "dll" | |
255 defaults.obj_extension = "obj" | |
256 defaults.external_deps_dirs = { "c:/external/" } | |
257 defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR and site_config.LUA_BINDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/bin" | |
258 defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR and site_config.LUA_INCDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/include" | |
259 defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR and site_config.LUA_LIBDIR:gsub("\\", "/") or "c:/lua"..lua_version.."/lib" | |
260 defaults.cmake_generator = "MinGW Makefiles" | |
261 defaults.makefile = "Makefile.win" | |
262 defaults.variables.MAKE = "nmake" | |
263 defaults.variables.CC = "cl" | |
264 defaults.variables.RC = "rc" | |
265 defaults.variables.WRAPPER = site_config.LUAROCKS_PREFIX .. "\\2.0\\rclauncher.obj" | |
266 defaults.variables.LD = "link" | |
267 defaults.variables.MT = "mt" | |
268 defaults.variables.LUALIB = "lua"..lua_version..".lib" | |
269 defaults.variables.CFLAGS = "/MD /O2" | |
270 defaults.variables.LIBFLAG = "/dll" | |
271 defaults.variables.LUALIB = "lua"..lua_version..".lib" | |
272 defaults.external_deps_patterns = { | |
273 bin = { "?.exe", "?.bat" }, | |
274 lib = { "?.lib", "?.dll", "lib?.dll" }, | |
275 include = { "?.h" } | |
276 } | |
277 defaults.runtime_external_deps_patterns = { | |
278 bin = { "?.exe", "?.bat" }, | |
279 lib = { "?.dll", "lib?.dll" }, | |
280 include = { "?.h" } | |
281 } | |
282 defaults.export_path = "SET PATH=%s" | |
283 defaults.export_path_separator = ";" | |
284 defaults.export_lua_path = "SET LUA_PATH=%s" | |
285 defaults.export_lua_cpath = "SET LUA_CPATH=%s" | |
286 defaults.local_cache = home.."/cache/luarocks" | |
287 end | |
288 | |
289 if detected.mingw32 then | |
290 defaults.platforms = { "win32", "mingw32" } | |
291 defaults.obj_extension = "o" | |
292 defaults.cmake_generator = "MinGW Makefiles" | |
293 defaults.variables.MAKE = "mingw32-make" | |
294 defaults.variables.CC = "mingw32-gcc" | |
295 defaults.variables.RC = "windres" | |
296 defaults.variables.WRAPPER = site_config.LUAROCKS_PREFIX .. "\\2.0\\rclauncher.o" | |
297 defaults.variables.LD = "mingw32-gcc" | |
298 defaults.variables.CFLAGS = "-O2" | |
299 defaults.variables.LIBFLAG = "-shared" | |
300 end | |
301 | |
302 if detected.unix then | |
303 defaults.lib_extension = "so" | |
304 defaults.external_lib_extension = "so" | |
305 defaults.obj_extension = "o" | |
306 defaults.external_deps_dirs = { "/usr/local", "/usr" } | |
307 defaults.variables.LUA_BINDIR = site_config.LUA_BINDIR or "/usr/local/bin" | |
308 defaults.variables.LUA_INCDIR = site_config.LUA_INCDIR or "/usr/local/include" | |
309 defaults.variables.LUA_LIBDIR = site_config.LUA_LIBDIR or "/usr/local/lib" | |
310 defaults.variables.CFLAGS = "-O2" | |
311 defaults.cmake_generator = "Unix Makefiles" | |
312 defaults.platforms = { "unix" } | |
313 defaults.variables.CC = "gcc" | |
314 defaults.variables.LD = "gcc" | |
315 defaults.gcc_rpath = true | |
316 defaults.variables.LIBFLAG = "-shared" | |
317 defaults.external_deps_patterns = { | |
318 bin = { "?" }, | |
319 lib = { "lib?.a", "lib?.so", "lib?.so.*" }, | |
320 include = { "?.h" } | |
321 } | |
322 defaults.runtime_external_deps_patterns = { | |
323 bin = { "?" }, | |
324 lib = { "lib?.so", "lib?.so.*" }, | |
325 include = { "?.h" } | |
326 } | |
327 defaults.export_path = "export PATH='%s'" | |
328 defaults.export_path_separator = ":" | |
329 defaults.export_lua_path = "export LUA_PATH='%s'" | |
330 defaults.export_lua_cpath = "export LUA_CPATH='%s'" | |
331 defaults.local_cache = home.."/.cache/luarocks" | |
332 if not defaults.variables.CFLAGS:match("-fPIC") then | |
333 defaults.variables.CFLAGS = defaults.variables.CFLAGS.." -fPIC" | |
334 end | |
335 end | |
336 | |
337 if detected.cygwin then | |
338 defaults.lib_extension = "so" -- can be overridden in the config file for mingw builds | |
339 defaults.arch = "cygwin-"..proc | |
340 defaults.platforms = {"unix", "cygwin"} | |
341 defaults.cmake_generator = "Unix Makefiles" | |
342 defaults.variables.CC = "echo -llua | xargs gcc" | |
343 defaults.variables.LD = "echo -llua | xargs gcc" | |
344 defaults.variables.LIBFLAG = "-shared" | |
345 end | |
346 | |
347 if detected.bsd then | |
348 defaults.variables.MAKE = "gmake" | |
349 defaults.variables.STATFLAG = "-f '%OLp'" | |
350 end | |
351 | |
352 if detected.macosx then | |
353 defaults.external_lib_extension = "dylib" | |
354 defaults.arch = "macosx-"..proc | |
355 defaults.platforms = {"unix", "bsd", "macosx"} | |
356 defaults.variables.LIBFLAG = "-bundle -undefined dynamic_lookup -all_load" | |
357 defaults.variables.STATFLAG = "-f '%A'" | |
358 local version = io.popen("sw_vers -productVersion"):read("*l") | |
359 version = tonumber(version and version:match("^[^.]+%.([^.]+)")) or 3 | |
360 if version >= 5 then | |
361 version = 5 | |
362 else | |
363 defaults.gcc_rpath = false | |
364 end | |
365 defaults.variables.CC = "export MACOSX_DEPLOYMENT_TARGET=10."..version.."; gcc" | |
366 defaults.variables.LD = "export MACOSX_DEPLOYMENT_TARGET=10."..version.."; gcc" | |
367 end | |
368 | |
369 if detected.linux then | |
370 defaults.arch = "linux-"..proc | |
371 defaults.platforms = {"unix", "linux"} | |
372 end | |
373 | |
374 if detected.freebsd then | |
375 defaults.arch = "freebsd-"..proc | |
376 defaults.platforms = {"unix", "bsd", "freebsd"} | |
377 end | |
378 | |
379 if detected.openbsd then | |
380 defaults.arch = "openbsd-"..proc | |
381 defaults.platforms = {"unix", "bsd", "openbsd"} | |
382 end | |
383 | |
384 if detected.netbsd then | |
385 defaults.arch = "netbsd-"..proc | |
386 defaults.platforms = {"unix", "bsd", "netbsd"} | |
387 end | |
388 | |
389 if detected.solaris then | |
390 defaults.arch = "solaris-"..proc | |
391 defaults.platforms = {"unix", "solaris"} | |
392 defaults.variables.MAKE = "gmake" | |
393 end | |
394 | |
395 -- Expose some more values detected by LuaRocks for use by rockspec authors. | |
396 defaults.variables.LIB_EXTENSION = defaults.lib_extension | |
397 defaults.variables.OBJ_EXTENSION = defaults.obj_extension | |
398 defaults.variables.LUAROCKS_PREFIX = site_config.LUAROCKS_PREFIX | |
399 defaults.variables.LUA = site_config.LUA_DIR_SET and (defaults.variables.LUA_BINDIR.."/"..defaults.lua_interpreter) or defaults.lua_interpreter | |
400 | |
401 -- Use defaults: | |
402 | |
403 -- Populate values from 'defaults.variables' in 'variables' if they were not | |
404 -- already set by user. | |
405 if not _M.variables then | |
406 _M.variables = {} | |
407 end | |
408 for k,v in pairs(defaults.variables) do | |
409 if not _M.variables[k] then | |
410 _M.variables[k] = v | |
411 end | |
412 end | |
413 | |
414 -- For values not set in the config file, use values from the 'defaults' table. | |
415 local cfg_mt = { | |
416 __index = function(t, k) | |
417 local default = defaults[k] | |
418 if default then | |
419 rawset(t, k, default) | |
420 end | |
421 return default | |
422 end | |
423 } | |
424 setmetatable(_M, cfg_mt) | |
425 | |
426 for _,tree in ipairs(rocks_trees) do | |
427 if type(tree) == "string" then | |
428 package.path = tree..lua_modules_path.."/?.lua;"..tree..lua_modules_path.."/?/init.lua;"..package.path | |
429 package.cpath = tree..lib_modules_path.."/?."..lib_extension..";"..package.cpath | |
430 else | |
431 package.path = (tree.lua_dir or tree.root..lua_modules_path).."/?.lua;".. | |
432 (tree.lua_dir or tree.root..lua_modules_path).."/?/init.lua;"..package.path | |
433 package.cpath = (tree.lib_dir or tree.root..lib_modules_path).."/?."..lib_extension..";"..package.cpath | |
434 end | |
435 end | |
436 | |
437 function which_config() | |
438 return sys_config_file, sys_config_ok, home_config_file, home_config_ok | |
439 end | |
440 | |
441 user_agent = "LuaRocks/"..program_version.." "..arch | |
442 | |
443 --- Check if platform was detected | |
444 -- @param query string: The platform name to check. | |
445 -- @return boolean: true if LuaRocks is currently running on queried platform. | |
446 function is_platform(query) | |
447 assert(type(query) == "string") | |
448 | |
449 for _, platform in ipairs(platforms) do | |
450 if platform == query then | |
451 return true | |
452 end | |
453 end | |
454 end |