Page Menu
Home
VyOS Platform
Search
Configure Global Search
Log In
Files
F119062657
common.mk
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
common.mk
View Options
# Common Makefile parts for BPF-building with libbpf
# --------------------------------------------------
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
#
# This file should be included from your Makefile like:
# COMMON_DIR = ../common/
# include $(COMMON_DIR)/common.mk
#
# It is expected that you define the variables:
# XDP_TARGETS and USER_TARGETS
# as a space-separated list
#
LLC ?= llc
CLANG ?= clang
CC ?= gcc
XDP_C = ${XDP_TARGETS:=.c}
XDP_OBJ = ${XDP_C:.c=.o}
USER_C := ${USER_TARGETS:=.c}
USER_OBJ := ${USER_C:.c=.o}
# Expect this is defined by including Makefile, but define if not
COMMON_DIR ?= ../common/
COPY_LOADER ?=
LOADER_DIR ?= $(COMMON_DIR)/../utils
# Extend if including Makefile already added some
COMMON_OBJS += $(COMMON_DIR)/common_params.o $(COMMON_DIR)/common_user_bpf_xdp.o
# Create expansions for dependencies
COMMON_H := ${COMMON_OBJS:.o=.h}
EXTRA_DEPS +=
# BPF-prog kern and userspace shares struct via header file:
KERN_USER_H ?= $(wildcard common_kern_user.h)
CFLAGS ?= -g -I../include/
BPF_CFLAGS ?= -I../include/
LIBS = -l:libbpf.a -lelf $(USER_LIBS)
all: llvm-check $(USER_TARGETS) $(XDP_OBJ) $(COPY_LOADER) $(COPY_STATS)
.PHONY: clean $(CLANG) $(LLC)
clean:
$(MAKE) -C $(COMMON_DIR) clean
rm -f $(USER_TARGETS) $(XDP_OBJ) $(USER_OBJ) $(COPY_LOADER) $(COPY_STATS)
rm -f *.ll
rm -f *~
ifdef COPY_LOADER
$(COPY_LOADER): $(LOADER_DIR)/${COPY_LOADER:=.c} $(COMMON_H)
make -C $(LOADER_DIR) $(COPY_LOADER)
cp $(LOADER_DIR)/$(COPY_LOADER) $(COPY_LOADER)
endif
ifdef COPY_STATS
$(COPY_STATS): $(LOADER_DIR)/${COPY_STATS:=.c} $(COMMON_H)
make -C $(LOADER_DIR) $(COPY_STATS)
cp $(LOADER_DIR)/$(COPY_STATS) $(COPY_STATS)
# Needing xdp_stats imply depending on header files:
EXTRA_DEPS += $(COMMON_DIR)/xdp_stats_kern.h $(COMMON_DIR)/xdp_stats_kern_user.h
endif
# For build dependency on this file, if it gets updated
COMMON_MK = $(COMMON_DIR)/common.mk
llvm-check: $(CLANG) $(LLC)
@for TOOL in $^ ; do \
if [ ! $$(command -v $${TOOL} 2>/dev/null) ]; then \
echo "*** ERROR: Cannot find tool $${TOOL}" ;\
exit 1; \
else true; fi; \
done
# Create dependency: detect if C-file change and touch H-file, to trigger
# target $(COMMON_OBJS)
$(COMMON_H): %.h: %.c
touch $@
# Detect if any of common obj changed and create dependency on .h-files
$(COMMON_OBJS): %.o: %.h
make -C $(COMMON_DIR)
$(USER_TARGETS): %: %.c Makefile $(COMMON_MK) $(COMMON_OBJS) $(KERN_USER_H) $(EXTRA_DEPS)
$(CC) -Wall $(CFLAGS) $(LDFLAGS) -o $@ $(COMMON_OBJS) \
$< $(LIBS)
$(XDP_OBJ): %.o: %.c Makefile $(COMMON_MK) $(KERN_USER_H) $(EXTRA_DEPS)
$(CLANG) -S \
-target bpf \
-D __BPF_TRACING__ \
$(BPF_CFLAGS) \
-Wall \
-Wno-unused-value \
-Wno-pointer-sign \
-Wno-compare-distinct-pointer-types \
-Werror \
-O2 -emit-llvm -c -g -o ${@:.o=.ll} $<
$(LLC) -march=bpf -filetype=obj -o $@ ${@:.o=.ll}
File Metadata
Details
Attached
Mime Type
text/x-makefile
Expires
Fri, Nov 6, 7:09 AM (15 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4568998
Default Alt Text
common.mk (2 KB)
Attached To
Mode
rVYOSONEX vyos-1x
Attached
Detach File
Event Timeline
Log In to Comment