compat: backport IS_ENABLED macro
authorEliad Peller <eliad@wizery.com>
Wed, 16 May 2012 15:28:00 +0000 (18:28 +0300)
committerLuis R. Rodriguez <mcgrof@frijolero.org>
Wed, 16 May 2012 20:32:46 +0000 (13:32 -0700)
IS_ENABLED(option) was backported as defined(option), but
because of the indirection, option was evaluated too early,
resulting in #if defined(1) for defined options, which failed
the compilation with the following error:

error: operator "defined" requires an identifier

Backport IS_ENABLED from the current kernel instead.

mcgrof@tux ~/compat (git::master)$ ckmake
Trying kernel                  3.4.0-030400rc1-generic [OK]
Trying kernel                  3.3.0-030300rc2-generic [OK]
Trying kernel                     3.2.2-030202-generic [OK]
Trying kernel                    3.1.10-030110-generic [OK]
Trying kernel                    3.0.18-030018-generic [OK]
Trying kernel                  2.6.39-02063904-generic [OK]
Trying kernel                  2.6.38-02063808-generic [OK]
Trying kernel                  2.6.37-02063706-generic [OK]
Trying kernel                  2.6.36-02063604-generic [OK]
Trying kernel                  2.6.35-02063512-generic [OK]
Trying kernel                  2.6.34-02063410-generic [OK]
Trying kernel                  2.6.33-02063305-generic [OK]
Trying kernel                  2.6.32-02063255-generic [OK]
Trying kernel                  2.6.31-02063113-generic [OK]
Trying kernel                  2.6.30-02063010-generic [OK]
Trying kernel                  2.6.29-02062906-generic [OK]
Trying kernel                  2.6.28-02062810-generic [OK]
Trying kernel                    2.6.27-020627-generic [OK]
Trying kernel                    2.6.26-020626-generic [OK]
Trying kernel                    2.6.25-020625-generic [OK]
Trying kernel                    2.6.24-020624-generic [OK]

Tested-by: Luis R. Rodriguez <mcgrof@frijolero.org>
Signed-off-by: Eliad Peller <eliad@wizery.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@frijolero.org>
include/linux/compat-3.1.h

index 1e8e05edb1b8c3ecd5c6cc9292af2e6400a96717..3fdcbf889949c52db5028168a26ce8a27c1c5eba 100644 (file)
@@ -18,10 +18,29 @@ static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev
        return skb;
 }
 
-#define IS_ENABLED(option) defined(option)
-
+/*
+ * 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 __ARG_PLACEHOLDER_1 0,
+#define config_enabled(cfg) _config_enabled(cfg)
+#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value)
+#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0)
+#define ___config_enabled(__ignored, val, ...) val
 #define genl_dump_check_consistent(cb, user_hdr, family)
 
+/*
+ * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CONFIG_FOO is set to 'y' or 'm',
+ * 0 otherwise.
+ *
+ */
+#define IS_ENABLED(option) \
+        (config_enabled(option) || config_enabled(option##_MODULE))
+
 #define IFF_TX_SKB_SHARING     0x10000 /* The interface supports sharing
                                         * skbs on transmit */