libbsd: How to add an option for switching off IPv6 (or other BSD Kernel configurations)

Chris Johns chrisj at rtems.org
Tue Aug 2 10:21:07 UTC 2016


On 2/08/2016 8:05 PM, Christian Mauderer wrote:
> Am 02.08.2016 um 08:57 schrieb Christian Mauderer:
>> Am 02.08.2016 um 04:09 schrieb Chris Johns:
>>> On 02/08/2016 00:04, Christian Mauderer wrote:
> [...]
>>
>>>> Are there any better ideas how to implement such an option?
>>>
>>> There are 2 parts that need be to changed to make this work. This
>>> assumes you will need to control the source being built.
>>>
>>> The first is the module descriptions in libbsd.py and then the
>>> generator. I suggest you look at the various module class methods used
>>> to add source and consider adding a 'section' argument which defaults to
>>> 'default' (always True). This would lets you move code into specific
>>> sections, for example:
>>>
>>>     dhcpcd_defines='-D__FreeBSD__ -DTHERE_IS_NO_FORK ...'
>>>     mod.addSourceFiles(
>>>         [
>>>             'dhcpcd/ipv6.c',
>>>             'dhcpcd/ipv6nd.c',
>>>         ],
>>>         mm.generator['source'](dhcpcd_defines),
>>>         section = 'networking.ipv6_yes'
>>>     )
>>>
>>> Note, this definition generates something that is evaluated when waf
>>> runs so the 'section' populates a dict where the 'networking.ipv6_yes'
>>> key is tested for True or False depending what the user specifies.
>>>
>>> You could also change the class constructor so you have:
>>>
>>>  mod = builder.Module('dhcpcd', section = 'networking.dhcp')
>>>
>>> The dot notation would allow control of the sources at the module level
>>> to finally get sorted out. The dhcpcd module becomes 'networking.dhcpcd'
>>> which means build if networking and dhcpcd are True. You could work down
>>> the dots checking at each point to make sure the module can be built.
>>> Currently module level user control has been left hanging with commented
>>> modules, eg '#mm.addModule(dev_usb_controller_add_on(mm)'. If the
>>> section 'usb.dev_usb_controller_add_on' is False by default that module
>>> is not built which is what we have now.
>>>
>>> The second part is in the waf script (wscript) which handles the user
>>> interface, ie parses
>>> --config="networking:ipv6=no,pink-frames-only,chrismac-buf-frames=64". I
>>> would add this code in a new Python module libbsd_opts.py and imported
>>> into libbsd_waf.py (generated) and called in the 'options' function in
>>> libbsd_waf.py. This would parse and populate a dict the generated module
>>> code uses.
>>>
>>
>> Thanks for the detailed description. I'll need some time to understand
>> everything but it looks like a good starting point.
>>
> [...]
>>
> 
> Hello Chris,
> 
> I think I managed to understand most of it even if I still only have a
> rough Idea where to start.
> 
> If I'm right, you suggested two alternative possible methods:
> 
> 1) Add the section-option as parameter to a addSourceFiles. This means
> it is only valid for some sources in a module.
> 
> 2) Alternatively add it directly to the module.
> 

I am saying have both so all modules are provide a section.

I only used the work section because it is the term used in INI files.

> Did I understand you correct. Or did you mean that the section is added
> to both - the module and the source?

Close, but how about annotating all source and then we can control it
better.

> 
> As far as I understand the first method, this could be also used for the
> define that depends on the option. Something like this:
> 
>     def dhcpcd(mm):
>         mod = builder.Module('dhcpcd')
>         dhcpcd_sources =
>             [
>                 'dhcpcd/arp.c',
>                 'dhcpcd/auth.c',
>                 ...
>             ]
>         dhcpcd_defines_base = '-D__FreeBSD__ -DTHERE_IS_NO_FORK ...'
>         dhcpcd_defines_inet6 = dhcpcd_defines_base + ' -DINET6'
>         mod.addSourceFiles(
>             dhcpcd_sources,
>             mm.generator['source'](dhcpcd_defines_base),
>             section = 'networking.ipv6_no'
>         )
>         mod.addSourceFiles(
>             dhcpcd_sources,
>             mm.generator['source'](dhcpcd_defines_inet6),
>             section = 'networking.ipv6_yes'
>         )
>         return mod
> 

It is close, however I suspect -DINET6 is need for all source when being
built. I will take a look and see what I can sort out.

> I'm not sure how this would be possible with the second method.

Let me take a closer look.

Chris



More information about the devel mailing list