Add feature test for Makefile pattern rules
diff --git a/src/Charmonizer/Core/Make.c b/src/Charmonizer/Core/Make.c
index 3240ff5..9c4722b 100644
--- a/src/Charmonizer/Core/Make.c
+++ b/src/Charmonizer/Core/Make.c
@@ -79,9 +79,10 @@
static struct {
char *make_command;
int shell_type;
+ int supports_pattern_rules;
} chaz_Make = {
NULL,
- 0
+ 0, 0
};
/* Detect make command.
@@ -207,7 +208,12 @@
va_list args;
const char *candidate;
int found = 0;
- const char makefile_content[] = "foo:\n\t@echo 643490c943525d19\n";
+ const char makefile_content[] =
+ "foo:\n"
+ "\t@echo 643490c943525d19\n"
+ "\n"
+ "%.ext:\n"
+ "\t@echo 8f4ef20576b070d5\n";
chaz_Util_write_file("_charm_Makefile", makefile_content);
/* Audition candidates. */
@@ -239,12 +245,28 @@
free(content);
}
chaz_Util_remove_and_verify("_charm_foo");
+ free(command);
if (succeeded) {
chaz_Make.make_command = chaz_Util_strdup(make);
+
+ command = chaz_Util_join(" ", make, "-f", "_charm_Makefile", "foo.ext",
+ NULL);
+ chaz_OS_run_redirected(command, "_charm_foo");
+ if (chaz_Util_can_open_file("_charm_foo")) {
+ size_t len;
+ char *content = chaz_Util_slurp_file("_charm_foo", &len);
+ if (content != NULL
+ && strstr(content, "8f4ef20576b070d5") != NULL
+ ) {
+ chaz_Make.supports_pattern_rules = 1;
+ }
+ free(content);
+ }
+ chaz_Util_remove_and_verify("_charm_foo");
+ free(command);
}
- free(command);
return succeeded;
}
@@ -698,11 +720,12 @@
/* Write rules to compile with custom flags. */
if (cflags[0] != '\0') {
- if (chaz_Make.shell_type == CHAZ_OS_CMD_EXE) {
- /* Write a rule for each object file. This is needed for nmake
- * which doesn't support pattern rules but also for mingw32-make
- * which has problems with pattern rules and backslash directory
- * separators.
+ if (!chaz_Make.supports_pattern_rules
+ || chaz_Make.shell_type == CHAZ_OS_CMD_EXE) {
+ /* Write a rule for each object file. This is needed for make
+ * utilities that don't support pattern rules but also for
+ * mingw32-make which has problems with pattern rules and
+ * backslash directory separators.
*/
S_chaz_MakeFile_write_object_rules(binary->sources, cflags, out);
}