More support
authorRobert Pengelly <robertapengelly@hotmail.com>
Mon, 24 Mar 2025 15:57:36 +0000 (15:57 +0000)
committerRobert Pengelly <robertapengelly@hotmail.com>
Mon, 24 Mar 2025 15:57:36 +0000 (15:57 +0000)
include/xmake/xmake.h
lib.c
read.c
variable.c
xmake.c

index 78c67be8c07a62765656e4b2995a08235ddae3e7..1c3db3faef60c5c01f544fe9722078b25c8773d2 100644 (file)
@@ -20,6 +20,9 @@ struct xmake_state {
     
     char *path;
     int quiet, no_print;
+    
+    int dry_run;
+    int ignore_errors;
 
 };
 
diff --git a/lib.c b/lib.c
index 32e53d97402e14f2a5bf7750e151e0dd16b101ea..c6d1bde45dadc45aaeeba3d69cad42e0e60d77fb 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -58,6 +58,24 @@ static int set_quiet (const char *arg) {
 
 }
 
+static int set_ignore_errors (const char *arg) {
+
+    (void) arg;
+    
+    state->ignore_errors = 1;
+    return 0;
+
+}
+
+static int set_dry_run (const char *arg) {
+
+    (void) arg;
+    
+    state->dry_run = 1;
+    return 0;
+
+}
+
 static int set_no_print (const char *arg) {
 
     (void) arg;
@@ -179,6 +197,14 @@ static struct option opts[] = {
     {   "--file=",                  &add_makefile           },
     {   "-f:",                      &add_makefile           },
     
+    {   "--ignore-errors",          &set_ignore_errors      },
+    {   "-i",                       &set_ignore_errors      },
+    
+    {   "--dry_run",                &set_dry_run            },
+    {   "-n",                       &set_dry_run            },
+    
+    
+    
     {   0,                          &non_option             }
 
 };
diff --git a/read.c b/read.c
index 0ebc8dcf4a1b12b439daf347b2a5a25e33fc479f..0656805f25a6a34a046b0ecde5ba552b7ff4a020 100644 (file)
--- a/read.c
+++ b/read.c
@@ -837,7 +837,12 @@ int read_makefile (const char *filename) {
     char *new_value;
     int ret;
     
-    if (!(lbuf.f = fopen (filename, "r"))) {
+    if (strcmp (filename, "-") == 0) {
+    
+        filename = "<stdin>";
+        lbuf.f = stdin;
+    
+    } else if (!(lbuf.f = fopen (filename, "r"))) {
         return 1;
     }
     
@@ -867,9 +872,11 @@ int read_makefile (const char *filename) {
     }
     
     ret = read_lbuf (&lbuf, 1);
-    
     free (lbuf.start);
-    fclose (lbuf.f);
+    
+    if (lbuf.f != stdin) {
+        fclose (lbuf.f);
+    }
     
     return ret;
 
index af425676d17efd107ee9cd51d798685fa7b32935..b3912391bac13bef74f97aa21452ea801ca67563 100644 (file)
@@ -609,8 +609,11 @@ void parse_var_line (const char *filename, unsigned long line_no, char *line, en
     
     } else if (opt == VAR_SHELL) {
     
-        fprintf (stderr, "+++internal error: != not supported yet. Stop.\n");
-        exit (EXIT_FAILURE);
+        char *temp = xstrdup (new_value);
+        free (new_value);
+        
+        new_value = variable_expand_line (filename, line_no, func_shell (filename, line_no, temp));
+        free (temp);
     
     }
     
diff --git a/xmake.c b/xmake.c
index e029e2a4b1b89288bc73bc54329f1616a458ce6d..8b41c0c1157c089a080d9d37cd0c6e3ce0966a83 100644 (file)
--- a/xmake.c
+++ b/xmake.c
@@ -36,9 +36,12 @@ static int doing_inference_rule_commands = 0;
 
 static int rule_run_command (const char *filename, unsigned long line_no, const char *name, char *p, char *q) {
 
-    int is_quiet = state->quiet, is_ignoring_errors = 0;
     char *new_cmds, *s;
     
+    int is_ignoring_errors = state->ignore_errors;
+    int is_quiet = state->quiet;
+    int should_execute = !state->dry_run;
+    
     *q = '\0';
     
     new_cmds = xstrdup (p);
@@ -47,7 +50,7 @@ static int rule_run_command (const char *filename, unsigned long line_no, const
     new_cmds = variable_expand_line ("<command-line>", 1, new_cmds);
     s = new_cmds;
     
-    while (isspace ((int) *s) || *s == '-' || *s == '@') {
+    while (isspace ((int) *s) || *s == '-' || *s == '@' || *s == '+') {
     
         if (*s == '@') {
             is_quiet = 1;
@@ -57,6 +60,10 @@ static int rule_run_command (const char *filename, unsigned long line_no, const
             is_ignoring_errors = 1;
         }
         
+        if (*s == '+') {
+            should_execute = 1;
+        }
+        
         s++;
     
     }
@@ -65,7 +72,7 @@ static int rule_run_command (const char *filename, unsigned long line_no, const
         printf ("%s\n", new_cmds);
     }
     
-    /*if (!dry_run) */{
+    if (should_execute) {
     
         int error = system (s);
         
@@ -491,6 +498,12 @@ int main (int argc, char **argv) {
     variable_add (xstrdup ("OS"), xstrdup (os_name), VAR_ORIGIN_FILE);
     variable_add (xstrdup ("MAKE"), xstrdup (argv[0]), VAR_ORIGIN_FILE);
     
+#if     defined (_WIN32) || defined (__WIN32__)
+    variable_add (xstrdup ("SHELL"), xstrdup ("cmd.exe"), VAR_ORIGIN_FILE);
+#else
+    variable_add (xstrdup ("SHELL"), xstrdup ("sh.exe"), VAR_ORIGIN_FILE);
+#endif
+    
     state = xmalloc (sizeof (*state));
     parse_args (argv, argc);
     
@@ -553,21 +566,15 @@ int main (int argc, char **argv) {
     
     {
     
-        char *cwd, *path;
-        size_t len;
+        char *path, *cwd = get_current_directory ();
         
-        cwd = get_current_directory ();
-        len = strlen ("CURDIR") + 4 + strlen (cwd);
-        
-        path = xmalloc (len + 1);
+        path = xmalloc (strlen ("CURDIR") + 4 + strlen (cwd) + 1);
         sprintf (path, "CURDIR ?= %s", cwd);
         
         parse_var_line ("<command-line>", 1, path, VAR_ORIGIN_FILE);
         free (path);
         
-        len = strlen (".CURDIR") + 4 + strlen (cwd);
-        
-        path = xmalloc (len + 1);
+        path = xmalloc (strlen (".CURDIR") + 4 + strlen (cwd) + 1);
         sprintf (path, ".CURDIR ?= %s", cwd);
         
         parse_var_line ("<command-line>", 1, path, VAR_ORIGIN_FILE);