mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] include: kconfig.h: move __is_defined definition into new header
@ 2024-04-03  7:23 Ahmad Fatoum
  2024-04-03  7:23 ` [PATCH 2/2] include: is_defined: implement __if_defined helper Ahmad Fatoum
  2024-04-22 12:16 ` [PATCH 1/2] include: kconfig.h: move __is_defined definition into new header Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2024-04-03  7:23 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

While we run the preprocessor over device trees before compiling them,
we don't define the Kconfig symbols and including <generated/autoconf.h>
would fail.

The file defines __is_defined however, which can be useful for other
macros that are either defined to 1 or undefined like the macros we
define for device tree fragments to indicate which file they are being
appended to. To make it possible to use __is_defined from fragments,
move the kconfig-independent part out of <linux/kconfig.h> into
<linux/is_defined.h>.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/linux/is_defined.h | 37 +++++++++++++++++++++++++++++++++++++
 include/linux/kconfig.h    | 33 +--------------------------------
 2 files changed, 38 insertions(+), 32 deletions(-)
 create mode 100644 include/linux/is_defined.h

diff --git a/include/linux/is_defined.h b/include/linux/is_defined.h
new file mode 100644
index 000000000000..d68f8e877f9b
--- /dev/null
+++ b/include/linux/is_defined.h
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LINUX_IS_DEFINED_H_
+#define __LINUX_IS_DEFINED_H_
+
+#define __ARG_PLACEHOLDER_1 0,
+#define __take_second_arg(__ignored, val, ...) val
+
+/*
+ * The use of "&&" / "||" is limited in certain expressions.
+ * The following enable to calculate "and" / "or" with macro expansion only.
+ */
+#define __and(x, y)			___and(x, y)
+#define ___and(x, y)			____and(__ARG_PLACEHOLDER_##x, y)
+#define ____and(arg1_or_junk, y)	__take_second_arg(arg1_or_junk y, 0)
+
+#define __or(x, y)			___or(x, y)
+#define ___or(x, y)			____or(__ARG_PLACEHOLDER_##x, y)
+#define ____or(arg1_or_junk, y)		__take_second_arg(arg1_or_junk 1, y)
+
+/*
+ * Helper macros to use CONFIG_ options in C/CPP expressions. Note that
+ * these only work with boolean and tristate options.
+ */
+
+/*
+ * Getting something that works in C and CPP for an arg that may or may
+ * not be defined is tricky.  Here, if we have "#define CONFIG_BOOGER 1"
+ * we match on the placeholder define, insert the "0," for arg1 and generate
+ * the triplet (0, 1, 0).  Then the last step cherry picks the 2nd arg (a one).
+ * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
+ * the last step cherry picks the 2nd arg, we get a zero.
+ */
+#define __is_defined(x)			___is_defined(x)
+#define ___is_defined(val)		____is_defined(__ARG_PLACEHOLDER_##val)
+#define ____is_defined(arg1_or_junk)	__take_second_arg(arg1_or_junk 1, 0)
+
+#endif
diff --git a/include/linux/kconfig.h b/include/linux/kconfig.h
index fec5076eda91..58f68adbbadf 100644
--- a/include/linux/kconfig.h
+++ b/include/linux/kconfig.h
@@ -3,38 +3,7 @@
 #define __LINUX_KCONFIG_H
 
 #include <generated/autoconf.h>
-
-#define __ARG_PLACEHOLDER_1 0,
-#define __take_second_arg(__ignored, val, ...) val
-
-/*
- * The use of "&&" / "||" is limited in certain expressions.
- * The following enable to calculate "and" / "or" with macro expansion only.
- */
-#define __and(x, y)			___and(x, y)
-#define ___and(x, y)			____and(__ARG_PLACEHOLDER_##x, y)
-#define ____and(arg1_or_junk, y)	__take_second_arg(arg1_or_junk y, 0)
-
-#define __or(x, y)			___or(x, y)
-#define ___or(x, y)			____or(__ARG_PLACEHOLDER_##x, y)
-#define ____or(arg1_or_junk, y)		__take_second_arg(arg1_or_junk 1, y)
-
-/*
- * Helper macros to use CONFIG_ options in C/CPP expressions. Note that
- * these only work with boolean and tristate options.
- */
-
-/*
- * Getting something that works in C and CPP for an arg that may or may
- * not be defined is tricky.  Here, if we have "#define CONFIG_BOOGER 1"
- * we match on the placeholder define, insert the "0," for arg1 and generate
- * the triplet (0, 1, 0).  Then the last step cherry picks the 2nd arg (a one).
- * When CONFIG_BOOGER is not defined, we generate a (... 1, 0) pair, and when
- * the last step cherry picks the 2nd arg, we get a zero.
- */
-#define __is_defined(x)			___is_defined(x)
-#define ___is_defined(val)		____is_defined(__ARG_PLACEHOLDER_##val)
-#define ____is_defined(arg1_or_junk)	__take_second_arg(arg1_or_junk 1, 0)
+#include <linux/is_defined.h>
 
 /*
  * IS_BUILTIN(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y', 0
-- 
2.39.2




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-22 12:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-03  7:23 [PATCH 1/2] include: kconfig.h: move __is_defined definition into new header Ahmad Fatoum
2024-04-03  7:23 ` [PATCH 2/2] include: is_defined: implement __if_defined helper Ahmad Fatoum
2024-04-22 12:16 ` [PATCH 1/2] include: kconfig.h: move __is_defined definition into new header Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox