kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* Conditional compilation depending on CONFIG_FOOBAR
@ 2011-12-12  3:44 contemplating zombie
  2011-12-12  3:47 ` contemplating zombie
  0 siblings, 1 reply; 4+ messages in thread
From: contemplating zombie @ 2011-12-12  3:44 UTC (permalink / raw)
  To: kernelnewbies

Hi,

I want to conditionally compile some code in module if CONFIG_FOOBAR is
defined.
How can I add this check to my module's makefile?

-Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111211/dad9339e/attachment.html 

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

* Conditional compilation depending on CONFIG_FOOBAR
  2011-12-12  3:44 Conditional compilation depending on CONFIG_FOOBAR contemplating zombie
@ 2011-12-12  3:47 ` contemplating zombie
  2011-12-12  7:59   ` Srivatsa Bhat
  0 siblings, 1 reply; 4+ messages in thread
From: contemplating zombie @ 2011-12-12  3:47 UTC (permalink / raw)
  To: kernelnewbies

Just to clarify more, if I put my code in something like:
#ifdef CONFIG_FOOBAR
my code
#endif

Then my module's Makefile should check if this parameter is defined in the
".config" file. How should I modify my Makefile to do that?

On Sun, Dec 11, 2011 at 10:44 PM, contemplating zombie <
contemplatingzombie@gmail.com> wrote:

> Hi,
>
> I want to conditionally compile some code in module if CONFIG_FOOBAR is
> defined.
> How can I add this check to my module's makefile?
>
> -Thanks.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111211/812eb49a/attachment.html 

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

* Conditional compilation depending on CONFIG_FOOBAR
  2011-12-12  3:47 ` contemplating zombie
@ 2011-12-12  7:59   ` Srivatsa Bhat
  2011-12-12 11:30     ` Javier Martinez Canillas
  0 siblings, 1 reply; 4+ messages in thread
From: Srivatsa Bhat @ 2011-12-12  7:59 UTC (permalink / raw)
  To: kernelnewbies

On Mon, Dec 12, 2011 at 9:17 AM, contemplating zombie <
contemplatingzombie@gmail.com> wrote:

> Just to clarify more, if I put my code in something like:
> #ifdef CONFIG_FOOBAR
> my code
> #endif
>
> Then my module's Makefile should check if this parameter is defined in the
> ".config" file. How should I modify my Makefile to do that?
>
>
> On Sun, Dec 11, 2011 at 10:44 PM, contemplating zombie <
> contemplatingzombie at gmail.com> wrote:
>
>> Hi,
>>
>> I want to conditionally compile some code in module if CONFIG_FOOBAR is
>> defined.
>> How can I add this check to my module's makefile?
>>
>> -Thanks.
>>
>
>
If I understand correctly, you want some part of your module to be compiled
only
when CONFIG_FOOBAR is defined. You already mentioned the solution yourself!:
Just put that code within #ifdef CONFIG_FOOBAR and #endif
That would check the .config file and see if CONFIG_FOOBAR is defined; and
only if it
is defined, that code piece gets compiled, else it will simply get stripped
off.

Regards,
Srivatsa S. Bhat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111212/a16e25aa/attachment-0001.html 

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

* Conditional compilation depending on CONFIG_FOOBAR
  2011-12-12  7:59   ` Srivatsa Bhat
@ 2011-12-12 11:30     ` Javier Martinez Canillas
  0 siblings, 0 replies; 4+ messages in thread
From: Javier Martinez Canillas @ 2011-12-12 11:30 UTC (permalink / raw)
  To: kernelnewbies

On Mon, Dec 12, 2011 at 8:59 AM, Srivatsa Bhat <bhat.srivatsa@gmail.com> wrote:
>
>
> On Mon, Dec 12, 2011 at 9:17 AM, contemplating zombie
> <contemplatingzombie@gmail.com> wrote:
>>
>> Just to clarify more, if I put my code in something like:
>> #ifdef CONFIG_FOOBAR
>> my code
>> #endif
>>
>> Then my module's Makefile should check if this parameter is defined in the
>> ".config" file. How should I modify my Makefile to do that?
>>
>>
>> On Sun, Dec 11, 2011 at 10:44 PM, contemplating zombie
>> <contemplatingzombie@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> I want to conditionally compile some code in module if CONFIG_FOOBAR is
>>> defined.
>>> How can I add this check to my module's makefile?
>>>
>>> -Thanks.
>>
>>
>
> If I understand correctly, you want some part of your module to be compiled
> only
> when CONFIG_FOOBAR is defined.?You already mentioned the solution yourself!:
> Just put that code within #ifdef CONFIG_FOOBAR and #endif
> That would check the .config file and see if CONFIG_FOOBAR is defined; and
> only if it
> is defined, that code piece gets?compiled, else it will simply get stripped
> off.
>

Now if the question is _how_ to define the configuration symbol
FOOBAR. Then you have to add a new configuration option to a Kconfig
file (probably the one that exists in the directory where you have the
file that is using it).

For example, suppose that you have a char device driver located in
drivers/char/yourdev.c and yourdev uses a FOOBAR option to do
something. Then you have to add something like this in
drivers/char/Kconfig

config FOOBAR
        bool "decide to use foobar or not"
         help
         Say Y here if you want to enable the foobar option.

When you execute make menuconfig or other make targets that generate
the compilation options menu. You will see your option under "Device
drivers" -> "Character devices"

The mconf binary will write in .config the value that you chose for
FOOBAR and will append CONFIG_

So if you enable FOOBAR, you will have something like:

CONFIG_FOOBAR=y

Then this symbols are used to create a generated autoconf.h file in
include/generated/autoconf.h

every compilation command in the kernel includes this file

gcc yourdev.c -I include/generated/autoconf.h

For a detailed description of the kernel build system look at
Documentation/kbuild/

Hope it helps,

-- 
Javier Mart?nez Canillas
(+34) 682 39 81 69
Barcelona, Spain

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

end of thread, other threads:[~2011-12-12 11:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-12  3:44 Conditional compilation depending on CONFIG_FOOBAR contemplating zombie
2011-12-12  3:47 ` contemplating zombie
2011-12-12  7:59   ` Srivatsa Bhat
2011-12-12 11:30     ` Javier Martinez Canillas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).