[Mono-list] Re: [DotGNU]C# compiler command line parsing

Serge serge@wildwestsoftware.com
Thu, 28 Mar 2002 15:26:20 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_0053_01C1D66C.E944D960
Content-Type: text/plain;
	charset="ISO-8859-1"
Content-Transfer-Encoding: 7bit

> That could be easily fixed
> by re-implementing the script in C or C#.

At least under Win2k+ this can be achieved with native shell script.
I'm attaching conversion of your script that works at the Windows command
prompt (under W2k/XP).
Another option is Windows Scripting Host.

Sergey


----- Original Message -----
From: "Rhys Weatherley" <rweather@zip.com.au>
To: "Fergus Henderson" <fjh@cs.mu.OZ.AU>
Cc: "Miguel de Icaza" <miguel@ximian.com>; <mono-list@ximian.com>;
<developers@dotgnu.org>
Sent: Thursday, March 28, 2002 11:31 AM
Subject: [Mono-list] Re: [DotGNU]C# compiler command line parsing


> Fergus Henderson wrote:
>
> > One way to do this would be to just add support for Microsoft's
> > command-line interface to the .NET and Mono C# compilers.  Another way
> > to do it would be to define a Unix-like command-line syntax, and write
> > a wrapper for Microsoft's csc that would convert the Unix-like syntax
> > into Microsoft's syntax and then invoke csc.  Software written in C#
> > could ship with this wrapper program included.
>
> Portable.NET's C# compiler already uses the gcc syntax.
> Attached is a script I wrote to wrap up "csc" and give it
> the same gcc-like syntax, so as to improve interoperability.
>
> Microsoft's syntax does not fit into a Unix environment very
> well, because it uses '/' as a switch character.  I don't see
> why we should dumb down our compilers, when a shell script
> can be used to smarten up Microsoft's.
>
> The only drawback with the script is that it only works in
> Cygwin and Unix environments.  It doesn't work at the
> raw Windows command prompt.  That could be easily fixed
> by re-implementing the script in C or C#.
>
> As another option, Portable.NET's "csant" tool, which is
> a C-only variant of NAnt, supports csc, mcs, and cscc
> syntax transparently.  The XML file describes what needs
> to be compiled, and "csant" converts it into the correct
> conventions depending upon which compiler has been
> configured.  Environment variables or command-line
> options are used to specify which compiler to use.
>
> Cheers,
>
> Rhys.
>
>





------=_NextPart_000_0053_01C1D66C.E944D960
Content-Type: application/octet-stream;
	name="mscsc.cmd"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="mscsc.cmd"

@echo off
: $Id$

goto main

:translate_opt
	set _OPT=%1

	if "%_OPT:~0,1%" == "-" (
		if "%_OPT%" == "-nostdlib" (
			set FLAGS=%FLAGS% /nostdlib
		) else if "%_OPT%" == "-g" (
			set FLAGS=%FLAGS% /debug+
		) else if "%_OPT%" == "-O" (
			set FLAGS=%FLAGS% /o+
		) else if "%_OPT%" == "-O1" (
			set FLAGS=%FLAGS% /o+
		) else if "%_OPT%" == "-O2" (
			set FLAGS=%FLAGS% /o+
		) else if "%_OPT%" == "-O0" (	
			set FLAGS=%FLAGS% /o-
		) else if "%_OPT%" == "-Werror" (
			set FLAGS=%FLAGS% /warnaserror+
		) else if "%_OPT%" == "-Wall" (
			set FLAGS=%FLAGS% /warn:4
		) else if "%_OPT%" == "-Wno-dll-import" (
			set FLAGS=%FLAGS% /nowarn:626
		) else if "%_OPT%" == "-Wno-field-assign" (
			set FLAGS=%FLAGS% /nowarn:649
		) else if "%_OPT%" == "-Wno-event-unused" (
			set FLAGS=%FLAGS% /nowarn:67
		) else if "%_OPT%" == "-fsyntax-check" (
			set FLAGS=%FLAGS% /nooutput
		) else if "%_OPT%" == "-fchecked" (
			set FLAGS=%FLAGS% /checked+
		) else if "%_OPT%" == "-funchecked" (
			set FLAGS=%FLAGS% /checked-
		) else if "%_OPT%" == "-fincremental" (
			set FLAGS=%FLAGS% /incremental
		) else if "%_OPT%" == "-funsafe" (
			set FLAGS=%FLAGS% /unsafe
		) else if "%_OPT%" == "-e" (
			set NEEDARG=_e
		) else if "%_OPT%" == "-o" (
			set NEEDARG=_o
		) else if "%_OPT%" == "-fresources=" (
			set RESOURCES=%RESOURCES% %_OPT:-fresources=%
		) else if "%_OPT:~1,1%" == "D" (
			set DEFINES=%DEFINES% %_OPT:-D=%
		) else if "%_OPT:~1,1%" == "L" (
			set LIBDIRS=%LIBDIRS% %_OPT:-L=%
		) else if "%_OPT:~1,1%" == "l" (
			set LIBRARIES=%LIBRARIES% %_OPT:-l=%
		) else (
			echo %PROGNAME%: Unknown option %_OPT%
			exit 1
		)
	) else (
		if not "%_OPT%" == "%CSC%" set FILES=%FILES% %_OPT%
	)
