examples: warn about broken pkg-config
[dpdk.git] / examples / performance-thread / pthread_shim / Makefile
1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright(c) 2010-2020 Intel Corporation
3
4 # binary name
5 APP = lthread_pthread_shim
6
7 # all source are stored in SRCS-y
8 SRCS-y := main.c pthread_shim.c
9
10 include ../common/common.mk
11
12 ifeq ($(MAKECMDGOALS),static)
13 # check for broken pkg-config
14 ifeq ($(shell echo $(LDFLAGS_STATIC) | grep 'whole-archive.*l:lib.*no-whole-archive'),)
15 $(warning "pkg-config output list does not contain drivers between 'whole-archive'/'no-whole-archive' flags.")
16 $(error "Cannot generate statically-linked binaries with this version of pkg-config")
17 endif
18 endif
19
20 CFLAGS += -DALLOW_EXPERIMENTAL_API
21 CFLAGS += -D_GNU_SOURCE
22 LDFLAGS += "-Wl,--copy-dt-needed-entries"
23
24 # Build using pkg-config variables if possible
25 ifneq ($(shell pkg-config --exists libdpdk && echo 0),0)
26 $(error "no installation of DPDK found")
27 endif
28
29 all: shared
30 .PHONY: shared static
31 shared: build/$(APP)-shared
32         ln -sf $(APP)-shared build/$(APP)
33 static: build/$(APP)-static
34         ln -sf $(APP)-static build/$(APP)
35
36 LDFLAGS += -lpthread
37
38 PKGCONF ?= pkg-config
39
40 PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)
41 CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
42 LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk)
43 LDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk)
44
45 build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
46         $(CC) $(CFLAGS) $(filter %.c,$^) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
47
48 build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build
49         $(CC) $(CFLAGS) $(filter %.c,$^) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
50
51 # workaround for a gcc bug with noreturn attribute
52 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
53 ifeq ($(shell gcc -dumpversion),-gt 0)
54 CFLAGS_main.o += -Wno-return-type
55 endif
56
57 build:
58         @mkdir -p $@
59
60 .PHONY: clean
61 clean:
62         rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared
63         test -d build && rmdir -p build || true