From patchwork Wed Oct 28 13:25:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hangbin Liu X-Patchwork-Id: 316142 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=-12.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, 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 13874C55179 for ; Wed, 28 Oct 2020 22:27:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B07B0206F4 for ; Wed, 28 Oct 2020 22:27:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="M0QDX0c4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387408AbgJ1W1m (ORCPT ); Wed, 28 Oct 2020 18:27:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42853 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733255AbgJ1W1d (ORCPT ); Wed, 28 Oct 2020 18:27:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603924051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B3C3SM+mTODeDpoZqXrRuy+dLn2cT9haezbBAbLVhV4=; b=M0QDX0c40fx9XLvhMyS1nM60RvSyg/9MAXcv41EvRmRIF71mAB5DDDhfMNcmDmmLp/3b9e yHQAD11vyl2smESUB8tXy7l3QZ7Km8izlKqJXt9rUjU+t0IV3zhT/PU+a65hU7oQDrn4GL A5vUfWwd/Fa+eL6Q1Q+2yBfDg0/oI2c= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-10-ZYr4fzDHNXqk6ZUSWUOpAw-1; Wed, 28 Oct 2020 09:25:52 -0400 X-MC-Unique: ZYr4fzDHNXqk6ZUSWUOpAw-1 Received: by mail-pl1-f199.google.com with SMTP id v4so96196ply.7 for ; Wed, 28 Oct 2020 06:25:52 -0700 (PDT) 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=B3C3SM+mTODeDpoZqXrRuy+dLn2cT9haezbBAbLVhV4=; b=GdfUAbvySDfDUYYHq9lLXak5XN1XjPVyqzWwcYA8IYaXYev3ZQJ6iYRYpIhHu84e8Q I92o99xfGkJP55Tr1sKSa2qDmjGoyFojAsvGvq/CfQRBHPa9ncx9CKjRUQGX5XLj01aI lpdVioqd6cUx0aCT6oToxMhUJQYgOuHDC2phV51jY85k0FP39RlyZiBf8xtn9SU8zIo2 ZQtCCQP5oBhFBXGJOrENrW0iAEa6t6g+E3t+0IqPV/Qm0I3NknhiIB3pDh6uCGh81ZaT oOUHRpVBIXRTsctVvjDyKr3ghfLuXmBfbrYeZs0815nQQP7DBDeMtDtMLXwtkZg+fQwZ nSxw== X-Gm-Message-State: AOAM532RWLYM2whQ9DfXsalPndGzSslArwtwAuuIKG78OafUC19ESKBk Swg9f/B8b83x8h3vCUn3SA4CtOJc5Xvi4+M/T64b3jOWGsFY5uBvUKT7pWX0w4W+ASg2vadJ/Dl qchunjsERHf50C40= X-Received: by 2002:a63:e34e:: with SMTP id o14mr2981915pgj.346.1603891549935; Wed, 28 Oct 2020 06:25:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/PK76b2eGaNlxeNSUA51cw16WWFm9l0JQrjl8/wv7GEAT2h/MGYx3BNITB72kZx5M/I/8XQ== X-Received: by 2002:a63:e34e:: with SMTP id o14mr2981886pgj.346.1603891549718; Wed, 28 Oct 2020 06:25:49 -0700 (PDT) Received: from localhost.localdomain.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id z20sm6055521pfk.199.2020.10.28.06.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 06:25:49 -0700 (PDT) From: Hangbin Liu To: Stephen Hemminger , Daniel Borkmann , David Ahern , Alexei Starovoitov Cc: Martin KaFai Lau , Song Liu , Yonghong Song , David Miller , Jesper Dangaard Brouer , netdev@vger.kernel.org, bpf@vger.kernel.org, Jiri Benc , Andrii Nakryiko , =?utf-8?q?Toke_H=C3=B8ila?= =?utf-8?q?nd-J=C3=B8rgensen?= , Hangbin Liu Subject: [PATCHv2 iproute2-next 1/5] configure: add check_libbpf() for later libbpf support Date: Wed, 28 Oct 2020 21:25:25 +0800 Message-Id: <20201028132529.3763875-2-haliu@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201028132529.3763875-1-haliu@redhat.com> References: <20201023033855.3894509-1-haliu@redhat.com> <20201028132529.3763875-1-haliu@redhat.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch adds a check to see if we support libbpf. By default the system libbpf will be used, but static linking against a custom libbpf version can be achieved by passing LIBBPF_DIR to configure. FORCE_LIBBPF can be set to force configure to abort if no suitable libbpf is found, which is useful for automatic packaging that wants to enforce the dependency. Reviewed-by: Toke Høiland-Jørgensen Signed-off-by: Hangbin Liu --- configure | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/configure b/configure index 307912aa..77f475d9 100755 --- a/configure +++ b/configure @@ -240,6 +240,51 @@ check_elf() fi } +check_libbpf() +{ + if ${PKG_CONFIG} libbpf --exists || [ -n "$LIBBPF_DIR" ] ; then + + if [ -n "$LIBBPF_DIR" ]; then + LIBBPF_CFLAGS="-I${LIBBPF_DIR}/include -L${LIBBPF_DIR}/lib64" + LIBBPF_LDLIBS="${LIBBPF_DIR}/lib64/libbpf.a -lz -lelf" + else + LIBBPF_CFLAGS=$(${PKG_CONFIG} libbpf --cflags) + LIBBPF_LDLIBS=$(${PKG_CONFIG} libbpf --libs) + fi + + cat >$TMPDIR/libbpftest.c < +int main(int argc, char **argv) { + void *ptr; + DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts, .relaxed_maps = true, .pin_root_path = "/path"); + (void) bpf_object__open_file("file", &opts); + (void) bpf_map__name(ptr); + (void) bpf_map__ifindex(ptr); + (void) bpf_map__reuse_fd(ptr, 0); + (void) bpf_map__pin(ptr, "/path"); + return 0; +} +EOF + + if $CC -o $TMPDIR/libbpftest $TMPDIR/libbpftest.c $LIBBPF_CFLAGS -lbpf 2>&1; then + echo "HAVE_LIBBPF:=y" >>$CONFIG + echo 'CFLAGS += -DHAVE_LIBBPF ' $LIBBPF_CFLAGS >> $CONFIG + echo 'LDLIBS += ' $LIBBPF_LDLIBS >>$CONFIG + echo "yes" + return 0 + fi + fi + + echo "no" + + # if set FORCE_LIBBPF but no libbpf support, just exist the config + # process to make sure we don't build without libbpf. + if [ -n "$FORCE_LIBBPF" ]; then + echo "FORCE_LIBBPF set, but couldn't find a usable libbpf" + exit 1 + fi +} + check_selinux() # SELinux is a compile time option in the ss utility { @@ -385,6 +430,9 @@ check_setns echo -n "SELinux support: " check_selinux +echo -n "libbpf support: " +check_libbpf + echo -n "ELF support: " check_elf