examples/ethtool: convert to pkg-config-based build

Remove references to the old DPDK build system from the makefiles, and use
pkg-config provided flags instead.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
This commit is contained in:
Bruce Richardson 2020-09-03 16:26:48 +01:00 committed by Thomas Monjalon
parent 5adbc4b847
commit fa23714eb8
3 changed files with 80 additions and 66 deletions

View File

@ -1,23 +1,11 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2015 Intel Corporation
# Copyright(c) 2015-2020 Intel Corporation
ifeq ($(RTE_SDK),)
$(error "Please define RTE_SDK environment variable")
endif
subdirs := lib ethtool-app
# Default target, detect a build directory, by looking for a path with a .config
RTE_TARGET ?= $(notdir $(abspath $(dir $(firstword $(wildcard $(RTE_SDK)/*/.config)))))
.PHONY: all static shared clean $(subdirs)
all static shared clean: $(subdirs)
include $(RTE_SDK)/mk/rte.vars.mk
ifneq ($(CONFIG_RTE_EXEC_ENV_LINUX),y)
$(info This application can only operate in a linux environment, \
please change the definition of the RTE_TARGET environment variable)
else
DIRS-y += lib ethtool-app
endif
DEPDIRS-ethtool-app := lib
include $(RTE_SDK)/mk/rte.extsubdir.mk
ethtool-app: lib
$(subdirs):
$(MAKE) -C $@ $(MAKECMDGOALS)

View File

@ -1,14 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation
ifeq ($(RTE_SDK),)
$(error "Please define RTE_SDK environment variable")
endif
# Default target, detect a build directory, by looking for a path with a .config
RTE_TARGET ?= $(notdir $(abspath $(dir $(firstword $(wildcard $(RTE_SDK)/*/.config)))))
include $(RTE_SDK)/mk/rte.vars.mk
# Copyright(c) 2010-2020 Intel Corporation
# binary name
APP = ethtool
@ -16,17 +7,40 @@ APP = ethtool
# all source are stored in SRCS-y
SRCS-y := main.c ethapp.c
CFLAGS += -O3 -pthread -I$(SRCDIR)/../lib
CFLAGS += $(WERROR_FLAGS)
CFLAGS += -DALLOW_EXPERIMENTAL_API
CFLAGS += -I../lib
LDFLAGS += -L../lib/build
LDFLAGS_STATIC = -l:librte_ethtool.a
LDFLAGS_SHARED = -lrte_ethtool
LDLIBS += -L$(subst ethtool-app,lib,$(RTE_OUTPUT))/lib
LDLIBS += -lrte_ethtool
ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y)
ifeq ($(CONFIG_RTE_LIBRTE_IXGBE_PMD),y)
LDLIBS += -lrte_pmd_ixgbe
endif
# Build using pkg-config variables if possible
ifneq ($(shell pkg-config --exists libdpdk && echo 0),0)
$(error "no installation of DPDK found")
endif
include $(RTE_SDK)/mk/rte.extapp.mk
all: shared
.PHONY: shared static
shared: build/$(APP)-shared
ln -sf $(APP)-shared build/$(APP)
static: build/$(APP)-static
ln -sf $(APP)-static build/$(APP)
PKGCONF ?= pkg-config
PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)
CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
LDFLAGS_SHARED += $(shell $(PKGCONF) --libs libdpdk)
LDFLAGS_STATIC += $(shell $(PKGCONF) --static --libs libdpdk)
build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build
$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC)
build:
@mkdir -p $@
.PHONY: clean
clean:
rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared
test -d build && rmdir -p build || true

View File

@ -1,37 +1,49 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2015 Intel Corporation
# Copyright(c) 2015-2020 Intel Corporation
ifeq ($(RTE_SDK),)
$(error "Please define RTE_SDK environment variable")
ifneq ($(shell pkg-config --exists libdpdk && echo 0),0)
$(error "no installation of DPDK found")
endif
ifneq ($(shell uname),Linux)
$(error This application can only operate in a linux environment)
endif
# Default target, detect a build directory, by looking for a path with a .config
RTE_TARGET ?= $(notdir $(abspath $(dir $(firstword $(wildcard $(RTE_SDK)/*/.config)))))
include $(RTE_SDK)/mk/rte.vars.mk
ifneq ($(CONFIG_RTE_EXEC_ENV_LINUX),y)
$(error This application can only operate in a linux environment, \
please change the definition of the RTE_TARGET environment variable)
endif
PKGCONF ?= pkg-config
# library name
LIB = librte_ethtool.a
LIBABIVER := 0.1
# all source are stored in SRC-Y
SRCS-y := rte_ethtool.c
LIB = librte_ethtool.so
LIB_STATIC = librte_ethtool.a
SRCS = rte_ethtool.c
CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)
CFLAGS += -fPIC
CFLAGS += -DALLOW_EXPERIMENTAL_API
ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y)
ifeq ($(CONFIG_RTE_LIBRTE_IXGBE_PMD),y)
LDLIBS += -lrte_pmd_ixgbe
endif
endif
LDLIBS += -lrte_eal -lrte_ethdev
PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)
CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk)
LDFLAGS += -Wl,--no-undefined $(LDFLAGS_SHARED)
include $(RTE_SDK)/mk/rte.extlib.mk
# check for ixgbe by grepping pre-processor output
ifneq ($(shell $(CC) $(CFLAGS) -dM -E - < /dev/null | grep IXGBE),)
LDFLAGS += -lrte_pmd_ixgbe
endif
.PHONY: all clean static shared
all shared: build/$(LIB)
static: build/$(LIB_STATIC)
clean:
rm -f build/$(LIB)
test -d build && rmdir -p build || true
build:
@mkdir -p $@
build/%.so: $(SRCS) Makefile $(PC_FILE) | build
$(CC) $(CFLAGS) -o $@ -shared $(SRCS) $(LDFLAGS)
build/%.a: $(SRCS) Makefile $(PC_FILE) | build
$(CC) $(CFLAGS) -c $(SRCS) -o build/$(SRCS).o
$(AR) -cr $@ build/*.o