[m-rev.] for review: Check availability of getopt() directly.

Julien Fischer jfischer at opturion.com
Mon Jun 3 15:30:56 AEST 2019


On Sat, 1 Jun 2019, Peter Wang wrote:

> On Fri, 31 May 2019 19:26:02 +1000 (AEST), Julien Fischer <jfischer at opturion.com> wrote:
>>> +# Link in local copy of getopt() only if required.
>>> +# XXX The files in runtime/GETOPT may not compile cleanly with modern
>>> +# compilers. We should replace it with another implementation.
>>
>> We need to replace them (certainly the one in runtime/mercury_getopt.c)
>> for licensing reasons anyway.
>
> How about this implementation?
>
>    https://github.com/kubo/ya_getopt
>
> It has a simple permissive licence and the code looks okay (at a glance).
> It comes with a test script that checks if the implementation matches
> the GNU implementation. On my system only ya_getopt_long_only() does NOT
> exactly match getopt_long_only(); it may be that the GNU implementation
> changed. We don't use getopt_long_only() anyway.
>
> Other possibilities:
>
>  - NetBSD/OpenBSD/FreeBSD getopt
>  - musl getopt
>  - newlib getopt
>  - https://github.com/kimgr/getopt_port/
>
> Some of them have longer licences that would need to be reproduced.

They're not that much longer and that's not really a concern anyway.

At a glance, the musl implementation looks ok.  The main difference
between the GNU implementation and the above seems to be that GNU one
performs argv permutation for getopt() and the *BSD / musl ones do not.
(They do argv permutation for getopt_long() however.)

We have three uses for getopt:

    1. in mkinit and friends      (getopt)
    2. in runtime/mercury_wrapper (getopt_long)
    3. in the trace directory     (getopt_long)

There is no licensing issue with (1) and the GNU implementation.

Julien.


More information about the reviews mailing list