diff mbox series

[v2,03/21] configure: Fixes ncursesw detection under msys2/mingw and enable curses

Message ID 20200909094617.1582-4-luoyonggang@gmail.com
State Superseded
Headers show
Series W32, W64 msys2/mingw patches | expand

Commit Message

罗勇刚(Yonggang Luo) Sept. 9, 2020, 9:45 a.m. UTC
The mingw pkg-config are showing following absolute path and contains : as the separator,
so we must handling : properly.

-D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC:/CI-Tools/msys64/mingw64/include/ncursesw:-I/usr/include/ncursesw:
-DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -pipe -lncursesw -lgnurx -ltre -lintl -liconv
-DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -lncursesw
-DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -lcursesw
-DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv
-DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -lncursesw
-DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -lcursesw
-DNCURSES_WIDECHAR -I/usr/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv
-DNCURSES_WIDECHAR -I/usr/include/ncursesw -lncursesw
-DNCURSES_WIDECHAR -I/usr/include/ncursesw -lcursesw

msys2/mingw lacks the POSIX-required langinfo.h.

gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv
test.c:4:10: fatal error: langinfo.h: No such file or directory
    4 | #include <langinfo.h>
      |          ^~~~~~~~~~~~
compilation terminated.

So we using g_get_codeset instead of nl_langinfo(CODESET)

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
---
 configure   |  9 +++------
 ui/curses.c | 10 +++++-----
 2 files changed, 8 insertions(+), 11 deletions(-)

Comments

罗勇刚(Yonggang Luo) Oct. 2, 2020, 5:49 p.m. UTC | #1
You can queue this instead

On Wed, Sep 9, 2020 at 5:46 PM Yonggang Luo <luoyonggang@gmail.com> wrote:
>

> The mingw pkg-config are showing following absolute path and contains :

as the separator,
> so we must handling : properly.

>

> -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L

-IC:/CI-Tools/msys64/mingw64/include/ncursesw:-I/usr/include/ncursesw:
> -DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC

-pipe -lncursesw -lgnurx -ltre -lintl -liconv
> -DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC

-lncursesw
> -DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC

-lcursesw
> -DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -pipe

-lncursesw -lgnurx -ltre -lintl -liconv
> -DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -lncursesw

> -DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -lcursesw

> -DNCURSES_WIDECHAR -I/usr/include/ncursesw -pipe -lncursesw -lgnurx -ltre

-lintl -liconv
> -DNCURSES_WIDECHAR -I/usr/include/ncursesw -lncursesw

> -DNCURSES_WIDECHAR -I/usr/include/ncursesw -lcursesw

>

> msys2/mingw lacks the POSIX-required langinfo.h.

>

> gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe

-lncursesw -lgnurx -ltre -lintl -liconv
> test.c:4:10: fatal error: langinfo.h: No such file or directory

>     4 | #include <langinfo.h>

>       |          ^~~~~~~~~~~~

> compilation terminated.

>

> So we using g_get_codeset instead of nl_langinfo(CODESET)

>

> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>

> Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>

> ---

>  configure   |  9 +++------

>  ui/curses.c | 10 +++++-----

>  2 files changed, 8 insertions(+), 11 deletions(-)

>

> diff --git a/configure b/configure

> index f4f8bc3756..2e6d54e15b 100755

> --- a/configure

> +++ b/configure

> @@ -3653,8 +3653,8 @@ if test "$iconv" = "no" ; then

>  fi

>  if test "$curses" != "no" ; then

>    if test "$mingw32" = "yes" ; then

> -    curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null):"

> -    curses_lib_list="$($pkg_config --libs ncurses

2>/dev/null):-lpdcurses"
> +    curses_inc_list="$($pkg_config --cflags ncursesw

2>/dev/null):-I/${MSYSTEM,,}/include/ncursesw:"
> +    curses_lib_list="$($pkg_config --libs ncursesw

2>/dev/null):-lncursesw"
>    else

>      curses_inc_list="$($pkg_config --cflags ncursesw

2>/dev/null):-I/usr/include/ncursesw:"
>      curses_lib_list="$($pkg_config --libs ncursesw

2>/dev/null):-lncursesw:-lcursesw"
> @@ -3664,17 +3664,14 @@ if test "$curses" != "no" ; then

>  #include <locale.h>

>  #include <curses.h>

>  #include <wchar.h>

> -#include <langinfo.h>

>  int main(void) {

> -  const char *codeset;

>    wchar_t wch = L'w';

>    setlocale(LC_ALL, "");

>    resize_term(0, 0);

>    addwstr(L"wide chars\n");

>    addnwstr(&wch, 1);

>    add_wch(WACS_DEGREE);

> -  codeset = nl_langinfo(CODESET);

> -  return codeset != 0;

> +  return 0;

>  }

>  EOF

