2 # Compile a C# program.
4 # Copyright (C) 2003-2019 Free Software Foundation, Inc.
5 # Written by Bruno Haible <bruno@clisp.org>, 2003.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20 # This uses the same choices as csharpcomp.c, but instead of relying on the
21 # environment settings at run time, it uses the environment variables
22 # present at configuration time.
24 # This is a separate shell script, because the various C# compilers have
25 # different command line options.
27 # Usage: /bin/sh csharpcomp.sh [OPTION] SOURCE.cs ... RES.resource ...
29 # -o PROGRAM.exe or -o LIBRARY.dll
30 # set the output assembly name
31 # -L DIRECTORY search for C# libraries also in DIRECTORY
32 # -l LIBRARY reference the C# library LIBRARY.dll
34 # -g generate debugging information
37 # creates a temporary directory.
39 # - tmp pathname of freshly created temporary directory
42 # Use the environment variable TMPDIR, falling back to /tmp. This allows
43 # users to specify a different temporary directory, for example, if their
44 # /tmp is filled up or too small.
47 # Use the mktemp program if available. If not available, hide the error
49 tmp
=`(umask 077 && mktemp -d -q "$TMPDIR/gtXXXXXX") 2>/dev/null` &&
50 test -n "$tmp" && test -d "$tmp"
53 # Use a simple mkdir command. It is guaranteed to fail if the directory
54 # already exists. $RANDOM is bash specific and expands to empty in shells
55 # other than bash, ksh and zsh. Its use does not increase security;
56 # rather, it minimizes the probability of failure in a very cluttered /tmp
58 tmp
=$TMPDIR/gt$$
-$RANDOM
59 (umask 077 && mkdir
"$tmp")
62 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
67 sed_quote_subst
='s/\([|&;<>()$`"'"'"'*?[#~=% \\]\)/\\\1/g'
71 while test $# != 0; do
76 options_mcs
="$options_mcs -target:library"
77 options_csc
="$options_csc -target:library"
80 options_csc
="$options_csc -target:exe"
83 options_mcs
="$options_mcs -out:"`echo "$2" | sed -e "$sed_quote_subst"`
84 options_csc
="$options_csc -out:"`echo "$2" | sed -e "$sed_quote_subst"`
88 options_mcs
="$options_mcs -lib:"`echo "$2" | sed -e "$sed_quote_subst"`
89 options_csc
="$options_csc -lib:"`echo "$2" | sed -e "$sed_quote_subst"`
93 options_mcs
="$options_mcs -reference:"`echo "$2" | sed -e "$sed_quote_subst"`
94 options_csc
="$options_csc -reference:"`echo "$2" | sed -e "$sed_quote_subst"`".dll"
98 options_csc
="$options_csc -optimize+"
101 options_mcs
="$options_mcs -debug"
102 options_csc
="$options_csc -debug+"
105 echo "csharpcomp: unknown option '$1'" 1>&2
109 options_mcs
="$options_mcs -resource:"`echo "$1" | sed -e "$sed_quote_subst"`
110 options_csc
="$options_csc -resource:"`echo "$1" | sed -e "$sed_quote_subst"`
113 sources
="$sources "`echo "$1" | sed -e "$sed_quote_subst"`
116 echo "csharpcomp: unknown type of argument '$1'" 1>&2
123 if test -n "@HAVE_MCS@"; then
124 # mcs prints it errors and warnings to stdout, not stderr. Furthermore it
125 # adds a useless line "Compilation succeeded..." at the end. Correct both.
126 sed_drop_success_line
='${
127 /^Compilation succeeded/d
130 trap 'rm -rf "$tmp"' 1 2 3 15
131 test -z "$CSHARP_VERBOSE" ||
echo mcs
$options_mcs $sources
132 mcs
$options_mcs $sources > "$tmp"/mcs.err
134 sed -e "$sed_drop_success_line" < "$tmp"/mcs.err
>&2
138 if test -n "@HAVE_CSC@"; then
139 test -z "$CSHARP_VERBOSE" ||
echo csc
$options_csc $sources
140 exec csc
$options_csc $sources
142 echo 'C# compiler not found, try installing mono, then reconfigure' 1>&2