]>
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")
34 # check for files using clippy but not listed in clippy_scan
36 basepath
= os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
)))
37 if os
.path
.exists(os
.path
.join(basepath
, ".git")):
38 clippy_ref
= subprocess
.check_output(
46 "^#\s*include.*_clippy.c",
52 clippy_ref
= set(clippy_ref
.splitlines())
53 missing
= clippy_ref
- set(clippy_scan
)
57 'error: files seem to be using clippy, but not listed in "clippy_scan" in subdir.am:\n\t%s\n'
58 % ("\n\t".join(sorted(missing
)))
64 ${clippybase}.$$(OBJEXT): ${clippybase}_clippy.c
65 ${clippybase}.lo: ${clippybase}_clippy.c
66 ${clippybase}_clippy.c: $$(CLIPPY_DEPS)"""
69 clippyauxdep
= Template(
71 # auxiliary clippy target
72 ${target}: ${clippybase}_clippy.c
76 lines
= before
.splitlines()
77 autoderp
= "#AUTODERP# "
80 make_rule_re
= re
.compile("^([^:\s]+):\s*([^:\s]+)\s*($|\n)")
84 if line
.startswith(autoderp
):
85 line
= line
[len(autoderp
) :]
87 if line
== "# clippy{":
90 if line
== "# }clippy":
94 if line
.startswith("#"):
95 out_lines
.append(line
)
100 while full_line
.endswith("\\"):
101 full_line
= full_line
[:-1] + full_lines
.pop(0)
103 m
= make_rule_re
.match(full_line
)
105 out_lines
.append(line
)
108 line
, lines
= full_line
, full_lines
110 target
, dep
= m
.group(1), m
.group(2)
112 if target
.endswith(".lo") or target
.endswith(".o"):
113 if not dep
.endswith(".h"):
114 bcdeps
.append("%s.bc: %s" % (target
, target
))
115 bcdeps
.append("\t$(AM_V_LLVM_BC)$(COMPILE) -emit-llvm -c -o $@ %s" % (dep
))
116 if m
.group(2) in clippy_scan
:
118 clippyauxdep
.substitute(target
=m
.group(1), clippybase
=m
.group(2)[:-2])
121 out_lines
.append(line
)
123 out_lines
.append("# clippy{\n# main clippy targets")
124 for clippy_file
in clippy_scan
:
125 out_lines
.append(clippydep
.substitute(clippybase
=clippy_file
[:-2]))
128 out_lines
.extend(bcdeps
)
135 "module_LTLIBRARIES",
138 bc_targets
.extend(mv
[varname
].strip().split())
139 for target
in bc_targets
:
140 amtgt
= target
.replace("/", "_").replace(".", "_").replace("-", "_")
141 objs
= mv
[amtgt
+ "_OBJECTS"].strip().split()
142 objs
= [obj
+ ".bc" for obj
in objs
]
143 deps
= mv
.get(amtgt
+ "_DEPENDENCIES", "").strip().split()
144 deps
= [d
+ ".bc" for d
in deps
if d
.endswith(".a")]
146 out_lines
.append("%s.bc: %s" % (target
, " ".join(objs
)))
147 out_lines
.append("\t$(AM_V_LLVM_LD)$(LLVM_LINK) -o $@ $^")
150 out_lines
.append("# }clippy")
153 after
= "\n".join(out_lines
)
157 with
open("Makefile.pyout", "w") as fd
:
159 os
.rename("Makefile.pyout", "Makefile")