55FILE_EXT=' '
66
77export CGO_ENABLED=0
8+ export C_INCLUDE_PATH=/usr/include/bpf
89
910mkdir -p " $OUT_DIR " /bin
1011mkdir -p " $OUT_DIR " /files
@@ -16,3 +17,57 @@ pushd "$REPO_ROOT"/azure-iptables-monitor
1617 -gcflags=" -dwarflocationlists=true" \
1718 .
1819popd
20+
21+ echo " Building azure-block-iptables binary..."
22+
23+ # Debian/Ubuntu
24+ if [[ -f /etc/debian_version ]]; then
25+
26+ apt-get update -y
27+ apt-get install -y --no-install-recommends llvm clang linux-libc-dev linux-headers-generic libbpf-dev libc6-dev nftables iproute2
28+
29+ if [[ $ARCH =~ amd64 ]]; then
30+ apt-get install -y --no-install-recommends gcc-multilib
31+ ARCH_GNU=x86_64-linux-gnu
32+ elif [[ $ARCH =~ arm64 ]]; then
33+ apt-get install -y --no-install-recommends gcc-aarch64-linux-gnu
34+ ARCH_GNU=aarch64-linux-gnu
35+ fi
36+
37+ # Create symlinks for architecture-specific includes
38+ for dir in /usr/include/" $ARCH_GNU " /* ; do
39+ if [[ -d " $dir " || -f " $dir " ]]; then
40+ ln -sfn " $dir " /usr/include/$( basename " $dir " )
41+ fi
42+ done
43+
44+ # Mariner
45+ else
46+ tdnf install -y llvm clang libbpf-devel nftables gcc binutils iproute glibc
47+
48+ if [[ $ARCH =~ amd64 ]]; then
49+ ARCH_GNU=x86_64-linux-gnu
50+ elif [[ $ARCH =~ arm64 ]]; then
51+ ARCH_GNU=aarch64-linux-gnu
52+ fi
53+
54+ # Create symlinks for architecture-specific includes
55+ for dir in /usr/include/" $ARCH_GNU " /* ; do
56+ if [[ -d " $dir " || -f " $dir " ]]; then
57+ ln -sfn " $dir " /usr/include/$( basename " $dir " )
58+ fi
59+ done
60+ fi
61+
62+ pushd " $REPO_ROOT "
63+ # Generate BPF objects
64+ GOOS=" $OS " CGO_ENABLED=0 go generate ./bpf-prog/azure-block-iptables/...
65+
66+ # Build the binary
67+ GOOS=" $OS " CGO_ENABLED=0 go build -a \
68+ -o " $OUT_DIR " /bin/azure-block-iptables" $FILE_EXT " \
69+ -trimpath \
70+ -ldflags " -s -w -X main.version=$AZURE_BLOCK_IPTABLES_VERSION " \
71+ -gcflags=" -dwarflocationlists=true" \
72+ ./bpf-prog/azure-block-iptables/cmd/azure-block-iptables
73+ popd
0 commit comments