>    IFS=:

> diff --git a/ui/curses.c b/ui/curses.c

> index a59b23a9cf..12bc682cf9 100644

> --- a/ui/curses.c

> +++ b/ui/curses.c

> @@ -30,7 +30,6 @@

>  #endif

>  #include <locale.h>

>  #include <wchar.h>

> -#include <langinfo.h>

>  #include <iconv.h>

>

>  #include "qapi/error.h"

> @@ -526,6 +525,7 @@ static void font_setup(void)

>      iconv_t nativecharset_to_ucs2;

>      iconv_t font_conv;

>      int i;

> +    g_autofree gchar *local_codeset = g_get_codeset();

>

>      /*

>       * Control characters are normally non-printable, but VGA does have

> @@ -566,14 +566,14 @@ static void font_setup(void)

>        0x25bc

>      };

>

> -    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");

> +    ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2");

>      if (ucs2_to_nativecharset == (iconv_t) -1) {

>          fprintf(stderr, "Could not convert font glyphs from UCS-2:

'%s'\n",
>                          strerror(errno));

>          exit(1);

>      }

>

> -    nativecharset_to_ucs2 = iconv_open("UCS-2", nl_langinfo(CODESET));

> +    nativecharset_to_ucs2 = iconv_open("UCS-2", local_codeset);

>      if (nativecharset_to_ucs2 == (iconv_t) -1) {

>          iconv_close(ucs2_to_nativecharset);

>          fprintf(stderr, "Could not convert font glyphs to UCS-2: '%s'\n",

> @@ -581,7 +581,7 @@ static void font_setup(void)

>          exit(1);

>      }

>

> -    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);

> +    font_conv = iconv_open(local_codeset, font_charset);

>      if (font_conv == (iconv_t) -1) {

>          iconv_close(ucs2_to_nativecharset);

>          iconv_close(nativecharset_to_ucs2);

> @@ -602,7 +602,7 @@ static void font_setup(void)

>      /* DEL */

>      convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);

>

