Skip to contentSkip to conversation

Kconfig, Makefile and ifdef: mod as yes vs. no?

PATCH Pekka Paalanen 2 participants 3 messages Jul 11, 2009 – Jul 12, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi,

I'm having hard time making a patch that would compile nouveau_backlight.o only if CONFIG_BACKLIGHT_CLASS_DEVICE is y or m, and define just stubs when it is n.

I'm trying this in the nouveau/linux-2.6 kernel tree, which is basically 2.6.31-rc2.

I attempted the following:

drivers/gpu/drm/nouveau/Makefile +3 -2
@@ -8,7 +8,7 @@ nouveau-y := nouveau_drv.o nouveau_state.o nouveau_fifo.o nouveau_mem.o \
              nouveau_sgdma.o nouveau_dma.o \
              nouveau_bo.o nouveau_fence.o nouveau_gem.o nouveau_ttm.o \
              nouveau_hw.o nouveau_calc.o nouveau_bios.o nouveau_i2c.o \
-            nouveau_display.o nouveau_fbcon.o nouveau_backlight.o \
+             nouveau_display.o nouveau_fbcon.o \
              nv04_timer.o \
              nv04_mc.o nv40_mc.o nv50_mc.o \
              nv04_fb.o nv10_fb.o nv40_fb.o \
@@ -19,8 +19,9 @@ nouveau-y := nouveau_drv.o nouveau_state.o nouveau_fifo.o nouveau_mem.o \
              nv50_crtc.o nv50_dac.o nv50_sor.o nv50_connector.o \
              nv50_cursor.o nv50_display.o nv50_fbcon.o \
              nv04_display.o nv04_output.o nv04_crtc.o nv04_cursor.o \
-            nv04_fbcon.o
+             nv04_fbcon.o
 
 nouveau-$(CONFIG_COMPAT) += nouveau_ioc32.o
+nouveau-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += nouveau_backlight.o
 
 obj-$(CONFIG_DRM_NOUVEAU)+= nouveau.o
drivers/gpu/drm/nouveau/nouveau_drv.h +13 -0
@@ -708,8 +708,21 @@ extern int  nouveau_dma_init(struct nouveau_channel *);
 extern int  nouveau_dma_wait(struct nouveau_channel *, int size);
 
 /* nouveau_backlight.c */
+#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE
 extern int nouveau_backlight_init(struct drm_device *);
 extern void nouveau_backlight_exit(struct drm_device *);
+#else
+static inline int nouveau_backlight_init(struct drm_device *dev)
+{
+       (void)dev;
+       return 0;
+}
+
+static inline void nouveau_backlight_exit(struct drm_device *dev)
+{
+       (void)dev;
+}
+#endif
 

When CONFIG_BACKLIGHT_CLASS_DEVICE=m this behaves as if it was n, i.e. I get the stubs and no nouveau_backlight.o.

For CONFIG_BACKLIGHT_CLASS_DEVICE=y and n I get what I want.

What is the proper way to get m behave like y in this situation?

Oh, and should I use the following instead of (void)dev;?
static inline void nouveau_backlight_exit(struct drm_device *dev __used) { }

Please, Cc me.

Thanks.

Signature · 2 lines
Pekka Paalanen
http://www.iki.fi/pq/
#1 lore raw
Quoted 2 lines · Pekka Paalanen

+#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE

You need to test _MODULE for the symbol too... since it's necessary to be able to distinguish between symbols which exist in the vmlinux, and symbols which require a module to be loaded.

#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) &&
defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)

should work.

regards, Kyle

#2 lore raw
Quoted 4 lines · On Sat, 11 Jul 2009 17:53:43 -0400 Kyle McMartin <[email protected]> wrote:
Quoted 2 lines · Pekka Paalanen

+#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE

Quoted 8 lines

You need to test _MODULE for the symbol too... since it's necessary to be able to distinguish between symbols which exist in the vmlinux, and symbols which require a module to be loaded.

#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) &&
defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)

should work.

Just || instead of &&, and yes, this is a solution for half of the problem, thanks.

But what about the Makefile?

nouveau-y := nouveau_drv.o ... nouveau-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += nouveau_backlight.o obj-$(CONFIG_DRM_NOUVEAU)+= nouveau.o

With this, nouveau_backlight.o is not built if
CONFIG_BACKLIGHT_CLASS_DEVICE=m. Should I write:

nouveau-$(if $(findstring m,$(CONFIG_BACKLIGHT_CLASS_DEVICE)),y,n) += \
nouveau_backlight.o

which to me looks ugly, or add a new Kconfig boolean option that is selected 'if CONFIG_BACKLIGHT_CLASS_DEVICE' and use that in both Makefile and code, or is there a canonical way to do this?

Other code seems to deal with a similar situation by #ifdef'ing the whole c-file contents. That cannot be the preferred way, can it?

Thanks.

Signature · 2 lines
Pekka Paalanen
http://www.iki.fi/pq/