diff options
-rw-r--r-- | src/luarocks/cfg.lua | 92 |
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 | |||
35 | cfg.program_version = "scm" | 35 | cfg.program_version = "scm" |
36 | cfg.program_series = "2.2" | 36 | cfg.program_series = "2.2" |
37 | cfg.major_version = (cfg.program_version:match("([^.]%.[^.])")) or cfg.program_series | 37 | cfg.major_version = (cfg.program_version:match("([^.]%.[^.])")) or cfg.program_series |
38 | cfg.variables = {} | ||
39 | cfg.rocks_trees = {} | ||
40 | cfg.platform = {} | ||
38 | 41 | ||
39 | local persist = require("luarocks.persist") | 42 | local persist = require("luarocks.persist") |
40 | 43 | ||
@@ -68,57 +71,55 @@ end | |||
68 | 71 | ||
69 | -- System detection: | 72 | -- System detection: |
70 | 73 | ||
71 | local detected = {} | ||
72 | local 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). |
79 | system = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l") | 79 | local system = site_config.LUAROCKS_UNAME_S or io.popen("uname -s"):read("*l") |
80 | proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l") | 80 | local proc = site_config.LUAROCKS_UNAME_M or io.popen("uname -m"):read("*l") |
81 | if proc:match("i[%d]86") then | 81 | if proc:match("i[%d]86") then |
82 | proc = "x86" | 82 | cfg.target_cpu = "x86" |
83 | elseif proc:match("amd64") or proc:match("x86_64") then | 83 | elseif proc:match("amd64") or proc:match("x86_64") then |
84 | proc = "x86_64" | 84 | cfg.target_cpu = "x86_64" |
85 | elseif proc:match("Power Macintosh") then | 85 | elseif proc:match("Power Macintosh") then |
86 | proc = "powerpc" | 86 | cfg.target_cpu = "powerpc" |
87 | else | ||
88 | cfg.target_cpu = proc | ||
87 | end | 89 | end |
88 | cfg.target_cpu = proc | ||
89 | 90 | ||
90 | if system == "FreeBSD" then | 91 | if 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 |
94 | elseif system == "OpenBSD" then | 95 | elseif 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 |
98 | elseif system == "NetBSD" then | 99 | elseif 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 |
102 | elseif system == "Darwin" then | 103 | elseif 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 |
106 | elseif system == "Linux" then | 107 | elseif system == "Linux" then |
107 | detected.unix = true | 108 | cfg.platform.unix = true |
108 | detected.linux = true | 109 | cfg.platform.linux = true |
109 | elseif system == "SunOS" then | 110 | elseif system == "SunOS" then |
110 | detected.unix = true | 111 | cfg.platform.unix = true |
111 | detected.solaris = true | 112 | cfg.platform.solaris = true |
112 | elseif system and system:match("^CYGWIN") then | 113 | elseif system and system:match("^CYGWIN") then |
113 | detected.unix = true | 114 | cfg.platform.unix = true |
114 | detected.cygwin = true | 115 | cfg.platform.cygwin = true |
115 | elseif system and system:match("^Windows") then | 116 | elseif system and system:match("^Windows") then |
116 | detected.windows = true | 117 | cfg.platform.windows = true |
117 | elseif system and system:match("^MINGW") then | 118 | elseif system and system:match("^MINGW") then |
118 | detected.windows = true | 119 | cfg.platform.windows = true |
119 | detected.mingw32 = true | 120 | cfg.platform.mingw32 = true |
120 | else | 121 | else |
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. |
123 | end | 124 | end |
124 | 125 | ||
@@ -129,7 +130,7 @@ local sys_config_dir, home_config_dir | |||
129 | local sys_config_ok, home_config_ok = false, false | 130 | local sys_config_ok, home_config_ok = false, false |
130 | local extra_luarocks_module_dir | 131 | local extra_luarocks_module_dir |
131 | sys_config_dir = site_config.LUAROCKS_SYSCONFDIR | 132 | sys_config_dir = site_config.LUAROCKS_SYSCONFDIR |
132 | if detected.windows then | 133 | if 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/" |
142 | end | 143 | end |
143 | 144 | ||
144 | cfg.variables = {} | ||
145 | cfg.rocks_trees = {} | ||
146 | |||
147 | -- Create global environment for the config files; | 145 | -- Create global environment for the config files; |
148 | local env_for_config_file = function() | 146 | local 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 | ||
331 | if detected.windows then | 329 | if 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" |
389 | end | 387 | end |
390 | 388 | ||
391 | if detected.mingw32 then | 389 | if 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 | ||
414 | end | 412 | end |
415 | 413 | ||
416 | if detected.unix then | 414 | if 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" |
451 | end | 449 | end |
452 | 450 | ||
453 | if detected.cygwin then | 451 | if 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" |
461 | end | 459 | end |
462 | 460 | ||
463 | if detected.bsd then | 461 | if 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'" |
466 | end | 464 | end |
467 | 465 | ||
468 | if detected.macosx then | 466 | if 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" |
488 | end | 486 | end |
489 | 487 | ||
490 | if detected.linux then | 488 | if 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"} |
493 | end | 491 | end |
494 | 492 | ||
495 | if detected.freebsd then | 493 | if 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" |
501 | end | 499 | end |
502 | 500 | ||
503 | if detected.openbsd then | 501 | if 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"} |
506 | end | 504 | end |
507 | 505 | ||
508 | if detected.netbsd then | 506 | if 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"} |
511 | end | 509 | end |
512 | 510 | ||
513 | if detected.solaris then | 511 | if 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" |