> -    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {

> +    if (strcmp(local_codeset, "UTF-8")) {

>          /* Non-Unicode capable, use termcap equivalents for those

available */
>          for (i = 0; i <= 0xFF; i++) {

>              wchar_t wch[CCHARW_MAX];

> --

> 2.28.0.windows.1

>



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
<div dir="ltr">You can queue this instead<br><br>On Wed, Sep 9, 2020 at 5:46 PM Yonggang Luo &lt;<a href="mailto:luoyonggang@gmail.com">luoyonggang@gmail.com</a>&gt; wrote:<br>&gt;<br>&gt; The mingw pkg-config are showing following absolute path and contains : as the separator,<br>&gt; so we must handling : properly.<br>&gt;<br>&gt; -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC:/CI-Tools/msys64/mingw64/include/ncursesw:-I/usr/include/ncursesw:<br>&gt; -DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -pipe -lncursesw -lgnurx -ltre -lintl -liconv<br>&gt; -DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -lncursesw<br>&gt; -DNCURSES_WIDECHAR -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC -lcursesw<br>&gt; -DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv<br>&gt; -DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -lncursesw<br>&gt; -DNCURSES_WIDECHAR /CI-Tools/msys64/mingw64/include/ncursesw -lcursesw<br>&gt; -DNCURSES_WIDECHAR -I/usr/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv<br>&gt; -DNCURSES_WIDECHAR -I/usr/include/ncursesw -lncursesw<br>&gt; -DNCURSES_WIDECHAR -I/usr/include/ncursesw -lcursesw<br>&gt;<br>&gt; msys2/mingw lacks the POSIX-required langinfo.h.<br>&gt;<br>&gt; gcc test.c -DNCURSES_WIDECHAR -I/mingw64/include/ncursesw -pipe -lncursesw -lgnurx -ltre -lintl -liconv<br>&gt; test.c:4:10: fatal error: langinfo.h: No such file or directory<br>&gt;     4 | #include &lt;langinfo.h&gt;<br>&gt;       |          ^~~~~~~~~~~~<br>&gt; compilation terminated.<br>&gt;<br>&gt; So we using g_get_codeset instead of nl_langinfo(CODESET)<br>&gt;<br>&gt; Signed-off-by: Yonggang Luo &lt;<a href="mailto:luoyonggang@gmail.com">luoyonggang@gmail.com</a>&gt;<br>&gt; Reviewed-by: Gerd Hoffmann &lt;<a href="mailto:kraxel@redhat.com">kraxel@redhat.com</a>&gt;<br>&gt; ---<br>&gt;  configure   |  9 +++------<br>&gt;  ui/curses.c | 10 +++++-----<br>&gt;  2 files changed, 8 insertions(+), 11 deletions(-)<br>&gt;<br>&gt; diff --git a/configure b/configure<br>&gt; index f4f8bc3756..2e6d54e15b 100755<br>&gt; --- a/configure<br>&gt; +++ b/configure<br>&gt; @@ -3653,8 +3653,8 @@ if test &quot;$iconv&quot; = &quot;no&quot; ; then<br>&gt;  fi<br>&gt;  if test &quot;$curses&quot; != &quot;no&quot; ; then<br>&gt;    if test &quot;$mingw32&quot; = &quot;yes&quot; ; then<br>&gt; -    curses_inc_list=&quot;$($pkg_config --cflags ncurses 2&gt;/dev/null):&quot;<br>&gt; -    curses_lib_list=&quot;$($pkg_config --libs ncurses 2&gt;/dev/null):-lpdcurses&quot;<br>&gt; +    curses_inc_list=&quot;$($pkg_config --cflags ncursesw 2&gt;/dev/null):-I/${MSYSTEM,,}/include/ncursesw:&quot;<br>&gt; +    curses_lib_list=&quot;$($pkg_config --libs ncursesw 2&gt;/dev/null):-lncursesw&quot;<br>&gt;    else<br>&gt;      curses_inc_list=&quot;$($pkg_config --cflags ncursesw 2&gt;/dev/null):-I/usr/include/ncursesw:&quot;<br>&gt;      curses_lib_list=&quot;$($pkg_config --libs ncursesw 2&gt;/dev/null):-lncursesw:-lcursesw&quot;<br>&gt; @@ -3664,17 +3664,14 @@ if test &quot;$curses&quot; != &quot;no&quot; ; then<br>&gt;  #include &lt;locale.h&gt;<br>&gt;  #include &lt;curses.h&gt;<br>&gt;  #include &lt;wchar.h&gt;<br>&gt; -#include &lt;langinfo.h&gt;<br>&gt;  int main(void) {<br>&gt; -  const char *codeset;<br>&gt;    wchar_t wch = L&#39;w&#39;;<br>&gt;    setlocale(LC_ALL, &quot;&quot;);<br>&gt;    resize_term(0, 0);<br>&gt;    addwstr(L&quot;wide chars\n&quot;);<br>&gt;    addnwstr(&amp;wch, 1);<br>&gt;    add_wch(WACS_DEGREE);<br>&gt; -  codeset = nl_langinfo(CODESET);<br>&gt; -  return codeset != 0;<br>&gt; +  return 0;<br>&gt;  }<br>&gt;  EOF<br>&gt;    IFS=:<br>&gt; diff --git a/ui/curses.c b/ui/curses.c<br>&gt; index a59b23a9cf..12bc682cf9 100644<br>&gt; --- a/ui/curses.c<br>&gt; +++ b/ui/curses.c<br>&gt; @@ -30,7 +30,6 @@<br>&gt;  #endif<br>&gt;  #include &lt;locale.h&gt;<br>&gt;  #include &lt;wchar.h&gt;<br>&gt; -#include &lt;langinfo.h&gt;<br>&gt;  #include &lt;iconv.h&gt;<br>&gt;<br>&gt;  #include &quot;qapi/error.h&quot;<br>&gt; @@ -526,6 +525,7 @@ static void font_setup(void)<br>&gt;      iconv_t nativecharset_to_ucs2;<br>&gt;      iconv_t font_conv;<br>&gt;      int i;<br>&gt; +    g_autofree gchar *local_codeset = g_get_codeset();<br>&gt;<br>&gt;      /*<br>&gt;       * Control characters are normally non-printable, but VGA does have<br>&gt; @@ -566,14 +566,14 @@ static void font_setup(void)<br>&gt;        0x25bc<br>&gt;      };<br>&gt;<br>&gt; -    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), &quot;UCS-2&quot;);<br>&gt; +    ucs2_to_nativecharset = iconv_open(local_codeset, &quot;UCS-2&quot;);<br>&gt;      if (ucs2_to_nativecharset == (iconv_t) -1) {<br>&gt;          fprintf(stderr, &quot;Could not convert font glyphs from UCS-2: &#39;%s&#39;\n&quot;,<br>&gt;                          strerror(errno));<br>&gt;          exit(1);<br>&gt;      }<br>&gt;<br>&gt; -    nativecharset_to_ucs2 = iconv_open(&quot;UCS-2&quot;, nl_langinfo(CODESET));<br>&gt; +    nativecharset_to_ucs2 = iconv_open(&quot;UCS-2&quot;, local_codeset);<br>&gt;      if (nativecharset_to_ucs2 == (iconv_t) -1) {<br>&gt;          iconv_close(ucs2_to_nativecharset);<br>&gt;          fprintf(stderr, &quot;Could not convert font glyphs to UCS-2: &#39;%s&#39;\n&quot;,<br>&gt; @@ -581,7 +581,7 @@ static void font_setup(void)<br>&gt;          exit(1);<br>&gt;      }<br>&gt;<br>&gt; -    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);<br>&gt; +    font_conv = iconv_open(local_codeset, font_charset);<br>&gt;      if (font_conv == (iconv_t) -1) {<br>&gt;          iconv_close(ucs2_to_nativecharset);<br>&gt;          iconv_close(nativecharset_to_ucs2);<br>&gt; @@ -602,7 +602,7 @@ static void font_setup(void)<br>&gt;      /* DEL */<br>&gt;      convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);<br>&gt;<br>&gt; -    if (strcmp(nl_langinfo(CODESET), &quot;UTF-8&quot;)) {<br>&gt; +    if (strcmp(local_codeset, &quot;UTF-8&quot;)) {<br>&gt;          /* Non-Unicode capable, use termcap equivalents for those available */<br>&gt;          for (i = 0; i &lt;= 0xFF; i++) {<br>&gt;              wchar_t wch[CCHARW_MAX];<br>&gt; --<br>&gt; 2.28.0.windows.1<br>&gt;<br><br><br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo</div>
diff mbox series

Patch

diff --git a/configure b/configure
index f4f8bc3756..2e6d54e15b 100755
--- a/configure
+++ b/configure
@@ -3653,8 +3653,8 @@  if test "$iconv" = "no" ; then
 fi
 if test "$curses" != "no" ; then
   if test "$mingw32" = "yes" ; then
-    curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null):"
-    curses_lib_list="$($pkg_config --libs ncurses 2>/dev/null):-lpdcurses"
+    curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null):-I/${MSYSTEM,,}/include/ncursesw:"
+    curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null):-lncursesw"
   else
     curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null):-I/usr/include/ncursesw:"
     curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null):-lncursesw:-lcursesw"
