I'm writing a python script that acts as a wrapper for GCC. Most of the options that GCC takes are straightforward to handle with argparse but I'm struggling with the "-Wl,option" option. I want it to store everything after the comma so I tried the following:
parser = argparse.ArgumentParser()
parser.add_argument("-Wl,", help="Option to pass to linker.")
known, unknown = parser.parse_known_args()
print(known)
print(unknown)
However, if I run the script as follows:
python foo.py -Wl,foo
I get the following output:
Namespace(E=False, S=False, Wl,=None, c=False, optimization=None, shared=False, target=None)
['-Wl,foo']
which indicates that it didn't recognize the -Wl option.
I could change the add_argument line to read:
parser.add_argument("-W", help="Option to pass to linker.")
This works, storing "l,foo" in the W option, but GCC uses -W for warning flags and I want to keep those separated from the -Wl options.
I could run through the list of unknown args and handle them that way but I was hoping there was a more elegant solution to the problem. Any tips?