forked from xdp-project/xdp-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate common parts of Makefiles into common.mk
There's a lot of repetition in the Makefiles which is not really needed (and leads to small deviations over timer). Move all the common stuff into common.mk and just include that. Make a few adjustments along the way to make sure things keep working. Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
- Loading branch information
Showing
6 changed files
with
95 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,16 @@ | ||
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) | ||
|
||
TARGETS := xdp_pass | ||
XDP_TARGETS := xdp_pass_kern | ||
USER_TARGETS := xdp_pass | ||
USER_C := xdp_pass_user.c | ||
|
||
|
||
LLC ?= llc | ||
CLANG ?= clang | ||
CC := gcc | ||
|
||
LIBBPF_DIR = ../libbpf/src/ | ||
COMMON_DIR = ../common/ | ||
COMMON_OBJS := $(COMMON_DIR)/common_params.o | ||
|
||
XDP_C = ${TARGETS:=_kern.c} | ||
XDP_OBJ = ${XDP_C:.c=.o} | ||
USER_C = ${TARGETS:=_user.c} | ||
USER_OBJ = ${USER_C:.c=.o} | ||
OBJECT_LIBBPF = $(LIBBPF_DIR)/libbpf.a | ||
|
||
COMMON_OBJS := ../common/common_params.o | ||
# Supports adding more COMMON_OBJS | ||
# COMMON_OBJS += ../common/common_bpf.o | ||
|
||
# Create expansions for dependencies | ||
COMMON_H := ${COMMON_OBJS:.o=.h} | ||
|
||
CFLAGS ?= -I$(LIBBPF_DIR)/root/usr/include/ | ||
CFLAGS += -I../headers/ | ||
LDFLAGS ?= -L$(LIBBPF_DIR) | ||
|
||
LIBS = -lbpf -lelf | ||
|
||
all: llvm-check $(TARGETS) $(XDP_OBJ) | ||
|
||
.PHONY: clean $(CLANG) $(LLC) | ||
|
||
clean: | ||
cd $(LIBBPF_DIR) && $(MAKE) clean; | ||
make -C ../common/ clean | ||
rm -f $(TARGETS) | ||
rm -f $(XDP_OBJ) | ||
rm -f $(USER_OBJ) | ||
rm -f *.ll | ||
rm -f *~ | ||
|
||
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 | ||
|
||
$(OBJECT_LIBBPF): | ||
@if [ ! -d $(LIBBPF_DIR) ]; then \ | ||
echo "Error: Need libbpf submodule"; \ | ||
echo "May need to run git submodule update --init"; \ | ||
exit 1; \ | ||
else \ | ||
cd $(LIBBPF_DIR) && $(MAKE) all; \ | ||
mkdir -p root; DESTDIR=root $(MAKE) install_headers; \ | ||
fi | ||
|
||
# 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/ | ||
|
||
$(TARGETS): %: %_user.c $(OBJECT_LIBBPF) Makefile $(COMMON_OBJS) | ||
$(CC) -Wall $(CFLAGS) $(LDFLAGS) -o $@ $(COMMON_OBJS) \ | ||
$< $(LIBS) | ||
|
||
$(XDP_OBJ): %.o: %.c Makefile | ||
$(CLANG) -S \ | ||
-target bpf \ | ||
-D __BPF_TRACING__ \ | ||
$(CFLAGS) \ | ||
-Wall \ | ||
-Wno-unused-value \ | ||
-Wno-pointer-sign \ | ||
-Wno-compare-distinct-pointer-types \ | ||
-Werror \ | ||
-O2 -emit-llvm -c -g $< | ||
$(LLC) -march=bpf -filetype=obj -o $@ ${@:.o=.ll} | ||
include $(COMMON_DIR)/common.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,10 @@ | ||
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) | ||
|
||
# Departing from the implicit _user.c scheme | ||
XDP_TARGETS := xdp_prog_kern | ||
USER_TARGETS := xdp_loader | ||
|
||
LLC ?= llc | ||
CLANG ?= clang | ||
CC := gcc | ||
|
||
LIBBPF_DIR = ../libbpf/src/ | ||
COMMON_DIR = ../common/ | ||
|
||
XDP_C = ${XDP_TARGETS:=.c} | ||
XDP_OBJ = ${XDP_C:.c=.o} | ||
USER_C = ${USER_TARGETS:=.c} | ||
USER_OBJ = ${USER_C:.c=.o} | ||
|
||
OBJECT_LIBBPF = $(LIBBPF_DIR)/libbpf.a | ||
|
||
COMMON_OBJS := ../common/common_params.o | ||
COMMON_OBJS += ../common/common_user_bpf_xdp.o | ||
# Create expansions for dependencies | ||
COMMON_H := ${COMMON_OBJS:.o=.h} | ||
|
||
CFLAGS ?= -I$(LIBBPF_DIR)/root/usr/include/ | ||
CFLAGS += -I../headers/ | ||
LDFLAGS ?= -L$(LIBBPF_DIR) | ||
|
||
LIBS = -lbpf -lelf | ||
|
||
all: llvm-check $(USER_TARGETS) $(XDP_OBJ) | ||
|
||
.PHONY: clean $(CLANG) $(LLC) | ||
|
||
clean: | ||
cd $(LIBBPF_DIR) && $(MAKE) clean; | ||
make -C ../common/ clean | ||
rm -f $(USER_TARGETS) | ||
rm -f $(XDP_OBJ) | ||
rm -f $(USER_OBJ) | ||
rm -f *.ll | ||
rm -f *~ | ||
|
||
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 | ||
|
||
$(OBJECT_LIBBPF): | ||
@if [ ! -d $(LIBBPF_DIR) ]; then \ | ||
echo "Error: Need libbpf submodule"; \ | ||
echo "May need to run: git submodule update --init"; \ | ||
exit 1; \ | ||
else \ | ||
cd $(LIBBPF_DIR) && $(MAKE) all; \ | ||
mkdir -p root; DESTDIR=root $(MAKE) install_headers; \ | ||
fi | ||
|
||
# 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/ | ||
|
||
$(USER_TARGETS): %: %.c $(OBJECT_LIBBPF) Makefile $(COMMON_OBJS) | ||
$(CC) -Wall $(CFLAGS) $(LDFLAGS) -o $@ $(COMMON_OBJS) \ | ||
$< $(LIBS) | ||
include $(COMMON_DIR)/common.mk | ||
|
||
$(XDP_OBJ): %.o: %.c Makefile | ||
$(CLANG) -S \ | ||
-target bpf \ | ||
-D __BPF_TRACING__ \ | ||
$(CFLAGS) \ | ||
-Wall \ | ||
-Wno-unused-value \ | ||
-Wno-pointer-sign \ | ||
-Wno-compare-distinct-pointer-types \ | ||
-Werror \ | ||
-O2 -emit-llvm -c -g $< | ||
$(LLC) -march=bpf -filetype=obj -o $@ ${@:.o=.ll} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.