13998e2a0SBruce Richardson# SPDX-License-Identifier: BSD-3-Clause
225d3438cSKevin Laatz# Copyright(c) 2016-2020 Intel Corporation
3ed2a80fdSPablo de Lara
4ed2a80fdSPablo de Lara# binary name
5ed2a80fdSPablo de LaraAPP = server
6ed2a80fdSPablo de Lara
7ed2a80fdSPablo de Lara# all source are stored in SRCS-y
8ed2a80fdSPablo de LaraSRCS-y := main.c init.c args.c
9ed2a80fdSPablo de Lara
1025d3438cSKevin LaatzCFLAGS += -I../shared
11ed2a80fdSPablo de Lara
12*11e02702SJerin JacobPKGCONF ?= pkg-config
13*11e02702SJerin Jacob
1425d3438cSKevin Laatz# Build using pkg-config variables if possible
15*11e02702SJerin Jacobifneq ($(shell $(PKGCONF) --exists libdpdk && echo 0),0)
1625d3438cSKevin Laatz$(error "no installation of DPDK found")
1725d3438cSKevin Laatzendif
18ed2a80fdSPablo de Lara
1925d3438cSKevin Laatzall: shared
2025d3438cSKevin Laatz.PHONY: shared static
2125d3438cSKevin Laatzshared: build/$(APP)-shared
2225d3438cSKevin Laatz	ln -sf $(APP)-shared build/$(APP)
2325d3438cSKevin Laatzstatic: build/$(APP)-static
2425d3438cSKevin Laatz	ln -sf $(APP)-static build/$(APP)
2525d3438cSKevin Laatz
2625d3438cSKevin LaatzPC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)
2725d3438cSKevin LaatzCFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
2825d3438cSKevin LaatzLDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk)
2925d3438cSKevin LaatzLDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk)
3025d3438cSKevin Laatz
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
39bc8e3247SDavid MarchandCFLAGS += -DALLOW_EXPERIMENTAL_API
40bc8e3247SDavid Marchand
4125d3438cSKevin Laatzbuild/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
4225d3438cSKevin Laatz	$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
4325d3438cSKevin Laatz
4425d3438cSKevin Laatzbuild/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build
4525d3438cSKevin Laatz	$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC)
4625d3438cSKevin Laatz
4725d3438cSKevin Laatzbuild:
4825d3438cSKevin Laatz	@mkdir -p $@
4925d3438cSKevin Laatz
5025d3438cSKevin Laatz.PHONY: clean
5125d3438cSKevin Laatzclean:
5225d3438cSKevin Laatz	rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared
5325d3438cSKevin Laatz	test -d build && rmdir -p build || true
54