From patchwork Sun Sep 17 19:19:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 13388633 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 81F21CD13D2 for ; Sun, 17 Sep 2023 19:20:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231166AbjIQTUa (ORCPT ); Sun, 17 Sep 2023 15:20:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231801AbjIQTUW (ORCPT ); Sun, 17 Sep 2023 15:20:22 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 201A8115; Sun, 17 Sep 2023 12:20:17 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66821C433C9; Sun, 17 Sep 2023 19:20:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694978416; bh=zlezv61pkEtIb39QJV+KksqxpQMU0fbcIUj51bSEwrY=; h=From:To:Cc:Subject:Date:From; b=oIzJcm+yqSjU0N+/nDHU6W2dBiG4y1dTlpVyxYVZl0TvEkebI5Rsm40kS+rbblFIW J9xYHqsfQSEGE/hrzWSnkCdsJc14eqkd2Z6cYnhuD2DqR3KVwaVBv1ceygvjxD7mp0 uSsZ9ztBuXxelRCElu1PTfkmN1VXpCVK1alE09zCaD6Ea3nwiJToHlkkSga0AmfxZF kJgY8RZB3FIxnaemnt6Qai0L4mOWctRk2BrqAUoNF6zQgCQJGZ894J/ExJ4LauKIxE 23CBrwm9tnAbGXXh1B2eSPvGstmkbum93JCxt3rbGQriU32RhBdOPt18egKTEpabXP kIIlN/4gJDHQQ== From: Arnd Bergmann To: Masahiro Yamada , Jonathan Corbet Cc: Arnd Bergmann , Javier Martinez Canillas , Sakari Ailus , Nicolas Schier , Nathan Chancellor , Nick Desaulniers , linux-kbuild@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] Documentation: kbuild: explain handling optional dependencies Date: Sun, 17 Sep 2023 21:19:59 +0200 Message-Id: <20230917192009.254979-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org From: Arnd Bergmann This problem frequently comes up in randconfig testing, with drivers failing to link because of a dependency on an optional feature. The Kconfig language for this is very confusing, so try to document it in "Kconfig hints" section. Reviewed-by: Javier Martinez Canillas Reviewed-by: Sakari Ailus Reviewed-by: Nicolas Schier Signed-off-by: Arnd Bergmann --- v2: fix typos pointed out by Nicolas Schier --- Documentation/kbuild/kconfig-language.rst | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Documentation/kbuild/kconfig-language.rst b/Documentation/kbuild/kconfig-language.rst index 858ed5d80defe..0135905c0aa35 100644 --- a/Documentation/kbuild/kconfig-language.rst +++ b/Documentation/kbuild/kconfig-language.rst @@ -573,6 +573,32 @@ above, leading to: bool "Support for foo hardware" depends on ARCH_FOO_VENDOR || COMPILE_TEST +Optional dependencies +~~~~~~~~~~~~~~~~~~~~~ + +Some drivers are able to optionally use a feature from another module +or build cleanly with that module disabled, but cause a link failure +when trying to use that loadable module from a built-in driver. + +The most common way to express this optional dependency in Kconfig logic +uses the slightly counterintuitive:: + + config FOO + tristate "Support for foo hardware" + depends on BAR || !BAR + +This means that there is either a dependency on BAR that disallows +the combination of FOO=y with BAR=m, or BAR is completely disabled. +For a more formalized approach if there are multiple drivers that have +the same dependency, a helper symbol can be used, like:: + + config FOO + tristate "Support for foo hardware" + depends on BAR_OPTIONAL + + config BAR_OPTIONAL + def_tristate BAR || !BAR + Kconfig recursive dependency limitations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~