summaryrefslogtreecommitdiff
path: root/deheader
diff options
context:
space:
mode:
Diffstat (limited to 'deheader')
-rwxr-xr-xdeheader26
1 files changed, 15 insertions, 11 deletions
diff --git a/deheader b/deheader
index d9119ba..3b0eaac 100755
--- a/deheader
+++ b/deheader
@@ -1361,11 +1361,11 @@ def trim(line):
else:
return repr(line)
-def testcompile(source, maker, msg="", verbosity=0, showerrs=False, subdir=""):
+def testcompile(source, compiler, maker, msg="", verbosity=0, showerrs=False, subdir=""):
"Test-compile a sourcefile. Return the status and the compilation time"
(stem, _suffix) = os.path.splitext(source)
tmpname = stem + ".o"
- command = "{0} -o {1} {2}".format(maker, tmpname, source)
+ command = "{0} {1} -o {2} {3}".format(compiler, maker, tmpname, source)
olddir = os.getcwd()
if len(subdir) > 0:
os.chdir(subdir)
@@ -1385,7 +1385,7 @@ def testcompile(source, maker, msg="", verbosity=0, showerrs=False, subdir=""):
print("deheader: %s%s %s." % (source, msg, explain))
return (status, end - start)
-def c_analyze(sourcefile, maker, includes, requires, verbosity, subdir=""):
+def c_analyze(sourcefile, compiler, maker, includes, requires, verbosity, subdir=""):
"Given a C file and a list of includes, return those that can be omitted."
# We'll remove headers in reverse order, because later unnecessary
# headers might depend on earlier ones
@@ -1409,7 +1409,7 @@ def c_analyze(sourcefile, maker, includes, requires, verbosity, subdir=""):
retain += 1
if not retain:
saveit.remove_headers(unneeded + [header])
- (st, _t) = testcompile(sourcefile, maker, " without %s" % trim(header), verbosity, showerrs=False, subdir=subdir)
+ (st, _t) = testcompile(sourcefile, compiler, maker, " without %s" % trim(header), verbosity, showerrs=False, subdir=subdir)
if st == 0:
unneeded.append(header)
includes.remove(header)
@@ -1428,19 +1428,19 @@ def c_analyze(sourcefile, maker, includes, requires, verbosity, subdir=""):
print("deheader: in %s, %s portability requires %s." % (os.path.join(subdir, sourcefile), trigger, ",".join(requirement)))
return unneeded
-def deheader(sourcefile, maker, includes, requires, remove, verbose):
+def deheader(sourcefile, compiler, maker, includes, requires, remove, verbose):
# Sanity check against broken sourcefiles; we want this to
# complain visibly if the sourcefile won't build at all.
subdir = ""
- (st, _t) = testcompile(sourcefile, maker, verbosity=max(1, verbose), showerrs=False)
+ (st, _t) = testcompile(sourcefile, compiler, maker, verbosity=max(1, verbose), showerrs=False)
if st != 0:
subdir = os.path.dirname(sourcefile)
sourcefile = os.path.basename(sourcefile)
- (st, _t) = testcompile(sourcefile, maker, verbosity=max(1, verbose), showerrs=True, subdir=subdir)
+ (st, _t) = testcompile(sourcefile, compiler, maker, verbosity=max(1, verbose), showerrs=True, subdir=subdir)
if st == 0:
# Now do the analysis
if sourcefile.endswith(".c") or sourcefile.endswith(".cpp") or sourcefile.endswith(".cc") or sourcefile.endswith(".h"):
- unneeded = c_analyze(sourcefile, maker,
+ unneeded = c_analyze(sourcefile, compiler, maker,
includes[:], requires, verbose, subdir=subdir)
if unneeded:
for line in unneeded:
@@ -1474,15 +1474,17 @@ class Summary:
(len(self.filenames), len(self.includes), len(self.unneeded))
if __name__ == "__main__":
- (options, arguments) = getopt.getopt(sys.argv[1:], "hi:m:qrvx:V",
+ (options, arguments) = getopt.getopt(sys.argv[1:], "hi:m:qrvx:V:c:",
["help", "ignore",
"maker", "quiet",
"remove", "verbose",
- "exclude", "version"])
+ "exclude", "version",
+ "compiler"])
maker = "make"
verbose = 0
quiet = False
remove = False
+ compiler = "g++"
ignores = []
exclusions = []
for (switch, val) in options:
@@ -1504,6 +1506,8 @@ if __name__ == "__main__":
raise SystemExit(0)
elif switch in ('-x', '--exclude'):
exclusions.append(val)
+ elif switch in ('-c', '--compiler'):
+ compiler = val
if not ignores:
ignore = None
else:
@@ -1518,7 +1522,7 @@ if __name__ == "__main__":
inclusion_map = InclusionMap(arguments, ignore, exclusions, verbose)
summaries = []
for sourcefile in sorted(inclusion_map.depends_on.keys()):
- summaries.append(deheader(sourcefile, maker,
+ summaries.append(deheader(sourcefile, compiler, maker,
inclusion_map.depends_on[sourcefile],
inclusion_map.requires[sourcefile],
remove, verbose))