From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A60EC43381 for ; Thu, 28 Mar 2019 11:34:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C81832075E for ; Thu, 28 Mar 2019 11:34:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="I1rjczkL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726550AbfC1LeC (ORCPT ); Thu, 28 Mar 2019 07:34:02 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:43358 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726234AbfC1LeC (ORCPT ); Thu, 28 Mar 2019 07:34:02 -0400 Received: by mail-wr1-f66.google.com with SMTP id k17so14479658wrx.10 for ; Thu, 28 Mar 2019 04:34:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z3BjxygZm0Gq+/tSBgxJS0o/K1H9Uj0ttyCNbXxNAqY=; b=I1rjczkLBqBSvcQXdVmSFGK1AOv4FAqO3+nyPETNPHrnecyEYBoGWsyHEtHec4r8l9 w3gxTRB2I0lQnt39b2yHhONQTD6bi/9KqYQ1+PGW4z5u3AATFqTOOdgJsHsSsxwPDaTZ axyE+yj/Mm+4tjFTZ0WmSy6WDXoqvjlhynm8zHS6x/HKY91X3+ZVEyaY8dPZ2G3LLImp MW3oKLCEW2OXAf8imlvfdOJvBUrlmm89lcjqg8pOVbPmJN2rJeck5fgRiwyMZYXVeFmQ FshSALie+g5pTok+h1EE4Vtodc1xRpD2idW/uJ3fvCIoOkPJe16oO2/GKMS7JODXPKRw louA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z3BjxygZm0Gq+/tSBgxJS0o/K1H9Uj0ttyCNbXxNAqY=; b=huDt1jEICdzBuEzxsv7iYgEas2PSeXCc4UB/u37zA8o2QtokiAU5cJmG1324/FBnWd y2B8RIwDYHsc1+gFN3Oky+X2XoUigPGA6h8MQJda4HtjxaiG8tmgtQuuHYcyEUgBxSTh UoZlwdFiPxqYkXmzeQYP5NL1Brau+EgsQJ+GkDMvKEcVI2BJTM5mjS0eSfIhjP0aoglY 19GNPyAaqWEdarG2g9kqxLaEPvLX1DTu24J/cEOEY9x1EA8BBp3ISXv5e5+vpiQpgu26 Za24pof8TemDckVitZKmPCgC/cU7hzA7SyxRS5IURztGmJo01f9tphPqfc0J9IIptP6i ld/g== X-Gm-Message-State: APjAAAUqC6PV/B0SoxRdhVVJCC3Xp/zoxolTU9olKXd44U23DoTfpfEw cxmr/0PoAIVgAoWrqm6TuVw30eX4 X-Google-Smtp-Source: APXvYqxjYBGtNYeJ7Y1tm5WcxpUeAPn56kO9AZasPKQJ3sqNj/nWzVc1Dg0VhNBRN9qF3vkIeLbqUA== X-Received: by 2002:a5d:4887:: with SMTP id g7mr27061142wrq.51.1553772839917; Thu, 28 Mar 2019 04:33:59 -0700 (PDT) Received: from localhost ([2a01:4b00:f419:6f00:b00c:66c8:99df:336]) by smtp.gmail.com with ESMTPSA id d4sm2089564wrv.42.2019.03.28.04.33.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Mar 2019 04:33:59 -0700 (PDT) From: luca.boccassi@gmail.com To: netdev@vger.kernel.org Cc: alexei.starovoitov@gmail.com Subject: [PATCH bpf-next v8] tools/bpf: generate pkg-config file for libbpf Date: Thu, 28 Mar 2019 11:33:53 +0000 Message-Id: <20190328113353.20936-1-luca.boccassi@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190319210639.6282-1-bluca@debian.org> References: <20190319210639.6282-1-bluca@debian.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Luca Boccassi Generate a libbpf.pc file at build time so that users can rely on pkg-config to find the library, its CFLAGS and LDFLAGS. Signed-off-by: Luca Boccassi Acked-by: Andrey Ignatov --- v2: use QUIET_GEN instead of QUIET_LINK to generate pc file, save kernel version in its own variable instead of calling make inline v3: use LIBBPF_VERSION instead of kernel_version v4: use -I${prefix}/include rather than -I${prefix}/include/bpf in the Cflags field as requested, to keep consistency with how the headers are used now and to avoid a dependency from the pc file to the headers installation v5: add acked-by, add SPDX line to pc file v6: remove URL field, generalize Description field v7: fix build with make OUTPUT=/foo/bar/ by prefixing $(OUTPUT) to the pc file variable v8: rebased on latest bpf-next to solve merge conflict (not that indentation looks wrong on 2 lines because the "+" added by the diff makes the first tab start at the 8th column rather than the 7th, it align once applied though) tools/lib/bpf/.gitignore | 1 + tools/lib/bpf/Makefile | 19 ++++++++++++++++--- tools/lib/bpf/libbpf.pc.template | 12 ++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 tools/lib/bpf/libbpf.pc.template diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore index 4db74758c674..7d9e182a1f51 100644 --- a/tools/lib/bpf/.gitignore +++ b/tools/lib/bpf/.gitignore @@ -1,3 +1,4 @@ libbpf_version.h +libbpf.pc FEATURE-DUMP.libbpf test_libbpf diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile index 5bf8e52c41fc..0fe54fe4cc04 100644 --- a/tools/lib/bpf/Makefile +++ b/tools/lib/bpf/Makefile @@ -90,6 +90,7 @@ LIBBPF_VERSION = $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION) LIB_TARGET = libbpf.a libbpf.so.$(LIBBPF_VERSION) LIB_FILE = libbpf.a libbpf.so* +PC_FILE = libbpf.pc # Set compile option CFLAGS ifdef EXTRA_CFLAGS @@ -134,13 +135,14 @@ VERSION_SCRIPT := libbpf.map LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET)) LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE)) +PC_FILE := $(addprefix $(OUTPUT),$(PC_FILE)) GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN) | \ awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {s++} END{print s}') VERSIONED_SYM_COUNT = $(shell readelf -s --wide $(OUTPUT)libbpf.so | \ grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l) -CMD_TARGETS = $(LIB_TARGET) +CMD_TARGETS = $(LIB_TARGET) $(PC_FILE) CXX_TEST_TARGET = $(OUTPUT)test_libbpf @@ -187,6 +189,12 @@ $(OUTPUT)libbpf.a: $(BPF_IN) $(OUTPUT)test_libbpf: test_libbpf.cpp $(OUTPUT)libbpf.a $(QUIET_LINK)$(CXX) $(INCLUDES) $^ -lelf -o $@ +$(OUTPUT)libbpf.pc: + $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \ + -e "s|@LIBDIR@|$(libdir_SQ)|" \ + -e "s|@VERSION@|$(LIBBPF_VERSION)|" \ + < libbpf.pc.template > $@ + check: check_abi check_abi: $(OUTPUT)libbpf.so @@ -223,7 +231,12 @@ install_headers: $(call do_install,libbpf.h,$(prefix)/include/bpf,644); $(call do_install,btf.h,$(prefix)/include/bpf,644); -install: install_lib +install_pkgconfig: $(PC_FILE) + $(call QUIET_INSTALL, $(PC_FILE)) \ + $(call do_install,$(PC_FILE),$(libdir_SQ)/pkgconfig,644) + + +install: install_lib install_pkgconfig ### Cleaning rules @@ -233,7 +246,7 @@ config-clean: clean: $(call QUIET_CLEAN, libbpf) $(RM) $(TARGETS) $(CXX_TEST_TARGET) \ - *.o *~ *.a *.so *.so.$(VERSION) .*.d .*.cmd LIBBPF-CFLAGS + *.o *~ *.a *.so *.so.$(VERSION) .*.d .*.cmd *.pc LIBBPF-CFLAGS $(call QUIET_CLEAN, core-gen) $(RM) $(OUTPUT)FEATURE-DUMP.libbpf diff --git a/tools/lib/bpf/libbpf.pc.template b/tools/lib/bpf/libbpf.pc.template new file mode 100644 index 000000000000..ac17fcef2108 --- /dev/null +++ b/tools/lib/bpf/libbpf.pc.template @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) + +prefix=@PREFIX@ +libdir=@LIBDIR@ +includedir=${prefix}/include + +Name: libbpf +Description: BPF library +Version: @VERSION@ +Libs: -L${libdir} -lbpf +Requires.private: libelf +Cflags: -I${includedir} -- 2.20.1