Skip to content

Commit

Permalink
build: add LLVM bitcode targets
Browse files Browse the repository at this point in the history
Just an easy way to produce LLVM .bc (bitcode) files.  Not used during
normal builds.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
  • Loading branch information
eqvinox committed May 5, 2020
1 parent 0045c13 commit 8fb4037
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
*.pb-c.c
*.pb.cc
*_clippy.c
*.bc
*.cg.json

### gcov outputs

Expand Down
32 changes: 30 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ EXTRA_PROGRAMS =
BUILT_SOURCES =
CLEANFILES =
DISTCLEANFILES =
SUFFIXES =

examplesdir = $(exampledir)

Expand Down Expand Up @@ -232,12 +233,39 @@ EXTRA_DIST += \
vrrpd/Makefile \
# end

clean-local: clean-python
.PHONY: clean-python
AM_V_LLVM_BC = $(am__v_LLVM_BC_$(V))
am__v_LLVM_BC_ = $(am__v_LLVM_BC_$(AM_DEFAULT_VERBOSITY))
am__v_LLVM_BC_0 = @echo " LLVM.BC " $@;
am__v_LLVM_BC_1 =

AM_V_LLVM_LD = $(am__v_LLVM_LD_$(V))
am__v_LLVM_LD_ = $(am__v_LLVM_LD_$(AM_DEFAULT_VERBOSITY))
am__v_LLVM_LD_0 = @echo " LLVM.LD " $@;
am__v_LLVM_LD_1 =

SUFFIXES += .lo.bc .o.bc

.o.o.bc:
$(AM_V_LLVM_BC)$(COMPILE) -emit-llvm -c -o $@ $(patsubst %.o,%.c,$<)
.lo.lo.bc:
$(AM_V_LLVM_BC)$(COMPILE) -emit-llvm -c -o $@ $(patsubst %.lo,%.c,$<)

%.cg.json: %.bc tools/frr-llvm-cg
tools/frr-llvm-cg -o $@ $<

# <lib>.la.bc, <lib>.a.bc and <daemon>.bc targets are generated by
# python/makefile.py
LLVM_LINK = llvm-link-$(llvm_version)

clean-local: clean-python clean-llvm-bitcode
.PHONY: clean-python clean-llvm-bitcode
clean-python:
find . -name __pycache__ -o -name .pytest_cache | xargs rm -rf
find . -name "*.pyc" -o -name "*_clippy.c" | xargs rm -f

clean-llvm-bitcode:
find . -name "*.bc" -o -name "*.cg.json" | xargs rm -f

redistclean:
$(MAKE) distclean CONFIG_CLEAN_FILES="$(filter-out $(EXTRA_DIST), $(CONFIG_CLEAN_FILES))"

Expand Down
2 changes: 2 additions & 0 deletions grpc/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ am__v_PROTOC_ = $(am__v_PROTOC_$(AM_DEFAULT_VERBOSITY))
am__v_PROTOC_0 = @echo " PROTOC" $@;
am__v_PROTOC_1 =

SUFFIXES += .pb.h .pb.cc .grpc.pb.cc

.proto.pb.cc:
$(AM_V_PROTOC)$(PROTOC) -I$(top_srcdir) --cpp_out=$(top_srcdir) $(top_srcdir)/$^
.proto.grpc.pb.cc:
Expand Down
2 changes: 1 addition & 1 deletion lib/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ am__v_CLIPPY_1 =

CLIPPY_DEPS = $(CLIPPY) $(top_srcdir)/python/clidef.py

SUFFIXES = _clippy.c .proto .pb-c.c .pb-c.h .pb.h .pb.cc .grpc.pb.cc
SUFFIXES += _clippy.c
.c_clippy.c:
$(AM_V_CLIPPY) $(CLIPPY) $(top_srcdir)/python/clidef.py -o $@ $<

Expand Down
25 changes: 25 additions & 0 deletions python/makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
lines = before.splitlines()
autoderp = '#AUTODERP# '
out_lines = []
bcdeps = []
make_rule_re = re.compile('^([^:\s]+):\s*([^:\s]+)\s*($|\n)')

while lines:
Expand All @@ -77,6 +78,12 @@
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]))

Expand All @@ -85,6 +92,24 @@
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('')

Expand Down
1 change: 1 addition & 0 deletions qpb/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ CLEANFILES += \
# end

EXTRA_DIST += qpb/qpb.proto
SUFFIXES += .proto .pb-c.c .pb-c.h

if HAVE_PROTOBUF

Expand Down
6 changes: 3 additions & 3 deletions tools/subdir.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ tools_gen_yang_deviations_LDADD = lib/libfrr.la $(LIBYANG_LIBS)
tools_ssd_SOURCES = tools/start-stop-daemon.c

# don't bother autoconf'ing these for a simple optional tool
llvm_config = llvm-config-$(shell echo __clang_major__ | $(CC) -xc -P -E -)
tools_frr_llvm_cg_CFLAGS = $(AM_CFLAGS) `$(llvm_config) --cflags`
tools_frr_llvm_cg_LDFLAGS = `$(llvm_config) --ldflags --libs`
llvm_version = $(shell echo __clang_major__ | $(CC) -xc -P -E -)
tools_frr_llvm_cg_CFLAGS = $(AM_CFLAGS) `llvm-config-$(llvm_version) --cflags`
tools_frr_llvm_cg_LDFLAGS = `llvm-config-$(llvm_version) --ldflags --libs`
tools_frr_llvm_cg_SOURCES = \
tools/frr-llvm-cg.c \
# end
Expand Down

0 comments on commit 8fb4037

Please sign in to comment.