All of lore.kernel.org
 help / color / mirror / Atom feed
* __KERNEL__ and __MODULE__
@ 2007-02-01  6:34 Daniel Rodrick
  2007-02-01 18:04 ` Simon Valiquette
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Rodrick @ 2007-02-01  6:34 UTC (permalink / raw)
  To: Linux Newbie, kernelnewbies

Hi,

I find a lot of code buried within #ifdefs for the following variables:

MODULE / __MODULE__
KERNEL / __KERNEL__

1) AFAIK, the MODULE / __MODULE__ is defined when my drievr is
selected to be compiled as a module, and the KERNEL / __KERNEL__ is
defined when is is selected to be built in the kernel image. Is this
right?

2) Why two variants ? KERNEL V/s __KERNEL__ and MODULE v/s __MODULE__?

3) Do I need to define these symbols in my Makefile myself or the
Kernel Makefiles / Kbuild does it for me?

Thanks,

Dan
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* Re: __KERNEL__ and __MODULE__
  2007-02-01  6:34 __KERNEL__ and __MODULE__ Daniel Rodrick
@ 2007-02-01 18:04 ` Simon Valiquette
  2007-02-01 19:28   ` Robert P. J. Day
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Valiquette @ 2007-02-01 18:04 UTC (permalink / raw)
  To: Daniel Rodrick; +Cc: Linux Newbie, kernelnewbies

Daniel Rodrick un jour écrivit:
> Hi,
> 
> I find a lot of code buried within #ifdefs for the following variables:
> 
> MODULE / __MODULE__
> KERNEL / __KERNEL__
> 
> 1) AFAIK, the MODULE / __MODULE__ is defined when my drievr is
> selected to be compiled as a module, and the KERNEL / __KERNEL__ is
> defined when is is selected to be built in the kernel image. Is this
> right?

   No.  The __KERNEL__ macro is defined because there is programs (like 
libraries) than include kernel code and there is many things that you 
don't want them to include.  So most modules will want the __KERNEL__ 
macro to be enabled.  It is usually done by passing -D__KERNEL__ to gcc.

> 2) Why two variants ? KERNEL V/s __KERNEL__ and MODULE v/s __MODULE__?

   AFAIK, there is only MODULE and __KERNEL__.  I don't think that 
__MODULE__ or KERNEL exist.  I greped the 2.6.17 kernel just to be sure, 
and didn't found any instance of them.

> 3) Do I need to define these symbols in my Makefile myself or the
> Kernel Makefiles / Kbuild does it for me?

   Use the source, Luke!  There is plenty of examples there and on the web.

   I would suggest that for now, you only make dynamicaly loadable modules 
and compile it from outside the kernel tree.  So you will be sure not to 
introduce problems in your kernel (and loose time finding out what).

   So for starting, you will probably want to add -D__KERNEL__ directly to 
gcc and define MODULE inside of your module for simplicity.  When you will 
know a bit more about kernel programming, you may try to include your code 
directly in the kernel tree.

   I never used kbuild, so I cannot fairly comment on it.  Still, I 
strongly recommand you to buy a copy of Linux Device Drivers from O'Reilly 
and maybe some others books like Robert Love's Linux Kernel Development. 
That will answer many of your questions and then you will be able to get 
much more from this mailing list.

Simon Valiquette
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

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

* Re: __KERNEL__ and __MODULE__
  2007-02-01 18:04 ` Simon Valiquette
@ 2007-02-01 19:28   ` Robert P. J. Day
  0 siblings, 0 replies; 3+ messages in thread
From: Robert P. J. Day @ 2007-02-01 19:28 UTC (permalink / raw)
  To: Simon Valiquette; +Cc: Daniel Rodrick, Linux Newbie, kernelnewbies

[-- Attachment #1: Type: TEXT/PLAIN, Size: 838 bytes --]

On Thu, 1 Feb 2007, Simon Valiquette wrote:

> Daniel Rodrick un jour écrivit:

> > 2) Why two variants ? KERNEL V/s __KERNEL__ and MODULE v/s __MODULE__?
>
>   AFAIK, there is only MODULE and __KERNEL__.  I don't think that
> __MODULE__ or KERNEL exist.  I greped the 2.6.17 kernel just to be
> sure, and didn't found any instance of them.

actually, there is a single example of "#ifdef KERNEL" in
include/linux/coda.h but, what the heck, i'll submit a patch for that
in the next 30 seconds.

rday

-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://www.fsdev.dreamhosters.com/wiki/index.php?title=Main_Page
========================================================================

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

end of thread, other threads:[~2007-02-01 19:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-01  6:34 __KERNEL__ and __MODULE__ Daniel Rodrick
2007-02-01 18:04 ` Simon Valiquette
2007-02-01 19:28   ` Robert P. J. Day

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.