aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/luarocks/cfg.lua92
1 files changed, 45 insertions, 47 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 8321e9b9..ff18e0a3 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -35,6 +35,9 @@ end
35cfg.program_version = "scm" 35cfg.program_version = "scm"
36cfg.program_series = "2.2" 36cfg.program_series = "2.2"
37cfg.major_version = (cfg.program_version:match("([^.]%.[^.])")) or cfg.program_series 37cfg.major_version = (cfg.program_version:match("([^.]%.[^.])")) or cfg.program_series
38cfg.variables = {}
39cfg.rocks_trees = {}
40cfg.platform = {}
38 41
39local persist = require("luarocks.persist") 42local persist = require("luarocks.persist")
40 43
@@ -68,57 +71,55 @@ end
68 71
69-- System detection: 72-- System detection:
70 73
71local detected = {}
72local system,proc
73
74-- A proper installation of LuaRocks will hardcode the system 74-- A proper installation of LuaRocks will hardcode the system
75-- and proc values with site_config.LUAROCKS_UNAME_S and site_config.LUAROCKS_UNAME_M, 75-- and proc values with site_config.LUAROCKS_UNAME_S and site_config.LUAROCKS_UNAME_M,
76-- so that this detection does not run every time. When it is 76-- so that this detection does not run every time. When it is
77-- performed, we use the Unix way to identify the system, 77-- performed, we use the Unix way to identify the system,
78-- even on Windows (assuming UnxUtils or Cygwin). 78-- even on Windows (assuming UnxUtils or Cygwin).
79system = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l") 79local system = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l")
80proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l") 80local proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l")
81if proc:match("i[%d]86") then 81if proc:match("i[%d]86") then
82 proc = "x86" 82 cfg.target_cpu = "x86"
83elseif proc:match("amd64") or proc:match("x86_64") then 83elseif proc:match("amd64") or proc:match("x86_64") then
84 proc = "x86_64" 84 cfg.target_cpu = "x86_64"
85elseif proc:match("Power Macintosh") then 85elseif proc:match("Power Macintosh") then
86 proc = "powerpc" 86 cfg.target_cpu = "powerpc"
87 else
88 cfg.target_cpu = proc
87end 89end
88cfg.target_cpu = proc
89 90
90if system == "FreeBSD" then 91if system == "FreeBSD" then
91 detected.unix = true 92 cfg.platform.unix = true
92 detected.freebsd = true 93 cfg.platform.freebsd = true
93 detected.bsd = true 94 cfg.platform.bsd = true
94elseif system == "OpenBSD" then 95elseif system == "OpenBSD" then
95 detected.unix = true 96 cfg.platform.unix = true
96 detected.openbsd = true 97 cfg.platform.openbsd = true
97 detected.bsd = true 98 cfg.platform.bsd = true
98elseif system == "NetBSD" then 99elseif system == "NetBSD" then
99 detected.unix = true 100 cfg.platform.unix = true
100 detected.netbsd = true 101 cfg.platform.netbsd = true
101 detected.bsd = true 102 cfg.platform.bsd = true
102elseif system == "Darwin" then 103elseif system == "Darwin" then
103 detected.unix = true 104 cfg.platform.unix = true
104 detected.macosx = true 105 cfg.platform.macosx = true
105 detected.bsd = true 106 cfg.platform.bsd = true
106elseif system == "Linux" then 107elseif system == "Linux" then
107 detected.unix = true 108 cfg.platform.unix = true
108 detected.linux = true 109 cfg.platform.linux = true
109elseif system == "SunOS" then 110elseif system == "SunOS" then
110 detected.unix = true 111 cfg.platform.unix = true
111 detected.solaris = true 112 cfg.platform.solaris = true
112elseif system and system:match("^CYGWIN") then 113elseif system and system:match("^CYGWIN") then
113 detected.unix = true 114 cfg.platform.unix = true
114 detected.cygwin = true 115 cfg.platform.cygwin = true
115elseif system and system:match("^Windows") then 116elseif system and system:match("^Windows") then
116 detected.windows = true 117 cfg.platform.windows = true
117elseif system and system:match("^MINGW") then 118elseif system and system:match("^MINGW") then
118 detected.windows = true 119 cfg.platform.windows = true
119 detected.mingw32 = true 120 cfg.platform.mingw32 = true
120else 121else
121 detected.unix = true 122 cfg.platform.unix = true
122 -- Fall back to Unix in unknown systems. 123 -- Fall back to Unix in unknown systems.
123end 124end
124 125
@@ -129,7 +130,7 @@ local sys_config_dir, home_config_dir
129local sys_config_ok, home_config_ok = false, false 130local sys_config_ok, home_config_ok = false, false
130local extra_luarocks_module_dir 131local extra_luarocks_module_dir
131sys_config_dir = site_config.LUAROCKS_SYSCONFDIR 132sys_config_dir = site_config.LUAROCKS_SYSCONFDIR
132if detected.windows then 133if cfg.platform.windows then
133 cfg.home = os.getenv("APPDATA") or "c:" 134 cfg.home = os.getenv("APPDATA") or "c:"
134 sys_config_dir = sys_config_dir or "c:/luarocks" 135 sys_config_dir = sys_config_dir or "c:/luarocks"
135 home_config_dir = cfg.home.."/luarocks" 136 home_config_dir = cfg.home.."/luarocks"
@@ -141,16 +142,13 @@ else
141 cfg.home_tree = (os.getenv("USER") ~= "root") and cfg.home.."/.luarocks/" 142 cfg.home_tree = (os.getenv("USER") ~= "root") and cfg.home.."/.luarocks/"
142end 143end
143 144
144cfg.variables = {}
145cfg.rocks_trees = {}
146
147-- Create global environment for the config files; 145-- Create global environment for the config files;
148local env_for_config_file = function() 146local env_for_config_file = function()
149 local e 147 local e
150 e = { 148 e = {
151 home = cfg.home, 149 home = cfg.home,
152 lua_version = cfg.lua_version, 150 lua_version = cfg.lua_version,
153 platform = util.make_shallow_copy(detected), 151 platform = util.make_shallow_copy(cfg.platform),
154 processor = cfg.target_cpu, -- remains for compat reasons 152 processor = cfg.target_cpu, -- remains for compat reasons
155 target_cpu = cfg.target_cpu, -- replaces `processor` 153 target_cpu = cfg.target_cpu, -- replaces `processor`
156 os_getenv = os.getenv, 154 os_getenv = os.getenv,
@@ -328,7 +326,7 @@ local defaults = {
328 rocks_provided = {} 326 rocks_provided = {}
329} 327}
330 328
331if detected.windows then 329if cfg.platform.windows then
332 local full_prefix = (site_config.LUAROCKS_PREFIX or (os.getenv("PROGRAMFILES")..[[\LuaRocks]])).."\\"..cfg.major_version 330 local full_prefix = (site_config.LUAROCKS_PREFIX or (os.getenv("PROGRAMFILES")..[[\LuaRocks]])).."\\"..cfg.major_version
333 extra_luarocks_module_dir = full_prefix.."\\lua\\?.lua" 331 extra_luarocks_module_dir = full_prefix.."\\lua\\?.lua"
334 332
@@ -388,7 +386,7 @@ if detected.windows then
388 defaults.web_browser = "start" 386 defaults.web_browser = "start"
389end 387end
390 388
391if detected.mingw32 then 389if cfg.platform.mingw32 then
392 defaults.platforms = { "win32", "mingw32", "windows" } 390 defaults.platforms = { "win32", "mingw32", "windows" }
393 defaults.obj_extension = "o" 391 defaults.obj_extension = "o"
394 defaults.cmake_generator = "MinGW Makefiles" 392 defaults.cmake_generator = "MinGW Makefiles"
@@ -413,7 +411,7 @@ if detected.mingw32 then
413 411
414end 412end
415 413
416if detected.unix then 414if cfg.platform.unix then
417 defaults.lib_extension = "so" 415 defaults.lib_extension = "so"
418 defaults.external_lib_extension = "so" 416 defaults.external_lib_extension = "so"
419 defaults.obj_extension = "o" 417 defaults.obj_extension = "o"
@@ -450,7 +448,7 @@ if detected.unix then
450 defaults.web_browser = "xdg-open" 448 defaults.web_browser = "xdg-open"
451end 449end
452 450
453if detected.cygwin then 451if cfg.platform.cygwin then
454 defaults.lib_extension = "so" -- can be overridden in the config file for mingw builds 452 defaults.lib_extension = "so" -- can be overridden in the config file for mingw builds
455 defaults.arch = "cygwin-"..cfg.target_cpu 453 defaults.arch = "cygwin-"..cfg.target_cpu
456 defaults.platforms = {"unix", "cygwin"} 454 defaults.platforms = {"unix", "cygwin"}
@@ -460,12 +458,12 @@ if detected.cygwin then
460 defaults.variables.LIBFLAG = "-shared" 458 defaults.variables.LIBFLAG = "-shared"
461end 459end
462 460
463if detected.bsd then 461if cfg.platform.bsd then
464 defaults.variables.MAKE = "gmake" 462 defaults.variables.MAKE = "gmake"
465 defaults.variables.STATFLAG = "-f '%OLp'" 463 defaults.variables.STATFLAG = "-f '%OLp'"
466end 464end
467 465
468if detected.macosx then 466if cfg.platform.macosx then
469 defaults.variables.MAKE = "make" 467 defaults.variables.MAKE = "make"
470 defaults.external_lib_extension = "dylib" 468 defaults.external_lib_extension = "dylib"
471 defaults.arch = "macosx-"..cfg.target_cpu 469 defaults.arch = "macosx-"..cfg.target_cpu
@@ -487,12 +485,12 @@ if detected.macosx then
487 defaults.web_browser = "open" 485 defaults.web_browser = "open"
488end 486end
489 487
490if detected.linux then 488if cfg.platform.linux then
491 defaults.arch = "linux-"..cfg.target_cpu 489 defaults.arch = "linux-"..cfg.target_cpu
492 defaults.platforms = {"unix", "linux"} 490 defaults.platforms = {"unix", "linux"}
493end 491end
494 492
495if detected.freebsd then 493if cfg.platform.freebsd then
496 defaults.arch = "freebsd-"..cfg.target_cpu 494 defaults.arch = "freebsd-"..cfg.target_cpu
497 defaults.platforms = {"unix", "bsd", "freebsd"} 495 defaults.platforms = {"unix", "bsd", "freebsd"}
498 defaults.gcc_rpath = false 496 defaults.gcc_rpath = false
@@ -500,17 +498,17 @@ if detected.freebsd then
500 defaults.variables.LD = "cc" 498 defaults.variables.LD = "cc"
501end 499end
502 500
503if detected.openbsd then 501if cfg.platform.openbsd then
504 defaults.arch = "openbsd-"..cfg.target_cpu 502 defaults.arch = "openbsd-"..cfg.target_cpu
505 defaults.platforms = {"unix", "bsd", "openbsd"} 503 defaults.platforms = {"unix", "bsd", "openbsd"}
506end 504end
507 505
508if detected.netbsd then 506if cfg.platform.netbsd then
509 defaults.arch = "netbsd-"..cfg.target_cpu 507 defaults.arch = "netbsd-"..cfg.target_cpu
510 defaults.platforms = {"unix", "bsd", "netbsd"} 508 defaults.platforms = {"unix", "bsd", "netbsd"}
511end 509end
512 510
513if detected.solaris then 511if cfg.platform.solaris then
514 defaults.arch = "solaris-"..cfg.target_cpu 512 defaults.arch = "solaris-"..cfg.target_cpu
515 defaults.platforms = {"unix", "solaris"} 513 defaults.platforms = {"unix", "solaris"}
516 defaults.variables.MAKE = "gmake" 514 defaults.variables.MAKE = "gmake"