summaryrefslogtreecommitdiff
path: root/python/makefile.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/makefile.py')
-rw-r--r--python/makefile.py34
1 files changed, 28 insertions, 6 deletions
diff --git a/python/makefile.py b/python/makefile.py
index 9af397d373..948d3f7391 100644
--- a/python/makefile.py
+++ b/python/makefile.py
@@ -11,6 +11,7 @@ import subprocess
import re
import argparse
from string import Template
+from makevars import MakeReVars
argp = argparse.ArgumentParser(description = 'FRR Makefile extensions')
argp.add_argument('--dev-build', action = 'store_const', const = True,
@@ -20,13 +21,9 @@ args = argp.parse_args()
with open('Makefile', 'r') as fd:
before = fd.read()
-nolinecont = before.replace('\\\n', '')
-m = re.search('^clippy_scan\s*=([^#]*)(?:#.*)?$', nolinecont, flags=re.MULTILINE)
-if m is None:
- sys.stderr.write('failed to parse Makefile.in\n')
- sys.exit(2)
+mv = MakeReVars(before)
-clippy_scan = m.group(1).strip().split()
+clippy_scan = mv['clippy_scan'].strip().split()
for clippy_file in clippy_scan:
assert clippy_file.endswith('.c')
@@ -57,6 +54,7 @@ ${target}: ${clippybase}_clippy.c
lines = before.splitlines()
autoderp = '#AUTODERP# '
out_lines = []
+bcdeps = []
make_rule_re = re.compile('^([^:\s]+):\s*([^:\s]+)\s*($|\n)')
while lines:
@@ -80,6 +78,12 @@ while lines:
out_lines.append(line)
continue
+ target, dep = m.group(1), m.group(2)
+
+ if target.endswith('.lo') or target.endswith('.o'):
+ if not dep.endswith('.h'):
+ bcdeps.append('%s.bc: %s' % (target, target))
+ bcdeps.append('\t$(AM_V_LLVM_BC)$(COMPILE) -emit-llvm -c -o $@ %s' % (dep))
if m.group(2) in clippy_scan:
out_lines.append(clippyauxdep.substitute(target=m.group(1), clippybase=m.group(2)[:-2]))
@@ -88,6 +92,24 @@ while lines:
out_lines.append('# clippy{\n# main clippy targets')
for clippy_file in clippy_scan:
out_lines.append(clippydep.substitute(clippybase = clippy_file[:-2]))
+
+out_lines.append('')
+out_lines.extend(bcdeps)
+out_lines.append('')
+bc_targets = []
+for varname in ['bin_PROGRAMS', 'sbin_PROGRAMS', 'lib_LTLIBRARIES', 'module_LTLIBRARIES', 'noinst_LIBRARIES']:
+ bc_targets.extend(mv[varname].strip().split())
+for target in bc_targets:
+ amtgt = target.replace('/', '_').replace('.', '_').replace('-', '_')
+ objs = mv[amtgt + '_OBJECTS'].strip().split()
+ objs = [obj + '.bc' for obj in objs]
+ deps = mv.get(amtgt + '_DEPENDENCIES', '').strip().split()
+ deps = [d + '.bc' for d in deps if d.endswith('.a')]
+ objs.extend(deps)
+ out_lines.append('%s.bc: %s' % (target, ' '.join(objs)))
+ out_lines.append('\t$(AM_V_LLVM_LD)$(LLVM_LINK) -o $@ $^')
+ out_lines.append('')
+
out_lines.append('# }clippy')
out_lines.append('')