[tlbuild] dvibook failure on Cygwin

Ken Brown kbrow1i at gmail.com
Wed Feb 29 13:42:47 CET 2012


On 2/29/2012 6:17 AM, Peter Breitenlohner wrote:

Hi Peter,

> for the moment that seems to be necessary, but I'd prefer a better
> solution.

I agree.

> In particular, declaring optarg once with dllimport and once without may
> cause problems
>
> ================
>
> I have looked at four different systems with <unistd.h> and <getopt.h>: GNU
> C library (i.e., Linux and Co), Cygwin, MinGW, and Mac Os X.
>
> In all cases '#include <unistd.h>' declares getopt() but neither
> getopt_long() nor 'struct option', whereas a subsequent or independent
> '#include <getopt.h>' makes sure all of them are declared.
>
> Mac Os X declares getopt() directly in unistd.h, whereas getopt.h includes
> unistd.h and declares the rest.
>
> For the other three unistd.h includes getopt.h with a special #define such
> that only getopt() is declared.
>
> ================
>
> Ideally c-unistd.h could do something similar for Cygwin:
> (1) #include <kpathsea/getopt.h> in such a way that getopt_long() and
> 'struct option' are not declared.
> (2) #include <unistd.h> in such a way that the inclusion of <getopt.h> is
> skipped.
> (3) Make sure that later direct inclusion of <kpathsea/getopt.h> will
> declare getopt_long() and 'struct option'.
>
> Alternatively (and somewhat less ideal) we could use the fact that in
> the TL
> tree whoever uses getopt() always includes <kpathsea/getopt.h> and doesn't
> depend on getopt() being declared via <unistd.h>:
> #if HAVE_UNISTD_H
> #if defined(__CYGWIN__) && !defined(__GETOPT_H__)
> #define __GETOPT_H__
> #include <unistd.h>
> #undef __GETOPT_H__
> #else
> #include <unistd.h>
> #endif
> #endif

I prefer the first alternative, since it's cleaner conceptually.  It 
makes the relation between c-unistd.h and <kpathsea/getoption.h> similar 
to the relation between <unistd.h> and <getoption.h>.

Unfortunately, there are still a lot of places where <unistd.h> is 
included directly and then <kpathsea/getoption.h> is included, leading 
to the warning about redeclaration of optarg, optind, etc.  Should all 
those inclusions of <unistd.h> be replaced by inclusions of 
<kpathsea/c-unistd.h>?  If so, I could quickly locate them all by 
grepping my build log for the warnings.

Regards,

Ken


More information about the tlbuild mailing list