examples: warn about broken pkg-config
[dpdk.git] / examples / l2fwd-keepalive / ka-agent / Makefile
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2016-2020 Intel Corporation
3
4 # binary name
5 APP = ka-agent
6
7 # all source are stored in SRCS-y
8 SRCS-y := main.c
9
10 CFLAGS += -I..
11
12 # Build using pkg-config variables if possible
13 ifneq ($(shell pkg-config --exists libdpdk && echo 0),0)
14 $(error "no installation of DPDK found")
15 endif
16
17 all: shared
18 .PHONY: shared static
19 shared: build/$(APP)-shared
20         ln -sf $(APP)-shared build/$(APP)
21 static: build/$(APP)-static
22         ln -sf $(APP)-static build/$(APP)
23
24 LDFLAGS += -lpthread -lrt
25
26 PKGCONF ?= pkg-config
27
28 PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)
29 CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
30 LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk)
31 LDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk)
32
33 ifeq ($(MAKECMDGOALS),static)
34 # check for broken pkg-config
35 ifeq ($(shell echo $(LDFLAGS_STATIC) | grep 'whole-archive.*l:lib.*no-whole-archive'),)
36 $(warning "pkg-config output list does not contain drivers between 'whole-archive'/'no-whole-archive' flags.")
37 $(error "Cannot generate statically-linked binaries with this version of pkg-config")
38 endif
39 endif
40
41 CFLAGS += -DALLOW_EXPERIMENTAL_API
42
43 build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
44         $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
45
46 build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build
47         $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC)
48
49 build:
50         @mkdir -p $@
51
52 .PHONY: clean
53 clean:
54         rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared
55         test -d build && rmdir -p build || true