From patchwork Tue Oct 31 18:11:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13442163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09E89C4332F for ; Tue, 31 Oct 2023 18:12:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376634AbjJaSML (ORCPT ); Tue, 31 Oct 2023 14:12:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376632AbjJaSMI (ORCPT ); Tue, 31 Oct 2023 14:12:08 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5C96A3; Tue, 31 Oct 2023 11:12:06 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 17B8EC433C7; Tue, 31 Oct 2023 18:12:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698775926; bh=z2kKP0Kx2dr57rizxfyHv38jeggUfLgco7MlYnA5gyE=; h=From:To:Cc:Subject:Date:From; b=dcgLn6vSn6gm14DKigv2Fh7/WSvAoDVEs2UjDpd6TDtwuq09AUWgxPLuVALGPSarp 34pPV1o98F2CmMGKv1QjRC4MCgbmp/iwVdbMpKZNrqe83luuMxboZhO4UfB6+8OyjL rBdjAcFNYmzjGITP4tpy8+ZYse6BTtaook47cxniePiZgjOpyUL3gwJdpKbLmKrrC3 fCvmcd7fUbgKqtBVmvk584Q2SSTL1GhmmLHlUDbGIQgqqQJ7fq2hpGuwWQR15J4Lv+ /x4umGUFK8eagzBKHuMAZYqSWkWwFK8Vr0nuFjZaIJgDFvRTSYOZrbBZCzC5GmJjA2 ZLXnUswjZ8xSg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Jonathan Corbet , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-doc@vger.kernel.org Subject: [PATCH] kbuild: support 'userldlibs' syntax Date: Wed, 1 Nov 2023 03:11:57 +0900 Message-Id: <20231031181157.704314-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org This syntax is useful to specify libraries linked to all userspace programs in the Makefile. Signed-off-by: Masahiro Yamada --- Documentation/kbuild/makefiles.rst | 4 ++++ scripts/Makefile.userprogs | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index d88d4f0f4f89..e9299971220a 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -937,6 +937,10 @@ Example:: # net/bpfilter/Makefile bpfilter_umh-userldflags += -static +To specify libraries linked to a userspace program, you can use +``-userldlibs``. The ``userldlibs`` syntax specifies libraries +linked to all userspace programs created in the current Makefile. + When linking bpfilter_umh, it will be passed the extra option -static. From command line, :ref:`USERCFLAGS and USERLDFLAGS ` will also be used. diff --git a/scripts/Makefile.userprogs b/scripts/Makefile.userprogs index fb415297337a..f3a7e1ef3753 100644 --- a/scripts/Makefile.userprogs +++ b/scripts/Makefile.userprogs @@ -19,19 +19,19 @@ user-cobjs := $(addprefix $(obj)/, $(user-cobjs)) user_ccflags = -Wp,-MMD,$(depfile) $(KBUILD_USERCFLAGS) $(userccflags) \ $($(target-stem)-userccflags) user_ldflags = $(KBUILD_USERLDFLAGS) $(userldflags) $($(target-stem)-userldflags) +user_ldlibs = $(userldlibs) $($(target-stem)-userldlibs) # Create an executable from a single .c file quiet_cmd_user_cc_c = CC [U] $@ cmd_user_cc_c = $(CC) $(user_ccflags) $(user_ldflags) -o $@ $< \ - $($(target-stem)-userldlibs) + $(user_ldlibs) $(user-csingle): $(obj)/%: $(src)/%.c FORCE $(call if_changed_dep,user_cc_c) # Link an executable based on list of .o files quiet_cmd_user_ld = LD [U] $@ cmd_user_ld = $(CC) $(user_ldflags) -o $@ \ - $(addprefix $(obj)/, $($(target-stem)-objs)) \ - $($(target-stem)-userldlibs) + $(addprefix $(obj)/, $($(target-stem)-objs)) $(user_ldlibs) $(user-cmulti): FORCE $(call if_changed,user_ld) $(call multi_depend, $(user-cmulti), , -objs)