Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(make): improve error handling and clean target logic in Makefile #713

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ clean:
$(CMD_RM) -f assets/ebpf_probe.go
$(CMD_RM) -f bin/ecapture
$(CMD_RM) -f .check*
@if [ -e ./lib/libpcap/Makefile ] ; then \
cd ./lib/libpcap && make clean
fi
if test -e "./lib/libpcap/Makefile"; then $(MAKE) -C ./lib/libpcap clean; fi

.PHONY: $(KERN_OBJECTS)
$(KERN_OBJECTS): %.o: %.c \
Expand All @@ -126,14 +124,14 @@ $(KERN_OBJECTS): %.o: %.c \
$(BPFHEADER) \
-target bpfel -c $< -o $(subst kern/,user/bytecode/,$(subst .o,_core.o,$@)) \
-fno-ident -fdebug-compilation-dir . -g -D__BPF_TARGET_MISSING="GCC error \"The eBPF is using target specific macros, please provide -target\"" \
-MD -MP
-MD -MP || exit 1
$(CMD_CLANG) -D__TARGET_ARCH_$(LINUX_ARCH) \
$(EXTRA_CFLAGS) \
$(BPFHEADER) \
-DKERNEL_LESS_5_2 \
-target bpfel -c $< -o $(subst kern/,user/bytecode/,$(subst .c,_core$(KERNEL_LESS_5_2_PREFIX),$<)) \
-fno-ident -fdebug-compilation-dir . -g -D__BPF_TARGET_MISSING="GCC error \"The eBPF is using target specific macros, please provide -target\"" \
-MD -MP
-MD -MP || exit 1

.PHONY: autogen
autogen: .checkver_$(CMD_BPFTOOL)
Expand Down Expand Up @@ -164,7 +162,7 @@ $(KERN_OBJECTS_NOCORE): %.nocore: %.c \
-o - |$(CMD_LLC) \
-march=bpf \
-filetype=obj \
-o $(subst kern/,user/bytecode/,$(subst .c,_noncore.o,$<))
-o $(subst kern/,user/bytecode/,$(subst .c,_noncore.o,$<)) || exit 1
$(CMD_CLANG) \
$(EXTRA_CFLAGS_NOCORE) \
$(BPFHEADER) \
Expand All @@ -180,13 +178,10 @@ $(KERN_OBJECTS_NOCORE): %.nocore: %.c \
-o - |$(CMD_LLC) \
-march=bpf \
-filetype=obj \
-o $(subst kern/,user/bytecode/,$(subst .c,_noncore$(KERNEL_LESS_5_2_PREFIX),$<))
-o $(subst kern/,user/bytecode/,$(subst .c,_noncore$(KERNEL_LESS_5_2_PREFIX),$<)) || exit 1

.PHONY: assets
assets: \
.checkver_$(CMD_GO) \
ebpf \
ebpf_noncore
assets: .checkver_$(CMD_GO) ebpf ebpf_noncore
$(CMD_GO) run github.com/shuLhan/go-bindata/cmd/go-bindata $(IGNORE_LESS52) -pkg assets -o "assets/ebpf_probe.go" $(wildcard ./user/bytecode/*.o)

.PHONY: assets_noncore
Expand All @@ -205,14 +200,10 @@ $(TARGET_LIBPCAP):
--without-dpdk --without-dag --without-septel --without-snf \
--without-gcc --with-pcap=linux \
--without-turbocap --host=$(LIBPCAP_ARCH) && \
CC=$(CMD_CC_PREFIX)$(CMD_CC) AR=$(CMD_AR_PREFIX)$(CMD_AR) make
CC=$(CMD_CC_PREFIX)$(CMD_CC) AR=$(CMD_AR_PREFIX)$(CMD_AR) make || exit 1

.PHONY: build
build: \
.checkver_$(CMD_GO) \
$(TARGET_LIBPCAP) \
assets \
assets_noncore
build: .checkver_$(CMD_GO) $(TARGET_LIBPCAP) assets assets_noncore
$(call allow-override,VERSION_FLAG,$(UNAME_R))
$(call gobuild, $(ANDROID))

Expand Down
8 changes: 5 additions & 3 deletions builder/init_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ echo "GOBIN_ZIP:${GOBIN_ZIP}"
cd ~ || exit

uname -a
sudo apt-get update
# 环境安装
sudo apt-get install --yes build-essential pkgconf libelf-dev llvm${CLANG_NUM} clang${CLANG_NUM} linux-tools-common linux-tools-generic ${CROSS_COMPILE_DEB} libssl-dev flex bison bc linux-source
sudo apt-get update || { echo "apt-get update failed"; exit 1; }
# 环境安装,添加错误检查
sudo apt-get -y install build-essential pkgconf libelf-dev llvm${CLANG_NUM} \
clang${CLANG_NUM} linux-tools-common linux-tools-generic ${CROSS_COMPILE_DEB} \
libssl-dev flex bison bc linux-source || { echo "apt-get install failed"; exit 1; }
for tool in "clang" "llc" "llvm-strip"
do
sudo rm -f /usr/bin/$tool
Expand Down
8 changes: 4 additions & 4 deletions functions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
$(CMD_TOUCH) $@ # avoid target rebuilds over and over due to inexistent file


# golang 版本检测 1.21 以上
# golang 版本检测 1.22 以上
.checkver_$(CMD_GO): \
| .check_$(CMD_GO)
@if [ ${GO_VERSION_MAJ} -eq 1 ]; then
if [ ${GO_VERSION_MIN} -lt 21 ]; then
echo -n "you MUST use golang 1.21 or newer, "
if [ ${GO_VERSION_MIN} -lt 22 ]; then
echo -n "you MUST use golang 1.22 or newer, "
echo "your current golang version is ${GO_VERSION}"
exit 1
fi
Expand All @@ -49,7 +49,7 @@ define gobuild
CGO_CFLAGS='-O2 -g -gdwarf-4 -I$(CURDIR)/lib/libpcap/' \
CGO_LDFLAGS='-O2 -g -L$(CURDIR)/lib/libpcap/ -lpcap -static' \
GOOS=linux GOARCH=$(GOARCH) CC=$(CMD_CC_PREFIX)$(CMD_CC) \
$(CMD_GO) build -tags '$(TARGET_TAG),netgo' -ldflags "-w -s -X 'github.com/gojue/ecapture/cli/cmd.GitVersion=$(TARGET_TAG)_$(GOARCH):$(VERSION_NUM):$(VERSION_FLAG)' -X 'github.com/gojue/ecapture/cli/cmd.ByteCodeFiles=$(BYTECODE_FILES)' -linkmode=external -extldflags -static " -o $(OUT_BIN)
$(CMD_GO) build -trimpath -buildmode=pie -mod=readonly -tags '$(TARGET_TAG),netgo' -ldflags "-w -s -X 'github.com/gojue/ecapture/cli/cmd.GitVersion=$(TARGET_TAG)_$(GOARCH):$(VERSION_NUM):$(VERSION_FLAG)' -X 'github.com/gojue/ecapture/cli/cmd.ByteCodeFiles=$(BYTECODE_FILES)' -linkmode=external -extldflags -static " -o $(OUT_BIN)
$(CMD_FILE) $(OUT_BIN)
endef

Expand Down
Loading