Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 | \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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' \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions src/Makefile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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) \
Expand Down Expand Up @@ -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
Loading