Skip to content

Commit 43708c4

Browse files
committed
Fixed find_make
Added Checking for make and gmake on All Platforms Added Checking for mozmake on Windows
1 parent 0e67a76 commit 43708c4

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

mozjs/build.rs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,36 @@ fn main() {
8383
}
8484
}
8585

86-
fn find_make() -> OsString {
87-
if let Some(make) = env::var_os("MAKE") {
88-
make
89-
} else {
90-
match Command::new("gmake").status() {
91-
Ok(gmake) => {
92-
if gmake.success() {
93-
OsStr::new("gmake").to_os_string()
86+
fn find_make() -> Option<OsString> {
87+
fn check_make(name: &OsStr) -> bool {
88+
let mut cmd = Command::new(name);
89+
cmd.arg("--version");
90+
cmd.status().map(|status| status.success()).unwrap_or(false)
91+
}
92+
93+
env::var_os("MAKE").or_else(|| {
94+
let gmake = OsString::from("gmake");
95+
let make = OsString::from("make");
96+
if check_make(&gmake) {
97+
Some(gmake)
98+
} else if check_make(&make) {
99+
Some(make)
100+
} else {
101+
#[cfg(windows)]
102+
{
103+
let mozmake = OsString::from("mozmake");
104+
if check_make(&mozmake) {
105+
Some(mozmake)
94106
} else {
95-
OsStr::new("make").to_os_string()
107+
None
96108
}
97109
}
98-
Err(_) => OsStr::new("make").to_os_string(),
110+
#[cfg(unix)]
111+
{
112+
None
113+
}
99114
}
100-
}
115+
})
101116
}
102117

103118
#[cfg(windows)]
@@ -206,15 +221,18 @@ fn build_jsapi(build_dir: &Path) {
206221
let new_path = env::join_paths(paths).unwrap();
207222
env::set_var("PATH", &new_path);
208223

209-
// Install mozmake if not installed
210-
if !mozbuild_dir.join("MOZMAKE_LOCK").exists() {
211-
install_mozmake(&mozbuild_dir);
212-
}
224+
if make.is_none() {
225+
// Install mozmake if not installed
226+
if !mozbuild_dir.join("MOZMAKE_LOCK").exists() {
227+
install_mozmake(&mozbuild_dir);
228+
}
213229

214-
make = OsString::from("mozmake");
230+
make = Some(OsString::from("mozmake"));
231+
}
215232
}
216233
}
217234

235+
let make = make.expect("Install `make` or `gmake`");
218236
let mut cmd = Command::new(make);
219237

220238
let encoding_c_mem_include_dir = env::var("DEP_ENCODING_C_MEM_INCLUDE_DIR").unwrap();

0 commit comments

Comments
 (0)