diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2d591ca..b3571f6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -75,7 +75,7 @@ jobs: - name: Build bpftool, with libbfd, static build run: | make -C src clean - EXTRA_CFLAGS=--static make -j -C src V=1 + EXTRA_LDFLAGS=-static make -j -C src V=1 ./src/bpftool 2>&1 | grep -q Usage ./src/bpftool -p version | \ tee /dev/stderr | \ diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 15548e2..5359931 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -87,7 +87,7 @@ jobs: env: LLVM_PATH: ${{ env[format('LLVM_{0}', matrix.arch)] }} run: | - EXTRA_CFLAGS=--static \ + EXTRA_LDFLAGS=-static \ LLVM_CONFIG="${GITHUB_WORKSPACE}/${{ env.LLVM_PATH }}/bin/llvm-config" \ LLVM_STRIP="${GITHUB_WORKSPACE}/${{ env.LLVM_PATH }}/bin/llvm-strip" \ HOSTAR="${GITHUB_WORKSPACE}/${{ env.LLVM_PATH }}/bin/llvm-ar" \ @@ -112,7 +112,7 @@ jobs: apt-get install -y make pkg-config gcc \ libelf-dev libcap-dev libstdc++-11-dev zlib1g-dev && \ cd /build/bpftool && \ - EXTRA_CFLAGS=--static \ + EXTRA_LDFLAGS=-static \ LLVM_CONFIG='/build/${{ env.LLVM_PATH }}/bin/llvm-config' \ LLVM_STRIP='/build/${{ env.LLVM_PATH }}/bin/llvm-strip' \ CLANG='/build/${{ env.LLVM_PATH }}/bin/clang' \ diff --git a/.github/workflows/static-build.yaml b/.github/workflows/static-build.yaml index 5042da0..4a41e4a 100644 --- a/.github/workflows/static-build.yaml +++ b/.github/workflows/static-build.yaml @@ -43,7 +43,7 @@ jobs: - name: Build bpftool (static build, default LLVM disassembler) working-directory: 'bpftool' run: | - EXTRA_CFLAGS=--static \ + EXTRA_LDFLAGS=-static \ LLVM_CONFIG="${GITHUB_WORKSPACE}/${LLVM_PATH}/bin/llvm-config" \ LLVM_STRIP="${GITHUB_WORKSPACE}/${LLVM_PATH}/bin/llvm-strip" \ make -j -C src V=1 diff --git a/README.md b/README.md index 77054c3..d2b5907 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ example, we can create a static build with the following commands: ```console $ cd src -$ EXTRA_CFLAGS=--static make +$ EXTRA_LDFLAGS=-static make ``` Note that to use the LLVM disassembler with static builds, we need a static @@ -150,12 +150,12 @@ version of the LLVM library installed on the system: $ make -j -C llvm_build llvm-config llvm-libraries ``` -2. Build bpftool with `EXTRA_CFLAGS` set to `--static`, and by passing the +2. Build bpftool with `EXTRA_LDFLAGS` set to `-static`, and by passing the path to the relevant `llvm-config`. ```console $ cd bpftool - $ LLVM_CONFIG=../../llvm_build/bin/llvm-config EXTRA_CFLAGS=--static make -j -C src + $ LLVM_CONFIG=../../llvm_build/bin/llvm-config EXTRA_LDFLAGS=-static make -j -C src ``` ### Build bpftool's man pages diff --git a/src/Makefile.feature b/src/Makefile.feature index b08e7b9..4391ad6 100644 --- a/src/Makefile.feature +++ b/src/Makefile.feature @@ -6,6 +6,9 @@ CFLAGS_BACKUP := $(CFLAGS) CFLAGS := $(EXTRA_CFLAGS) CFLAGS += -Wno-unused-command-line-argument +LDFLAGS_BACKUP := $(LDFLAGS) +LDFLAGS := $(EXTRA_LDFLAGS) + ifeq ($(V),1) LOG=$(warning $(1)) LOG_RES = (echo $(1) && >&2 echo result: $(1)) @@ -43,7 +46,7 @@ LIBBFD_PROBE += ' bfd_demangle(0, 0, 0);' LIBBFD_PROBE += ' return 0;' LIBBFD_PROBE += '}' LIBBFD_PROBE_CMD = printf '%b\n' $(LIBBFD_PROBE) | \ - $(CC) $(CFLAGS) -Wall -Werror -x c -DPACKAGE='"bpftool"' - $(1) -o /dev/null >/dev/null + $(CC) $(CFLAGS) -Wall -Werror -x c -DPACKAGE='"bpftool"' - $(LDFLAGS) $(1) -o /dev/null >/dev/null define libbfd_build $(call detect,$(LIBBFD_PROBE_CMD)) @@ -76,7 +79,7 @@ DISASSEMBLER_PROBE += ' return 0;' DISASSEMBLER_PROBE += '}' DISASSEMBLER_PROBE_CMD = printf '%b\n' $(1) | \ - $(CC) $(CFLAGS) -Wall -Werror -x c -DPACKAGE='"bpftool"' - -lbfd -lopcodes -S -o - >/dev/null + $(CC) $(CFLAGS) -Wall -Werror -x c -DPACKAGE='"bpftool"' - $(LDFLAGS) -lbfd -lopcodes -S -o - >/dev/null define disassembler_build $(call detect,$(DISASSEMBLER_PROBE_CMD)) endef @@ -109,7 +112,7 @@ LIBCAP_PROBE += ' cap_free(0);' LIBCAP_PROBE += ' return 0;' LIBCAP_PROBE += '}' LIBCAP_PROBE_CMD = printf '%b\n' $(LIBCAP_PROBE) | \ - $(CC) $(CFLAGS) -Wall -Werror -x c - -lcap -S -o - >/dev/null + $(CC) $(CFLAGS) -Wall -Werror -x c - $(LDFLAGS) -lcap -S -o - >/dev/null define libcap_build $(call detect,$(LIBCAP_PROBE_CMD)) @@ -130,19 +133,15 @@ LLVM_PROBE += ' LLVMDisposeMessage(triple);' LLVM_PROBE += ' return 0;' LLVM_PROBE += '}' -# We need some adjustments for the flags. -# - $(CFLAGS) was set to parent $(EXTRA_CFLAGS) at the beginning of this file. -# - $(EXTRA_LDFLAGS) from parent Makefile should be kept as well. -# - Libraries to use depend on whether we have a static or shared version of -# LLVM, pass the llvm-config flag and adjust the list of libraries -# accordingly. +# Libraries to use depend on whether we have a static or shared version of +# LLVM, pass the llvm-config flag and adjust the list of libraries accordingly. FEATURE_LLVM_CFLAGS := $(CFLAGS) $(shell $(LLVM_CONFIG) --cflags 2>/dev/null) FEATURE_LLVM_LIBS := $(shell $(LLVM_CONFIG) --libs target 2>/dev/null) ifeq ($(shell $(LLVM_CONFIG) --shared-mode 2>/dev/null),static) FEATURE_LLVM_LIBS += $(shell $(LLVM_CONFIG) --system-libs target 2>/dev/null) FEATURE_LLVM_LIBS += -lstdc++ endif -FEATURE_LDFLAGS := $(EXTRA_LDFLAGS) $(shell $(LLVM_CONFIG) --ldflags 2>/dev/null) +FEATURE_LDFLAGS := $(LDFLAGS) $(shell $(LLVM_CONFIG) --ldflags 2>/dev/null) LLVM_PROBE_CMD = printf '%b\n' $(LLVM_PROBE) | \ $(CC) $(FEATURE_LLVM_CFLAGS) $(FEATURE_LDFLAGS) \ @@ -174,4 +173,5 @@ $(foreach feature,$(filter-out libbfd%,$(FEATURE_DISPLAY)), \ $(call feature_print_status,$(feature-$(feature)),$(feature))) CFLAGS := $(CFLAGS_BACKUP) +LDFLAGS := $(LDFLAGS_BACKUP) undefine LOG LOG_RES