github.com/jayanthvn/pure-gobpf@v0.0.0-20230623131354-8d1d959d9e0b/Makefile (about)

     1  .PHONY: all build-linux 
     2  
     3  export GOPROXY = direct
     4  
     5  UNAME_ARCH = $(shell uname -m)
     6  ARCH = $(lastword $(subst :, ,$(filter $(UNAME_ARCH):%,x86_64:x86 aarch64:arm64)))
     7  
     8  
     9  BUILD_MODE ?= -buildmode=pie
    10  build-linux: BUILD_FLAGS = $(BUILD_MODE) -ldflags '-s -w'
    11  build-linux:    ## Build the VPC CNI plugin agent using the host's Go toolchain.
    12  	find ./pkg -type f -name '*.go' -exec sh -c 'echo Compiling {} && go build {}' \;
    13  
    14  format:       ## Format all Go source code files.
    15  	@command -v goimports >/dev/null || { echo "ERROR: goimports not installed"; exit 1; }
    16  	@exit $(shell find ./* \
    17  	  -type f \
    18  	  -name '*.go' \
    19  	  -print0 | sort -z | xargs -0 -- goimports $(or $(FORMAT_FLAGS),-w) | wc -l | bc)
    20  
    21  # Build BPF
    22  CLANG := clang
    23  CLANG_INCLUDE := -I../../..
    24  EBPF_SOURCE := test-data/tc.ingress.bpf.c
    25  EBPF_BINARY := test-data/tc.ingress.bpf.elf
    26  EBPF_TEST_SOURCE := test-data/tc.bpf.c
    27  EBPF_TEST_BINARY := test-data/tc.bpf.elf 
    28  EBPF_TEST_MAP_SOURCE := test-data/test.map.bpf.c
    29  EBPF_TEST_MAP_BINARY := test-data/test.map.bpf.elf 
    30  build-bpf: ## Build BPF
    31  	$(CLANG) $(CLANG_INCLUDE) -g -O2 -Wall -fpie -target bpf -DCORE -D__BPF_TRACING__ -march=bpf -D__TARGET_ARCH_$(ARCH) -c $(EBPF_SOURCE) -o $(EBPF_BINARY)
    32  	$(CLANG) $(CLANG_INCLUDE) -g -O2 -Wall -fpie -target bpf -DCORE -D__BPF_TRACING__ -march=bpf -D__TARGET_ARCH_$(ARCH) -c $(EBPF_TEST_SOURCE) -o $(EBPF_TEST_BINARY)
    33  	$(CLANG) $(CLANG_INCLUDE) -g -O2 -Wall -fpie -target bpf -DCORE -D__BPF_TRACING__ -march=bpf -D__TARGET_ARCH_$(ARCH) -c $(EBPF_TEST_MAP_SOURCE) -o $(EBPF_TEST_MAP_BINARY)
    34  
    35  vmlinuxh:
    36  	bpftool btf dump file /sys/kernel/btf/vmlinux format c > $(abspath ./test-data/vmlinux.h)
    37  
    38  ##@ Run Unit Tests
    39  # Run unit tests
    40  unit-test: vmlinuxh
    41  unit-test: build-bpf
    42  unit-test: export AWS_EBPF_SDK_LOG_FILE=stdout
    43  unit-test:    ## Run unit tests
    44  	go test -v -coverprofile=coverage.txt -covermode=atomic ./pkg/...