Subject: Re: -municode support
From: Kai Tietz <[email-masked]>
To: Hirofumi Katayama <[email-masked]>
Cc: [email-masked]
Date: Thu, 8 Oct 2009 09:54:39 +0200
List-Id: <cygwin.cygwin.com>

[email-masked] wrote on 08.10.2009 05:02:21:

> I think Cygwin should support -municode option.
> The following patches I made might be incorrect and/or incomplete.
> 
> diff -u -N -r cygwin-1.7.0-62-old/winsup/mingw/conuni.c
> cygwin-1.7.0-62/winsup/mingw/conuni.c
> --- cygwin-1.7.0-62-old/winsup/mingw/conuni.c   Thu Jan  1 00:00:00 1970
> +++ cygwin-1.7.0-62/winsup/mingw/conuni.c   Tue Oct  6 12:48:04 2009
> @@ -0,0 +1,15 @@
> +/*
> + * conuni.c
> + * This file has no copyright assigned and is placed in the Public 
Domain.
> + * This file is a part of the mingw-runtime package.
> + * No warranty is given; refer to the file DISCLAIMER within the 
package.
> + */
> +
> +#include <stdlib.h>
> +#include <wchar.h>
> +
> +int wmain(int, wchar_t **);
> +int main(int argc, char *argv[])
> +{
> +    return wmain(argc, __wargv);
> +}
> diff -u -N -r cygwin-1.7.0-62-old/winsup/mingw/Makefile.in
> cygwin-1.7.0-62/winsup/mingw/Makefile.in
> --- cygwin-1.7.0-62-old/winsup/mingw/Makefile.in   Thu Jul 30 23:38:40 
2009
> +++ cygwin-1.7.0-62/winsup/mingw/Makefile.in   Tue Oct  6 12:45:12 2009
> @@ -221,7 +221,7 @@
>     TARFLAGS="$(TARFLAGS)" \
>     TARFILEEXT="$(TARFILEEXT)"
> 
> -CRT0S = crt1.o dllcrt1.o crt2.o dllcrt2.o CRT_noglob.o crtmt.o crtst.o 
\
> +CRT0S = crt1.o dllcrt1.o crt2.o dllcrt2.o conuni.o winuni.o
> CRT_noglob.o crtmt.o crtst.o \
>     CRT_fp8.o CRT_fp10.o txtmode.o binmode.o
>  MINGW_OBJS = CRTglob.o CRTfmode.o CRTinit.o  dllmain.o gccmain.o \
>          main.o crtst.o mthr_stub.o CRT_fp10.o txtmode.o \
> @@ -364,6 +364,12 @@
>  crt2.o dllcrt2.o:
>     $(CC) -c -D__MSVCRT__ -U__CRTDLL__ $(ALL_CFLAGS) $< -o $@
> 
> +conuni.o:
> +   $(CC) -c -D__MSVCRT__ -U__CRTDLL__ $(ALL_CFLAGS) $< -o $@
> +
> +winuni.o:
> +   $(CC) -c -D__MSVCRT__ -U__CRTDLL__ $(ALL_CFLAGS) $< -o $@
> +
>  check: check-headers
> 
>  TEST_H_OPTIONS = $(ALL_CFLAGS) -Wall -W -Wsystem-headers -c \
> @@ -550,6 +556,8 @@
>  CRTinit.o: CRTinit.c
>  crt1.o: crt1.c init.c
>  crt2.o: crt1.c init.c
> +conuni.o: conuni.c
> +winuni.o: winuni.c
>  crtmt.o: crtmt.c
>  crtst.o: crtst.c
>  ctype_old.o: ctype_old.c
> diff -u -N -r cygwin-1.7.0-62-old/winsup/mingw/winuni.c
> cygwin-1.7.0-62/winsup/mingw/winuni.c
> --- cygwin-1.7.0-62-old/winsup/mingw/winuni.c   Thu Jan  1 00:00:00 1970
> +++ cygwin-1.7.0-62/winsup/mingw/winuni.c   Tue Oct  6 12:48:38 2009
> @@ -0,0 +1,36 @@
> +/*
> + * winuni.c
> + * This file has no copyright assigned and is placed in the Public 
Domain.
> + * This file is a part of the mingw-runtime package.
> + * No warranty is given; refer to the file DISCLAIMER within the 
package.
> + */
> +
> +#define WIN32_LEAN_AND_MEAN
> +#include <windows.h>
> +#include <wchar.h>
> +
> +INT WINAPI wWinMain(
> +    HINSTANCE   hInstance,
> +    HINSTANCE   hPrevInstance,
> +    LPWSTR      pszCmdLine,
> +    INT         nCmdShow);
> +
> +INT WINAPI WinMain(
> +    HINSTANCE   hInstance,
> +    HINSTANCE   hPrevInstance,
> +    LPSTR       pszCmdLine,
> +    INT         nCmdShow)
> +{
> +    static const WCHAR blank[] = {' ', '\t', 0};
> +    WCHAR *pch = GetCommandLineW();
> +    if (*pch == '\"')
> +    {
> +        pch = wcschr(pch + 1, '\"') + 1;
> +    }
> +    else
> +    {
> +        pch = pch + wcscspn(pch, blank);
> +    }
> +    pch = pch + wcsspn(pch, blank);
> +    return wWinMain(hInstance, hPrevInstance, pch, nCmdShow);
> +}
> diff -u -N -r gcc-core-4.4.1-old/gcc/config/i386/cygming.opt
> gcc-core-4.4.1/gcc/config/i386/cygming.opt
> --- gcc-core-4.4.1-old/gcc/config/i386/cygming.opt   Thu Aug  2 19:49:32 
2007
> +++ gcc-core-4.4.1/gcc/config/i386/cygming.opt   Tue Oct  6 13:24:54 
2009
> @@ -45,3 +45,6 @@
>  mwindows
>  Target
>  Create GUI application
> +
> +municode
> +Create Unicode application
> diff -u -N -r gcc-core-4.4.1-old/gcc/config/i386/cygwin.h
> gcc-core-4.4.1/gcc/config/i386/cygwin.h
> --- gcc-core-4.4.1-old/gcc/config/i386/cygwin.h   Sat Feb 21 00:20:38 
2009
> +++ gcc-core-4.4.1/gcc/config/i386/cygwin.h   Tue Oct  6 13:15:16 2009
> @@ -30,13 +30,14 @@
>    %{!mno-cygwin:-D__CYGWIN32__ -D__CYGWIN__ %{!ansi:-Dunix}
> -D__unix__ -D__unix }\
>    %{mwin32|mno-cygwin:-DWIN32 -D_WIN32 -D__WIN32 -D__WIN32__ %{!
> ansi:-DWINNT}}\
>    %{!nostdinc:%{!mno-win32|mno-cygwin:-idirafter ../include/w32api%s
> -idirafter ../../include/w32api%s}}\
> +  %{municode: -DUNICODE -D_UNICODE}\
>  "
> 
>  #undef STARTFILE_SPEC
>  #define STARTFILE_SPEC "\
>    %{shared|mdll: %{mno-cygwin:dllcrt2%O%s}}\
>    %{!shared: %{!mdll: %{!mno-cygwin:crt0%O%s} %{mno-cygwin:crt2%O%s}\
> -  %{pg:gcrt0%O%s}}}\
> +  %{pg:gcrt0%O%s} %{municode: %{mconsole:conuni%O%s} %{mwindows:
> winuni%O%s}}}}\
>    crtbegin.o%s"
> 
>  #undef ENDFILE_SPEC
> diff -u -N -r gcc-core-4.4.1-old/gcc/config/i386/mingw32.h
> gcc-core-4.4.1/gcc/config/i386/mingw32.h
> --- gcc-core-4.4.1-old/gcc/config/i386/mingw32.h   Sat Feb 21 00:20:38 
2009
> +++ gcc-core-4.4.1/gcc/config/i386/mingw32.h   Tue Oct  6 13:18:10 2009
> @@ -59,7 +59,7 @@
>  #define STANDARD_INCLUDE_COMPONENT "MINGW"
> 
>  #undef CPP_SPEC
> -#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT}"
> +#define CPP_SPEC "%{posix:-D_POSIX_SOURCE} %{mthreads:-D_MT}
> %{municode:-DUNICODE -D_UNICODE}"
> 
>  /* For Windows applications, include more libraries, but always include
>     kernel32.  */
> @@ -103,7 +103,9 @@
> 
>  #undef STARTFILE_SPEC
>  #define STARTFILE_SPEC "%{shared|mdll:dllcrt2%O%s} \
> -  %{!shared:%{!mdll:crt2%O%s}} %{pg:gcrt2%O%s} \
> +  %{!shared:%{!mdll:crt2%O%s \
> +  %{municode: %{mconsole:conuni%O%s} %{mwindows:winuni%O%s}}}} \
> +  %{pg:gcrt2%O%s} \
>    crtbegin.o%s"
> 
>  #undef ENDFILE_SPEC
> diff -u -N -r gcc-core-4.4.1-old/gcc/doc/g++.1 
gcc-core-4.4.1/gcc/doc/g++.1
> --- gcc-core-4.4.1-old/gcc/doc/g++.1   Wed Jul 22 17:23:38 2009
> +++ gcc-core-4.4.1/gcc/doc/g++.1   Tue Oct  6 13:32:56 2009
> @@ -838,7 +838,7 @@
>  See i386 and x86\-64 Options.
>  .Sp
>  \&\fIi386 and x86\-64 Windows Options\fR
> -\&\fB\-mconsole \-mcygwin \-mno\-cygwin \-mdll
> +\&\fB\-mconsole \-mcygwin \-mno\-cygwin \-mdll \-municode
>  \&\-mnop\-fun\-dllimport \-mthread \-mwin32 \-mwindows\fR
>  .Sp
>  \&\fIXstormy16 Options\fR
> @@ -14500,6 +14500,12 @@
>  specifies that a \s-1GUI\s0 application is to be generated by
>  instructing the linker to set the \s-1PE\s0 header subsystem type
>  appropriately.
> +.IP "\fB\-municode\fR" 4
> +.IX Item "-municode"
> +This option is available for Cygwin and MinGW targets.  It
> +specifies that a \s-1Unicode\s0 application is to be generated by
> +instructing the linker to set the \s-1PE\s0 header subsystem type
> +appropriately.
>  .PP
>  See also under \fBi386 and x86\-64 Options\fR for standard options.
>  .PP
> diff -u -N -r gcc-core-4.4.1-old/gcc/doc/gcc.1 
gcc-core-4.4.1/gcc/doc/gcc.1
> --- gcc-core-4.4.1-old/gcc/doc/gcc.1   Wed Jul 22 16:53:10 2009
> +++ gcc-core-4.4.1/gcc/doc/gcc.1   Tue Oct  6 13:31:20 2009
> @@ -838,7 +838,7 @@
>  See i386 and x86\-64 Options.
>  .Sp
>  \&\fIi386 and x86\-64 Windows Options\fR
> -\&\fB\-mconsole \-mcygwin \-mno\-cygwin \-mdll
> +\&\fB\-mconsole \-mcygwin \-mno\-cygwin \-mdll \-municode
>  \&\-mnop\-fun\-dllimport \-mthread \-mwin32 \-mwindows\fR
>  .Sp
>  \&\fIXstormy16 Options\fR
> @@ -14500,6 +14500,12 @@
>  specifies that a \s-1GUI\s0 application is to be generated by
>  instructing the linker to set the \s-1PE\s0 header subsystem type
>  appropriately.
> +.IP "\fB\-municode\fR" 4
> +.IX Item "-municode"
> +This option is available for Cygwin and MinGW targets.  It
> +specifies that a \s-1Unicode\s0 application is to be generated by
> +instructing the linker to set the \s-1PE\s0 header subsystem type
> +appropriately.
>  .PP
>  See also under \fBi386 and x86\-64 Options\fR for standard options.
>  .PP
> diff -u -N -r gcc-core-4.4.1-old/gcc/doc/gcc.info
> gcc-core-4.4.1/gcc/doc/gcc.info
> --- gcc-core-4.4.1-old/gcc/doc/gcc.info   Wed Jul 22 17:33:04 2009
> +++ gcc-core-4.4.1/gcc/doc/gcc.info   Tue Oct  6 13:30:34 2009
> @@ -1056,7 +1056,7 @@
>       _x86-64 Options_ See i386 and x86-64 Options.
> 
>       _i386 and x86-64 Windows Options_
> -          -mconsole -mcygwin -mno-cygwin -mdll
> +          -mconsole -mcygwin -mno-cygwin -mdll -municode
>            -mnop-fun-dllimport -mthread -mwin32 -mwindows
> 
>       _Xstormy16 Options_
> @@ -14565,6 +14565,11 @@
>       specifies that a GUI application is to be generated by instructing
>       the linker to set the PE header subsystem type appropriately.
> 
> +`-municode'
> +     This option is available for Cygwin and MinGW targets.  It
> +     specifies that a Unicode application is to be generated by 
instructing
> +     the linker to set the PE header subsystem type appropriately.
> +
>   See also under *note i386 and x86-64 Options:: for standard options.
> 
>  
> diff -u -N -r gcc-core-4.4.1-old/gcc/doc/invoke.texi
> gcc-core-4.4.1/gcc/doc/invoke.texi
> --- gcc-core-4.4.1-old/gcc/doc/invoke.texi   Wed Apr  1 16:18:48 2009
> +++ gcc-core-4.4.1/gcc/doc/invoke.texi   Tue Oct  6 13:32:02 2009
> @@ -826,7 +826,7 @@
>  See i386 and x86-64 Options.
> 
>  @emph{i386 and x86-64 Windows Options}
> -@gccoptlist{-mconsole -mcygwin -mno-cygwin -mdll
> +@gccoptlist{-mconsole -mcygwin -mno-cygwin -mdll -municode
>  -mnop-fun-dllimport -mthread -mwin32 -mwindows}
> 
>  @emph{Xstormy16 Options}
> @@ -15533,6 +15533,13 @@
>  specifies that a GUI application is to be generated by
>  instructing the linker to set the PE header subsystem type
>  appropriately.
> +
> +@item -municode
> +@opindex municode
> +This option is available for Cygwin and MinGW targets.  It
> +specifies that a Unicode application is to be generated by
> +instructing the linker to set the PE header subsystem type
> +appropriately.
>  @end table
> 
>  See also under @ref{i386 and x86-64 Options} for standard options.
> 
> --
> Problem reports:       http://cygwin.com/problems.html
> FAQ:                   http://cygwin.com/faq/
> Documentation:         http://cygwin.com/docs.html
> Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
> 

This feature would be nice for mingw.org and cygwin, but it is already 
present on gcc. To reinvent the wheel makes less sense here IMHO. The 
mingw-w64 supports -municode for gcc 4.5 for the triplet <cpu>-w64-mingw* 
at the moment, as cygwin/mingw don't have unicode startup facility at the 
moment.
And btw the patch here (especially the parts related to gcc) is here on 
the wrong list. And also I would prefer for the gcc patch, that it uses 
current implementation and names, instead of choosing here some new one.

Regards,
Kai Tietz

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple