__KERNEL__ and __MODULE__

__KERNEL__ and __MODULE__

am 01.02.2007 07:34:12 von Daniel Rodrick

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

Re: __KERNEL__ and __MODULE__

am 01.02.2007 19:04:01 von Simon Valiquette

Daniel Rodrick un jour =E9crivit:
> Hi,
>=20
> I find a lot of code buried within #ifdefs for the following variable=
s:
>=20
> MODULE / __MODULE__
> KERNEL / __KERNEL__
>=20
> 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=
=20
libraries) than include kernel code and there is many things that you=20
don't want them to include. So most modules will want the __KERNEL__=20
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=20
__MODULE__ or KERNEL exist. I greped the 2.6.17 kernel just to be sure=
,=20
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 modu=
les=20
and compile it from outside the kernel tree. So you will be sure not t=
o=20
introduce problems in your kernel (and loose time finding out what).

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

I never used kbuild, so I cannot fairly comment on it. Still, I=20
strongly recommand you to buy a copy of Linux Device Drivers from O'Rei=
lly=20
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 ge=
t=20
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

Re: __KERNEL__ and __MODULE__

am 01.02.2007 20:28:49 von rpjday

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.

--0-1449346627-1170358129=:17545
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by rubicon.netdirect.ca id l11JTHEs010476

On Thu, 1 Feb 2007, Simon Valiquette wrote:

> Daniel Rodrick un jour =E9crivit:

> > 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

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

http://www.fsdev.dreamhosters.com/wiki/index.php?title=3DMai n_Page
==================== =====3D=
==================== =====3D=
==================== ==
--0-1449346627-1170358129=:17545--

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/