aboutsummaryrefslogtreecommitdiffstats
path: root/src/bpfswitch/ksrc/Makefile
blob: 64bec2f82472e2a03cd5cc5c9b5e6c7c68355001 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# SPDX-License-Identifier: GPL-2.0

include ../config.mk

ifneq (,$(BUILDDIR))
OBJDIR = $(BUILDDIR)/ksrc/obj/
else
OBJDIR = obj/
endif

MODS += $(OBJDIR)xdp_l2fwd.o
MODS += $(OBJDIR)xdp_dummy.o

VPATH := .

# rule is based on samples/bpf/Makefile
DEFS = -D__KERNEL__ -D__BPF_TRACING__  -D__TARGET_ARCH_x86 $(EXTRA_DEFS)

CFLAGS += -Wno-unused-value -Wno-pointer-sign
CFLAGS += -Wno-compare-distinct-pointer-types
CFLAGS += -Wno-gnu-variable-sized-type-not-at-end
CFLAGS += -Wno-address-of-packed-member
CFLAGS += -Wno-tautological-compare
CFLAGS += -Wno-unknown-warning-option
CFLAGS += -fno-stack-protector

INCLUDES  = -I../include
INCLUDES += -I$(KSRC)/arch/x86/include
INCLUDES += -I$(KBLD)/arch/x86/include/generated
INCLUDES += -I$(KBLD)/include
INCLUDES += -I$(KSRC)/include
INCLUDES += -I$(KSRC)/arch/x86/include/uapi
INCLUDES += -I$(KBLD)/arch/x86/include/generated/uapi
INCLUDES += -I$(KSRC)/include/uapi
INCLUDES += -I$(KBLD)/include/generated/uapi

SINCLUDES  = -include $(KSRC)/include/linux/kconfig.h
SINCLUDES += -include include/asm_goto_workaround.h

# this is to find stdarg.h. Ubuntu has this under x86_64-linux-gnu
# and Fedora is under x86_64-redhat-linux. Let's try 'find'.
GCCVER=$(shell gcc -v 2>&1 | awk '{if ($$0 ~ /gcc version/) {ver=split($$3,n,"."); print n[1]}}')
GCC_INC=$(shell find /usr/lib/gcc/x86_64-*linux*/$(GCCVER) -name include)
NOSTDINC_FLAGS = -nostdinc -isystem $(GCC_INC)

all: build $(MODS)

build:
	@mkdir -p $(OBJDIR)

$(OBJDIR)%.o: %.c
	$(QUIET_CLANG)$(CLANG) $(NOSTDINC_FLAGS) $(INCLUDES) \
		$(SINCLUDES) $(DEFS) $(CFLAGS) \
		-O2 -emit-llvm $(CLANG_FLAGS) -c $< -o $@.cl
	$(QUIET_LLC)$(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@ $@.cl
	@rm $@.cl

clean:
	@rm -rf $(OBJDIR)