@@ -3664,17 +3664,14 @@  if test "$curses" != "no" ; then
 #include <locale.h>
 #include <curses.h>
 #include <wchar.h>
-#include <langinfo.h>
 int main(void) {
-  const char *codeset;
   wchar_t wch = L'w';
   setlocale(LC_ALL, "");
   resize_term(0, 0);
   addwstr(L"wide chars\n");
   addnwstr(&wch, 1);
   add_wch(WACS_DEGREE);
-  codeset = nl_langinfo(CODESET);
-  return codeset != 0;
+  return 0;
 }
 EOF
   IFS=:
diff --git a/ui/curses.c b/ui/curses.c
index a59b23a9cf..12bc682cf9 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -30,7 +30,6 @@ 
 #endif
 #include <locale.h>
 #include <wchar.h>
-#include <langinfo.h>
 #include <iconv.h>
 
 #include "qapi/error.h"
@@ -526,6 +525,7 @@  static void font_setup(void)
     iconv_t nativecharset_to_ucs2;
     iconv_t font_conv;
     int i;
+    g_autofree gchar *local_codeset = g_get_codeset();
 
     /*
      * Control characters are normally non-printable, but VGA does have
@@ -566,14 +566,14 @@  static void font_setup(void)
       0x25bc
     };
 
-    ucs2_to_nativecharset = iconv_open(nl_langinfo(CODESET), "UCS-2");
+    ucs2_to_nativecharset = iconv_open(local_codeset, "UCS-2");
     if (ucs2_to_nativecharset == (iconv_t) -1) {
         fprintf(stderr, "Could not convert font glyphs from UCS-2: '%s'\n",
                         strerror(errno));
         exit(1);
     }
 
-    nativecharset_to_ucs2 = iconv_open("UCS-2", nl_langinfo(CODESET));
+    nativecharset_to_ucs2 = iconv_open("UCS-2", local_codeset);
     if (nativecharset_to_ucs2 == (iconv_t) -1) {
         iconv_close(ucs2_to_nativecharset);
         fprintf(stderr, "Could not convert font glyphs to UCS-2: '%s'\n",
@@ -581,7 +581,7 @@  static void font_setup(void)
         exit(1);
     }
 
-    font_conv = iconv_open(nl_langinfo(CODESET), font_charset);
+    font_conv = iconv_open(local_codeset, font_charset);
     if (font_conv == (iconv_t) -1) {
         iconv_close(ucs2_to_nativecharset);
         iconv_close(nativecharset_to_ucs2);
@@ -602,7 +602,7 @@  static void font_setup(void)
     /* DEL */
     convert_ucs(0x7F, 0x2302, ucs2_to_nativecharset);
 
-    if (strcmp(nl_langinfo(CODESET), "UTF-8")) {
+    if (strcmp(local_codeset, "UTF-8")) {
         /* Non-Unicode capable, use termcap equivalents for those available */
         for (i = 0; i <= 0xFF; i++) {
             wchar_t wch[CCHARW_MAX];