-def extract_cflags(shcmd):
- cflags = shlex.split(shcmd)
- return [x for x in cflags
- if x.startswith('-D') or x.startswith('-I') or x.startswith('-W')
- or x.startswith('-std=')]
+def cmdline_for_sparse(sparse, cmdline):
+ # Do not include the C compiler executable
+ skip = True
+ arg = False
+ out = sparse + ['-no-compile']
+ for x in cmdline:
+ if arg:
+ out.append(x)
+ arg = False
+ continue
+ if skip:
+ skip = False
+ continue
+ # prevent sparse from treating output files as inputs
+ if x == '-MF' or x == '-MQ' or x == '-o':
+ skip = True
+ continue
+ # cgcc ignores -no-compile if it sees -M or -MM?
+ if x.startswith('-M'):
+ continue
+ # sparse does not understand these!
+ if x == '-iquote' or x == '-isystem':
+ x = '-I'
+ if x == '-I':
+ arg = True
+ out.append(x)
+ return out