summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-06-11 23:26:21 +0300
committerAndrei Karas <akaras@inbox.ru>2016-06-11 23:26:21 +0300
commit9dabaf6c1722a3ca1e0d42ae495cdeacc1718090 (patch)
treefa50055530c0d030c52bce5f08e73fbb1562954a
parentd180fdd36b29e02c378390d916e1f9b5bbcb269f (diff)
downloaddeheader-9dabaf6c1722a3ca1e0d42ae495cdeacc1718090.tar.gz
deheader-9dabaf6c1722a3ca1e0d42ae495cdeacc1718090.tar.bz2
deheader-9dabaf6c1722a3ca1e0d42ae495cdeacc1718090.tar.xz
deheader-9dabaf6c1722a3ca1e0d42ae495cdeacc1718090.zip
Add --defines/-d flag for set compiler defines.
-rwxr-xr-xdeheader25
1 files changed, 14 insertions, 11 deletions
diff --git a/deheader b/deheader
index 3b0eaac..6166c57 100755
--- a/deheader
+++ b/deheader
@@ -1361,11 +1361,11 @@ def trim(line):
else:
return repr(line)
-def testcompile(source, compiler, maker, msg="", verbosity=0, showerrs=False, subdir=""):
+def testcompile(source, compiler, defines, 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} {1} -o {2} {3}".format(compiler, maker, tmpname, source)
+ command = "{0} {1} {2} -o {3} {4}".format(compiler, defines, maker, tmpname, source)
olddir = os.getcwd()
if len(subdir) > 0:
os.chdir(subdir)
@@ -1385,7 +1385,7 @@ def testcompile(source, compiler, maker, msg="", verbosity=0, showerrs=False, su
print("deheader: %s%s %s." % (source, msg, explain))
return (status, end - start)
-def c_analyze(sourcefile, compiler, maker, includes, requires, verbosity, subdir=""):
+def c_analyze(sourcefile, compiler, defines, 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, compiler, maker, includes, requires, verbosity, subdir
retain += 1
if not retain:
saveit.remove_headers(unneeded + [header])
- (st, _t) = testcompile(sourcefile, compiler, maker, " without %s" % trim(header), verbosity, showerrs=False, subdir=subdir)
+ (st, _t) = testcompile(sourcefile, compiler, defines, 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, compiler, 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, compiler, maker, includes, requires, remove, verbose):
+def deheader(sourcefile, compiler, defines, 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, compiler, maker, verbosity=max(1, verbose), showerrs=False)
+ (st, _t) = testcompile(sourcefile, compiler, defines, maker, verbosity=max(1, verbose), showerrs=False)
if st != 0:
subdir = os.path.dirname(sourcefile)
sourcefile = os.path.basename(sourcefile)
- (st, _t) = testcompile(sourcefile, compiler, maker, verbosity=max(1, verbose), showerrs=True, subdir=subdir)
+ (st, _t) = testcompile(sourcefile, compiler, defines, 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, compiler, maker,
+ unneeded = c_analyze(sourcefile, compiler, defines, maker,
includes[:], requires, verbose, subdir=subdir)
if unneeded:
for line in unneeded:
@@ -1474,17 +1474,18 @@ 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:c:",
+ (options, arguments) = getopt.getopt(sys.argv[1:], "hi:m:qrvx:V:c:d:",
["help", "ignore",
"maker", "quiet",
"remove", "verbose",
"exclude", "version",
- "compiler"])
+ "compiler", "defines"])
maker = "make"
verbose = 0
quiet = False
remove = False
compiler = "g++"
+ defines = ""
ignores = []
exclusions = []
for (switch, val) in options:
@@ -1508,6 +1509,8 @@ if __name__ == "__main__":
exclusions.append(val)
elif switch in ('-c', '--compiler'):
compiler = val
+ elif switch in ('-d', '--defines'):
+ defines = val
if not ignores:
ignore = None
else:
@@ -1522,7 +1525,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, compiler, maker,
+ summaries.append(deheader(sourcefile, compiler, defines, maker,
inclusion_map.depends_on[sourcefile],
inclusion_map.requires[sourcefile],
remove, verbose))