goto :EOF


:translate_opt_arg
	set _ARG=%1
	if "%NEEDARG%" == "_e" (
		set FLAGS=%FLAGS% /main:%_ARG%
	) else if "%NEEDARG%" == "_o" (
		if /I "%_ARG:~-4%" == ".dll" (
			set FLAGS=%FLAGS% /target:library
		) else if /I "%_ARG:~-4%" == ".exe" (
			set FLAGS=%FLAGS% /target:exe
		) else (
			set FLAGS=%FLAGS% /target:module
		)
	)
	set FLAGS=%FLAGS% /out:%_ARG%
	set NEEDARG=
goto :EOF


:translate
	if "%NEEDARG%" == "" (
		call :translate_opt %1
	) else (
		call :translate_opt_arg %1
	)
goto :EOF


:build_refs
	set _DIR=%1
	set _LIB=%2
	if exist %_DIR%\%_LIB%.dll (
		if "%REFS%" == "" (
			set REFS=%_DIR%\%_LIB%.dll
		) else (
			set REFS=%REFS%;%_DIR%\%_LIB%.dll
		)
	) else if exist %_DIR%\%_LIB% (
		if "%REFS%" == "" (
			set REFS=%_DIR%\%_LIB%
		) else (
			set REFS=%REFS%;%_DIR%\%_LIB%
		)
	)
goto :EOF




:main
set PROGNAME=%0

if "%1" == "" (
	echo Usage: %PROGNAME% csc [options] inputfiles
	exit 1
)

set CSC=%1
set ARGS=%*

set FLAGS=/nologo
set FILES=
set NEEDARG=
set DEFINES=
set LIBDIRS=
set LIBRARIES=
set RESOURCES=
set REFS=

for %%i in (%ARGS%) do (call :translate %%i)

if "%DEFINES%" neq "" set FLAGS=%FLAGS% /d:%DEFINES:~1%

if "%RESOURCES%" neq "" set RESOURCES=%RESOURCES:/=\%
if "%RESOURCES%" neq "" set FLAGS=%FLAGS% /resource:%RESOURCES:~1%

if "%LIBDIRS%" neq "" set LIBDIRS=%LIBDIRS:/=\%
if "%LIBRARIES%" neq "" (
	if "%LIBDIRS%" neq "" (
		for %%i in (%LIBRARIES%) do (
			for %%j in (%LIBDIRS%) do (
				call :build_refs %%j %%i
			)
		)
	)
)
if "%REFS%" neq "" set FLAGS=%FLAGS% /reference:%REFS%

if "%FILES%" neq "" set FILES=%FILES:/=\%

goto execute
echo CSC: %CSC%
echo FLAGS: %FLAGS%
echo FILES: %FILES%
echo LIBDIRS: %LIBDIRS%
echo LIBRARIES: %LIBRARIES%
echo RESOURCES: %RESOURCES%

:execute
echo %CSC% %FLAGS% %FILES%
%CSC% %FLAGS% %FILES%
------=_NextPart_000_0053_01C1D66C.E944D960--