]>
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")
21 help="run additional developer checks",
23 args
= argp
.parse_args()
25 with
open("Makefile", "r") as fd
:
28 mv
= MakeReVars(before
)
30 clippy_scan
= mv
["clippy_scan"].strip().split()
31 for clippy_file
in clippy_scan
:
32 assert clippy_file
.endswith(".c")
35 for varname
in ["bin_PROGRAMS", "sbin_PROGRAMS", "lib_LTLIBRARIES", "module_LTLIBRARIES"]:
36 xref_targets
.extend(mv
[varname
].strip().split())
38 # check for files using clippy but not listed in clippy_scan
40 basepath
= os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
)))
41 if os
.path
.exists(os
.path
.join(basepath
, ".git")):
42 clippy_ref
= subprocess
.check_output(
50 "^#\s*include.*_clippy.c",
56 clippy_ref
= set(clippy_ref
.splitlines())
57 missing
= clippy_ref
- set(clippy_scan
)
61 'error: files seem to be using clippy, but not listed in "clippy_scan" in subdir.am:\n\t%s\n'
62 % ("\n\t".join(sorted(missing
)))
68 ${clippybase}.$$(OBJEXT): ${clippybase}_clippy.c
69 ${clippybase}.lo: ${clippybase}_clippy.c
70 ${clippybase}_clippy.c: $$(CLIPPY_DEPS)"""
73 clippyauxdep
= Template(
75 # auxiliary clippy target
76 ${target}: ${clippybase}_clippy.c
80 lines
= before
.splitlines()
81 autoderp
= "#AUTODERP# "
84 make_rule_re
= re
.compile("^([^:\s]+):\s*([^:\s]+)\s*($|\n)")
88 if line
.startswith(autoderp
):
89 line
= line
[len(autoderp
) :]
91 if line
== "# clippy{":
94 if line
== "# }clippy":
98 if line
.startswith("#"):
99 out_lines
.append(line
)
103 full_lines
= lines
[:]
104 while full_line
.endswith("\\"):
105 full_line
= full_line
[:-1] + full_lines
.pop(0)
107 m
= make_rule_re
.match(full_line
)
109 out_lines
.append(line
)
112 line
, lines
= full_line
, full_lines
114 target
, dep
= m
.group(1), m
.group(2)
116 if target
.endswith(".lo") or target
.endswith(".o"):
117 if not dep
.endswith(".h"):
118 bcdeps
.append("%s.bc: %s" % (target
, target
))
119 bcdeps
.append("\t$(AM_V_LLVM_BC)$(COMPILE) -emit-llvm -c -o $@ %s" % (dep
))
120 if m
.group(2) in clippy_scan
:
122 clippyauxdep
.substitute(target
=m
.group(1), clippybase
=m
.group(2)[:-2])
125 out_lines
.append(line
)
127 out_lines
.append("# clippy{\n# main clippy targets")
128 for clippy_file
in clippy_scan
:
129 out_lines
.append(clippydep
.substitute(clippybase
=clippy_file
[:-2]))
132 out_lines
.append("xrefs = %s" % (" ".join(["%s.xref" % target
for target
in xref_targets
])))
133 out_lines
.append("frr.xref: $(xrefs)")
136 #frr.xref: $(bin_PROGRAMS) $(sbin_PROGRAMS) $(lib_LTLIBRARIES) $(module_LTLIBRARIES)
137 # $(AM_V_XRELFO) $(CLIPPY) $(top_srcdir)/python/xrelfo.py -o $@ $^
140 out_lines
.extend(bcdeps
)
147 "module_LTLIBRARIES",
150 bc_targets
.extend(mv
[varname
].strip().split())
151 for target
in bc_targets
:
152 amtgt
= target
.replace("/", "_").replace(".", "_").replace("-", "_")
153 objs
= mv
[amtgt
+ "_OBJECTS"].strip().split()
154 objs
= [obj
+ ".bc" for obj
in objs
]
155 deps
= mv
.get(amtgt
+ "_DEPENDENCIES", "").strip().split()
156 deps
= [d
+ ".bc" for d
in deps
if d
.endswith(".a")]
158 out_lines
.append("%s.bc: %s" % (target
, " ".join(objs
)))
159 out_lines
.append("\t$(AM_V_LLVM_LD)$(LLVM_LINK) -o $@ $^")
162 out_lines
.append("# }clippy")
165 after
= "\n".join(out_lines
)
169 with
open("Makefile.pyout", "w") as fd
:
171 os
.rename("Makefile.pyout", "Makefile")