Skip to content

Commit

Permalink
Modified makefile to enable cross-compilation on x86_64 hosts for arm…
Browse files Browse the repository at this point in the history
…64 platform.
  • Loading branch information
dirk29 committed May 16, 2024
1 parent ae4bd23 commit d2adb08
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
22 changes: 21 additions & 1 deletion .github/workflows/kflowd-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ jobs:
sudo rm -f /usr/bin/llvm-strip
sudo ln -s /usr/bin/llvm-strip-16 /usr/bin/llvm-strip
- name: 'Prepare Cross-Compilation'
run: |
sudo apt install gcc-aarch64-linux-gnu
sudo dpkg --add-architecture arm64
sudo sed -i 's/^deb http/deb [arch=amd64,i386] http/g' /etc/apt/sources.list
# remove later
cat /etc/apt/sources.list
echo "deb [arch=arm64] http://ports.ubuntu.com/ focal main multiverse universe" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=arm64] http://ports.ubuntu.com/ focal-security main multiverse universe" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=arm64] http://ports.ubuntu.com/ focal-backports main multiverse universe" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=arm64] http://ports.ubuntu.com/ focal-updates main multiverse universe" | sudo tee -a /etc/apt/sources.list
sudo apt update || true
sudo apt install libelf1:arm64
sudo apt install libz3-4:arm64
cd /usr/lib/aarch64-linux-gnu/
# remove later
sudo ls -la
sudo ln -s libelf.so.1 libelf.so
sudo ln -s libz.so.1 libz.so
- name: 'Clone Repository'
uses: actions/checkout@v4
with:
Expand All @@ -48,7 +68,7 @@ jobs:
run: |
cd src
sudo echo -e "deb [trusted=yes] https://repo.goreleaser.com/apt/ /" | sudo tee /etc/apt/sources.list.d/goreleaser.list
sudo apt update
sudo apt update || true
sudo apt install nfpm
make deb
make rpm
Expand Down
2 changes: 1 addition & 1 deletion plugins
13 changes: 8 additions & 5 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ LIBBPF_SRC := $(abspath ../libbpf/src)
LIBBPF_OBJ := $(abspath $(OUTPUT)/libbpf.a)
BINDIR := ../bin/
ARCH := $(shell uname -m | sed 's/x86_64/x86/' | sed 's/aarch64/arm64/')
BPFTOOL ?= $(abspath ../vmlinux/$(ARCH)/bpftool)
BPFTOOL := $(abspath ../vmlinux/$(ARCH)/bpftool)
ifeq ($(CROSS_COMPILE),aarch64-linux-gnu-)
ARCH := arm64
endif
VMLINUX := ../vmlinux/$(ARCH)/vmlinux.h
GIT_VERSION := $(shell git describe --abbrev=4 --dirty --always --tags | cut -d '-' -f 1,2,4 | sed 's/-/./1')
GLIBC_VERSION := ${shell ldd --version | head -n 1 | cut -d ')' -f2}
Expand All @@ -23,7 +26,7 @@ LIBBPF_VERSION := ${shell git submodule status ../libbpf | cut -d ' ' -f 4 | sed
DATETIME := $(shell date +'%b-%d-%Y_%H:%M:%S%z')
INCLUDES := -I$(OUTPUT) -I../libbpf/include/uapi -I$(dir $(VMLINUX))
CFLAGS := -Wextra -g -std=gnu99 -Wall -DDATETIME=\"$(DATETIME)\" -DVERSION=\"$(GIT_VERSION)\"\
-DCLANG_VERSION=\"$(CLANG_VERSION)\" -DLIBBPF_VERSION=\"$(LIBBPF_VERSION)\"
-D ARCH=\"$(ARCH)\" -DCLANG_VERSION=\"$(CLANG_VERSION)\" -DLIBBPF_VERSION=\"$(LIBBPF_VERSION)\"
CLANG_CHECKS := --checks=-*,clang-analyzer-*,-clang-analyzer-cplusplus* --warnings-as-errors=*
LDFLAGS := -ldl
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)
Expand Down Expand Up @@ -51,7 +54,7 @@ define allow-override
$(eval $(1) = $(2)))
endef

$(call allow-override,CC,$(CROSS_COMPILE)cc)
$(call allow-override,CC,$(CROSS_COMPILE)gcc)
$(call allow-override,LD,$(CROSS_COMPILE)ld)

.PHONY: all
Expand Down Expand Up @@ -124,7 +127,7 @@ export NFPM_PRE
export NFPM_POST

rpm deb: $(APPS)
$(eval PACKAGE_ARCH := $(shell uname -m | if test $@ = 'deb'; then sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/'; else cat; fi))
$(eval PACKAGE_ARCH := $(shell echo $(ARCH) | if test 'deb' = 'deb'; then sed 's/x86/amd64/'; else sed 's/x86/x86_64/' | sed 's/arm64/aarch64/'; fi))
$(eval PACKAGE_VERSION := $(shell ../bin/kflowd --version | cut -d ' ' -f2))
$(Q)echo "$$NFPM" > nfpm.yaml
$(Q)echo "$$NFPM_PRE" > preinstall.sh
Expand All @@ -140,7 +143,7 @@ $(OUTPUT) $(OUTPUT)/libbpf:

# Build libbpf
$(LIBBPF_OBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf
$(Q)$(MAKE) -C $(LIBBPF_SRC) BUILD_STATIC_ONLY=1\
$(Q)$(MAKE) CROSS_COMPILE=$(CROSS_COMPILE)g -C $(LIBBPF_SRC) BUILD_STATIC_ONLY=1\
OBJDIR=$(dir $@)libbpf DESTDIR=$(dir $@)\
INCLUDEDIR= LIBDIR= UAPIDIR=\
install
Expand Down
4 changes: 2 additions & 2 deletions src/kflowd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1263,8 +1263,8 @@ int main(int argc, char **argv) {
char dt[DATETIME_LEN_MAX];
strncpy(dt, DATETIME, DATETIME_LEN_MAX);
dt[11] = 0x20;
fprintf(stdout, "kflowd " VERSION " (built %s, Linux %s, clang %s, glibc %u.%u, libbpf %s)\n", dt,
utsn.release, CLANG_VERSION, __GLIBC__, __GLIBC_MINOR__, LIBBPF_VERSION);
fprintf(stdout, "kflowd " VERSION " (built %s, Linux %s, %s, clang %s, glibc %u.%u, libbpf %s)\n", dt,
utsn.release, ARCH, CLANG_VERSION, __GLIBC__, __GLIBC_MINOR__, LIBBPF_VERSION);
}
return 0;
case '?':
Expand Down
Binary file modified vmlinux/arm64/bpftool
Binary file not shown.

0 comments on commit d2adb08

Please sign in to comment.