2023-01-23 18:54:21 +07:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
2024-01-04 16:28:16 +07:00
|
|
|
# Copyright (c) 2022-2024, daeuniverse Organization <dae@v2raya.org>
|
2023-01-23 18:54:21 +07:00
|
|
|
#
|
|
|
|
|
|
|
|
# The development version of clang is distributed as the 'clang' binary,
|
|
|
|
# while stable/released versions have a version number attached.
|
|
|
|
# Pin the default clang to a stable version.
|
2023-01-28 12:27:54 +07:00
|
|
|
CLANG ?= clang
|
2023-01-23 18:54:21 +07:00
|
|
|
STRIP ?= llvm-strip
|
2023-01-27 01:10:27 +07:00
|
|
|
CFLAGS := -O2 -Wall -Werror $(CFLAGS)
|
2023-01-31 21:02:18 +07:00
|
|
|
TARGET ?= bpfel,bpfeb
|
2023-02-05 09:29:00 +07:00
|
|
|
OUTPUT ?= dae
|
2024-10-30 00:06:13 +07:00
|
|
|
MAX_MATCH_SET_LEN ?= 1024
|
2023-03-14 12:54:43 +07:00
|
|
|
CFLAGS := -DMAX_MATCH_SET_LEN=$(MAX_MATCH_SET_LEN) $(CFLAGS)
|
2023-03-17 14:37:12 +07:00
|
|
|
NOSTRIP ?= n
|
2023-03-17 14:56:55 +07:00
|
|
|
STRIP_PATH := $(shell command -v $(STRIP) 2>/dev/null)
|
2024-01-27 12:33:00 +07:00
|
|
|
BUILD_TAGS_FILE := .build_tags
|
2023-03-17 14:37:12 +07:00
|
|
|
ifeq ($(strip $(NOSTRIP)),y)
|
|
|
|
STRIP_FLAG := -no-strip
|
2023-03-17 14:56:55 +07:00
|
|
|
else ifeq ($(wildcard $(STRIP_PATH)),)
|
|
|
|
STRIP_FLAG := -no-strip
|
2023-03-17 14:37:12 +07:00
|
|
|
else
|
2023-03-19 11:26:09 +07:00
|
|
|
STRIP_FLAG := -strip=$(STRIP_PATH)
|
2023-03-17 14:37:12 +07:00
|
|
|
endif
|
2023-01-27 01:10:27 +07:00
|
|
|
|
2024-02-05 13:00:09 +07:00
|
|
|
GOARCH ?= $(shell go env GOARCH)
|
|
|
|
|
2023-06-04 10:38:05 +07:00
|
|
|
# Do NOT remove the line below. This line is for CI.
|
2023-04-01 23:10:37 +07:00
|
|
|
#export GOMODCACHE=$(PWD)/go-mod
|
|
|
|
|
2023-01-27 01:10:27 +07:00
|
|
|
# Get version from .git.
|
|
|
|
date=$(shell git log -1 --format="%cd" --date=short | sed s/-//g)
|
|
|
|
count=$(shell git rev-list --count HEAD)
|
|
|
|
commit=$(shell git rev-parse --short HEAD)
|
|
|
|
ifeq ($(wildcard .git/.),)
|
2023-01-28 12:52:31 +07:00
|
|
|
VERSION ?= unstable-0.nogit
|
2023-01-27 01:10:27 +07:00
|
|
|
else
|
2023-01-28 12:52:31 +07:00
|
|
|
VERSION ?= unstable-$(date).r$(count).$(commit)
|
2023-01-27 01:10:27 +07:00
|
|
|
endif
|
2023-01-23 18:54:21 +07:00
|
|
|
|
2023-08-14 18:16:23 +07:00
|
|
|
BUILD_ARGS := -trimpath -ldflags "-s -w -X github.com/daeuniverse/dae/cmd.Version=$(VERSION) -X github.com/daeuniverse/dae/common/consts.MaxMatchSetLen_=$(MAX_MATCH_SET_LEN)" $(BUILD_ARGS)
|
2023-08-09 22:00:38 +07:00
|
|
|
|
2023-06-08 09:55:37 +07:00
|
|
|
.PHONY: clean-ebpf ebpf dae submodule submodules
|
2023-01-23 19:01:24 +07:00
|
|
|
|
2023-06-08 09:55:37 +07:00
|
|
|
## Begin Dae Build
|
2023-05-13 14:38:10 +07:00
|
|
|
dae: export GOOS=linux
|
2024-01-02 22:31:50 +07:00
|
|
|
ifndef CGO_ENABLED
|
|
|
|
dae: export CGO_ENABLED=0
|
|
|
|
endif
|
2023-01-24 13:25:21 +07:00
|
|
|
dae: ebpf
|
2023-08-09 22:00:38 +07:00
|
|
|
@echo $(CFLAGS)
|
2024-01-27 12:33:00 +07:00
|
|
|
go build -tags=$(shell cat $(BUILD_TAGS_FILE)) -o $(OUTPUT) $(BUILD_ARGS) .
|
2023-06-08 09:55:37 +07:00
|
|
|
## End Dae Build
|
2023-01-23 18:54:21 +07:00
|
|
|
|
2023-06-08 09:55:37 +07:00
|
|
|
## Begin Git Submodules
|
|
|
|
.gitmodules.d.mk: .gitmodules
|
2023-06-09 21:10:21 +07:00
|
|
|
@set -e && \
|
2023-06-17 13:32:29 +07:00
|
|
|
submodules=$$(grep '\[submodule "' .gitmodules | cut -d'"' -f2 | tr '\n' ' ' | tr ' \n' '\n') && \
|
2023-06-09 21:10:21 +07:00
|
|
|
echo "submodule_paths=$${submodules}" > $@
|
2023-06-08 09:55:37 +07:00
|
|
|
|
|
|
|
-include .gitmodules.d.mk
|
|
|
|
|
|
|
|
$(submodule_paths): .gitmodules.d.mk
|
|
|
|
git submodule update --init --recursive -- $@ && \
|
|
|
|
touch $@
|
|
|
|
|
|
|
|
submodule submodules: $(submodule_paths)
|
|
|
|
@if [ -z "$(submodule_paths)" ]; then \
|
2023-06-09 21:10:21 +07:00
|
|
|
rm -f .gitmodules.d.mk; \
|
2023-06-08 09:55:37 +07:00
|
|
|
echo "Failed to generate submodules list. Please try again."; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
## End Git Submodules
|
|
|
|
|
|
|
|
## Begin Ebpf
|
2023-06-04 10:38:05 +07:00
|
|
|
clean-ebpf:
|
2023-02-18 17:31:40 +07:00
|
|
|
@rm -f control/bpf_bpf*.go && \
|
2023-02-07 22:49:30 +07:00
|
|
|
rm -f control/bpf_bpf*.o
|
2024-01-27 12:33:00 +07:00
|
|
|
@rm -f trace/bpf_bpf*.go && \
|
|
|
|
rm -f trace/bpf_bpf*.o
|
2024-10-14 10:21:45 +07:00
|
|
|
@rm -f control/kern/tests/bpftest_bpf*.go && \
|
|
|
|
rm -f control/kern/tests/bpftest_bpf*.o
|
2023-04-23 12:27:29 +07:00
|
|
|
fmt:
|
|
|
|
go fmt ./...
|
2023-01-31 17:33:47 +07:00
|
|
|
|
2023-01-23 18:54:21 +07:00
|
|
|
# $BPF_CLANG is used in go:generate invocations.
|
2023-01-23 19:01:24 +07:00
|
|
|
ebpf: export BPF_CLANG := $(CLANG)
|
2023-03-17 14:37:12 +07:00
|
|
|
ebpf: export BPF_STRIP_FLAG := $(STRIP_FLAG)
|
2023-01-23 19:01:24 +07:00
|
|
|
ebpf: export BPF_CFLAGS := $(CFLAGS)
|
2023-01-31 19:25:55 +07:00
|
|
|
ebpf: export BPF_TARGET := $(TARGET)
|
2024-01-27 12:33:00 +07:00
|
|
|
ebpf: export BPF_TRACE_TARGET := $(GOARCH)
|
2023-06-08 09:55:37 +07:00
|
|
|
ebpf: submodule clean-ebpf
|
2023-02-18 17:31:40 +07:00
|
|
|
@unset GOOS && \
|
2023-01-28 17:32:42 +07:00
|
|
|
unset GOARCH && \
|
|
|
|
unset GOARM && \
|
2023-03-17 14:56:55 +07:00
|
|
|
echo $(STRIP_FLAG) && \
|
2024-01-27 12:33:00 +07:00
|
|
|
go generate ./control/control.go && \
|
|
|
|
go generate ./trace/trace.go && echo trace > $(BUILD_TAGS_FILE) || echo > $(BUILD_TAGS_FILE)
|
|
|
|
|
2024-03-15 19:26:21 +07:00
|
|
|
ebpf-lint:
|
2024-04-08 21:23:55 +07:00
|
|
|
./scripts/checkpatch.pl --no-tree --strict --no-summary --show-types --color=always control/kern/tproxy.c --ignore COMMIT_COMMENT_SYMBOL,NOT_UNIFIED_DIFF,COMMIT_LOG_LONG_LINE,LONG_LINE_COMMENT,VOLATILE,ASSIGN_IN_IF,PREFER_DEFINED_ATTRIBUTE_MACRO,CAMELCASE,LEADING_SPACE,OPEN_ENDED_LINE,SPACING,BLOCK_COMMENT_STYLE
|
2024-03-15 19:26:21 +07:00
|
|
|
|
2024-10-14 10:21:45 +07:00
|
|
|
ebpf-test: export BPF_CLANG := $(CLANG)
|
|
|
|
ebpf-test: export BPF_STRIP_FLAG := $(STRIP_FLAG)
|
|
|
|
ebpf-test: export BPF_CFLAGS := $(CFLAGS)
|
|
|
|
ebpf-test: export BPF_TARGET := $(TARGET)
|
|
|
|
ebpf-test: export BPF_TRACE_TARGET := $(GOARCH)
|
|
|
|
ebpf-test: submodule clean-ebpf
|
|
|
|
@unset GOOS && \
|
|
|
|
unset GOARCH && \
|
|
|
|
unset GOARM && \
|
|
|
|
echo $(STRIP_FLAG) && \
|
|
|
|
go generate ./control/kern/tests/bpf_test.go && \
|
|
|
|
go clean -testcache && \
|
|
|
|
go test -v ./control/kern/tests/...
|
|
|
|
|
2023-06-08 09:55:37 +07:00
|
|
|
## End Ebpf
|