rmyorston / pdpmake

Public domain POSIX make
https://frippery.org/make
Other
107 stars 11 forks source link

Ignore unknown command line switches #43

Closed ghost closed 4 months ago

ghost commented 4 months ago

For example, --no-print-directory. Currently, it will abort with this error:

$ make -C make/windows
==== Building SOIL2-static (debug_x86_64) ====
make: unknown option -- -
Usage: make [--posix] [-C path] [-f makefile] [-j num] [-x pragma]
         [-ehiknpqrsSt] [macro[::[:]]=val ...] [target ...]

This build supports: non-POSIX extensions, POSIX 202X, POSIX 2017
In strict POSIX mode the 2017 standard is enforced by default.
make: (makefile:318): failed to build 'SOIL2-static' exit 2
ghost commented 4 months ago

@rmyorston Can you work on this first? Other issues are hard to debug.

rmyorston commented 4 months ago

I'm not sure I want to work on this. Detecting (and not ignoring) unknown options seems like the right thing to do.

ghost commented 4 months ago

I'm not sure I want to work on this. Detecting (and not ignoring) unknown options seems like the right thing to do.

Please do anything you think that is right. I only want to be able to proceed with building eepp.

ghost commented 4 months ago

It seems pdpmake doesn't support GNU style of long options. What about ignoring anything started with --?

rmyorston commented 4 months ago

Here's a patch to ignore options starting with --. It's a non-POSIX extension, so in POSIX mode long options still result in an error. Everything after the first -- isn't treated as an option.

diff --git a/main.c b/main.c
index 0e6e3b7..370587b 100644
--- a/main.c
+++ b/main.c
@@ -463,6 +463,23 @@ main(int argc, char **argv)
    } else {
        posix = getenv("PDPMAKE_POSIXLY_CORRECT") != NULL;
    }
+
+   if (!posix) {
+       int i, j, saw_double_dash = FALSE;
+
+       // As an extension silently ignore options with leading '--'
+       for (i = j = 0; argv[i]; ++i) {
+           if (!saw_double_dash && strncmp(argv[i], "--", 2) == 0) {
+               if (argv[i][2] == '\0')
+                   saw_double_dash = TRUE;
+               else
+                   continue;
+           }
+           argv[j++] = argv[i];
+       }
+       argv[j] = NULL;
+       argc = j;
+   }
 #endif

 #if ENABLE_FEATURE_MAKE_POSIX_202X

However, many long options take an argument. So make --jobs 4 becomes make 4, not at all what was intended.

ghost commented 4 months ago

However, many long options take an argument. So make --jobs 4 becomes make 4, not at all what was intended.

I didn't think about that. What about trying to map long options to the existing options and ignore the ones that currently don't have anything equivalent? This is more involved but is also more flexible, I think.

ghost commented 4 months ago

@rmyorston Please ignore --no-print-directory as I don't see any existing equivalent option.

rmyorston commented 4 months ago

I'm not very keen on the idea of adding code to pdpmake to process GNU make long options.

Having it reject all long options is just about acceptable, though as we've seen it doesn't work in practice. Having it understand GNU make long options is a step too far.

ghost commented 4 months ago

Having it reject all long options is just about acceptable, though as we've seen it doesn't work in practice.

However, many long options take an argument. So make --jobs 4 becomes make 4, not at all what was intended.

You can ignore anything after a long option that isn't a short option (doesn't start with a single -).

agvxov commented 4 months ago

rmyorston is right, it does not make sense to ignore unsupported flags. there are reasons why you dont see serious applications doing that (e.g busybox). imagine someone passing a long option, expecting GNU behaviour then pulling their hair out, unable to find what is wrong with their command because clearly pdpmake "accepted" it; or alternatively breaking scripts without warning; etc...

rmyorston commented 4 months ago

You can ignore anything after a long option that isn't a short option

No, that won't work. There are cases where a long option can take an argument starting with a single dash: make --file -Makefile or make --eval '-include file'.

(I didn't say they were sensible cases ;-)

ale5000-git commented 4 months ago

@rmyorston

Just an idea of a possible way:

Add a small list of commonly used long options with one parameter, like as it was done inside mixed_case_special_name: const char *names = "PATH=\0""COMSPEC=\0""PROGRAMDATA=\0"; For the ones inside the list ignore them with the parameter instead for all others ignore them without parameters.

But the most improtant thing is to emit a warning for every ignored parameter.