xref: /dpdk/examples/vhost/Makefile (revision 53d3f477)
13998e2a0SBruce Richardson# SPDX-License-Identifier: BSD-3-Clause
23998e2a0SBruce Richardson# Copyright(c) 2010-2014 Intel Corporation
3b82da759SHuawei Xie
40eba4adeSBruce Richardson# binary name
50eba4adeSBruce RichardsonAPP = vhost-switch
60eba4adeSBruce Richardson
70eba4adeSBruce Richardson# all source are stored in SRCS-y
8*53d3f477SJiayu HuSRCS-y := main.c virtio_net.c
90eba4adeSBruce Richardson
1011e02702SJerin JacobPKGCONF ?= pkg-config
1111e02702SJerin Jacob
1222119c45SBruce Richardson# Build using pkg-config variables if possible
1311e02702SJerin Jacobifneq ($(shell $(PKGCONF) --exists libdpdk && echo 0),0)
14fda34680SCiara Power$(error "no installation of DPDK found")
15fda34680SCiara Powerendif
1622119c45SBruce Richardson
171842d194SBruce Richardsonall: shared
181842d194SBruce Richardson.PHONY: shared static
191842d194SBruce Richardsonshared: build/$(APP)-shared
201842d194SBruce Richardson	ln -sf $(APP)-shared build/$(APP)
211842d194SBruce Richardsonstatic: build/$(APP)-static
221842d194SBruce Richardson	ln -sf $(APP)-static build/$(APP)
2322119c45SBruce Richardson
241842d194SBruce RichardsonLDFLAGS += -pthread
251842d194SBruce Richardson
2669b1bb49SBruce RichardsonPC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)
27ca926852SBruce RichardsonCFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
28ca926852SBruce RichardsonLDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk)
298549295dSBruce RichardsonLDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk)
301842d194SBruce Richardson
315a196330SBruce Richardsonifeq ($(MAKECMDGOALS),static)
325a196330SBruce Richardson# check for broken pkg-config
335a196330SBruce Richardsonifeq ($(shell echo $(LDFLAGS_STATIC) | grep 'whole-archive.*l:lib.*no-whole-archive'),)
345a196330SBruce Richardson$(warning "pkg-config output list does not contain drivers between 'whole-archive'/'no-whole-archive' flags.")
355a196330SBruce Richardson$(error "Cannot generate statically-linked binaries with this version of pkg-config")
365a196330SBruce Richardsonendif
375a196330SBruce Richardsonendif
385a196330SBruce Richardson
398728ccf3SThomas MonjalonCFLAGS += -DALLOW_EXPERIMENTAL_API
408728ccf3SThomas Monjalon
411842d194SBruce Richardsonbuild/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
421842d194SBruce Richardson	$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
431842d194SBruce Richardson
441842d194SBruce Richardsonbuild/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build
451842d194SBruce Richardson	$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC)
4622119c45SBruce Richardson
4722119c45SBruce Richardsonbuild:
4822119c45SBruce Richardson	@mkdir -p $@
4922119c45SBruce Richardson
5022119c45SBruce Richardson.PHONY: clean
5122119c45SBruce Richardsonclean:
521842d194SBruce Richardson	rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared
537e9562a1SBruce Richardson	test -d build && rmdir -p build || true
54