]>
git.proxmox.com Git - mirror_frr.git/blob - python/makefile.py
3 # FRR extended automake/Makefile functionality helper
5 # This script is executed on/after generating Makefile to add some pieces for
13 from string
import Template
14 from makevars
import MakeReVars
16 argp
= argparse
.ArgumentParser(description
= 'FRR Makefile extensions')
17 argp
.add_argument('--dev-build', action
= 'store_const', const
= True,
18 help = 'run additional developer checks')
19 args
= argp
.parse_args()
21 with
open('Makefile', 'r') as fd
:
24 mv
= MakeReVars(before
)
26 clippy_scan
= mv
['clippy_scan'].strip().split()
27 for clippy_file
in clippy_scan
:
28 assert clippy_file
.endswith('.c')
30 # check for files using clippy but not listed in clippy_scan
32 basepath
= os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
)))
33 if os
.path
.exists(os
.path
.join(basepath
, '.git')):
34 clippy_ref
= subprocess
.check_output([
35 'git', '-C', basepath
, 'grep', '-l', '-P', '^#\s*include.*_clippy.c', '--', '**.c']).decode('US-ASCII')
37 clippy_ref
= set(clippy_ref
.splitlines())
38 missing
= clippy_ref
- set(clippy_scan
)
41 sys
.stderr
.write('error: files seem to be using clippy, but not listed in "clippy_scan" in subdir.am:\n\t%s\n' % ('\n\t'.join(sorted(missing
))))
44 clippydep
= Template('''
45 ${clippybase}.$$(OBJEXT): ${clippybase}_clippy.c
46 ${clippybase}.lo: ${clippybase}_clippy.c
47 ${clippybase}_clippy.c: $$(CLIPPY_DEPS)''')
49 clippyauxdep
= Template('''# clippy{
50 # auxiliary clippy target
51 ${target}: ${clippybase}_clippy.c
54 lines
= before
.splitlines()
55 autoderp
= '#AUTODERP# '
58 make_rule_re
= re
.compile('^([^:\s]+):\s*([^:\s]+)\s*($|\n)')
62 if line
.startswith(autoderp
):
63 line
= line
[len(autoderp
):]
65 if line
== '# clippy{':
68 if line
== '# }clippy':
72 if line
.startswith('#'):
73 out_lines
.append(line
)
78 while full_line
.endswith('\\'):
79 full_line
= full_line
[:-1] + full_lines
.pop(0)
81 m
= make_rule_re
.match(full_line
)
83 out_lines
.append(line
)
86 line
, lines
= full_line
, full_lines
88 target
, dep
= m
.group(1), m
.group(2)
90 if target
.endswith('.lo') or target
.endswith('.o'):
91 if not dep
.endswith('.h'):
92 bcdeps
.append('%s.bc: %s' % (target
, target
))
93 bcdeps
.append('\t$(AM_V_LLVM_BC)$(COMPILE) -emit-llvm -c -o $@ %s' % (dep
))
94 if m
.group(2) in clippy_scan
:
95 out_lines
.append(clippyauxdep
.substitute(target
=m
.group(1), clippybase
=m
.group(2)[:-2]))
97 out_lines
.append(line
)
99 out_lines
.append('# clippy{\n# main clippy targets')
100 for clippy_file
in clippy_scan
:
101 out_lines
.append(clippydep
.substitute(clippybase
= clippy_file
[:-2]))
104 out_lines
.extend(bcdeps
)
107 for varname
in ['bin_PROGRAMS', 'sbin_PROGRAMS', 'lib_LTLIBRARIES', 'module_LTLIBRARIES', 'noinst_LIBRARIES']:
108 bc_targets
.extend(mv
[varname
].strip().split())
109 for target
in bc_targets
:
110 amtgt
= target
.replace('/', '_').replace('.', '_').replace('-', '_')
111 objs
= mv
[amtgt
+ '_OBJECTS'].strip().split()
112 objs
= [obj
+ '.bc' for obj
in objs
]
113 deps
= mv
.get(amtgt
+ '_DEPENDENCIES', '').strip().split()
114 deps
= [d
+ '.bc' for d
in deps
if d
.endswith('.a')]
116 out_lines
.append('%s.bc: %s' % (target
, ' '.join(objs
)))
117 out_lines
.append('\t$(AM_V_LLVM_LD)$(LLVM_LINK) -o $@ $^')
120 out_lines
.append('# }clippy')
123 after
= '\n'.join(out_lines
)
127 with
open('Makefile.pyout', 'w') as fd
:
129 os
.rename('Makefile.pyout', 'Makefile')