2 # Compile a C# program.
4 # Copyright (C) 2003-2005 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 2, or (at your option)
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, write to the Free Software Foundation,
19 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 # This uses the same choices as csharpcomp.c, but instead of relying on the
22 # environment settings at run time, it uses the environment variables
23 # present at configuration time.
25 # This is a separate shell script, because the various C# compilers have
26 # different command line options.
28 # Usage: /bin/sh csharpcomp.sh [OPTION] SOURCE.cs ... RES.resource ...
30 # -o PROGRAM.exe or -o LIBRARY.dll
31 # set the output assembly name
32 # -L DIRECTORY search for C# libraries also in DIRECTORY
33 # -l LIBRARY reference the C# library LIBRARY.dll
35 # -g generate debugging information
38 # creates a temporary directory.
40 # - tmp pathname of freshly created temporary directory
43 # Use the environment variable TMPDIR, falling back to /tmp. This allows
44 # users to specify a different temporary directory, for example, if their
45 # /tmp is filled up or too small.
48 # Use the mktemp program if available. If not available, hide the error
50 tmp
=`(umask 077 && mktemp -d "$TMPDIR/gtXXXXXX") 2>/dev/null` &&
51 test -n "$tmp" && test -d "$tmp"
54 # Use a simple mkdir command. It is guaranteed to fail if the directory
55 # already exists. $RANDOM is bash specific and expands to empty in shells
56 # other than bash, ksh and zsh. Its use does not increase security;
57 # rather, it minimizes the probability of failure in a very cluttered /tmp
59 tmp
=$TMPDIR/gt$$
-$RANDOM
60 (umask 077 && mkdir
"$tmp")
63 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
68 sed_quote_subst
='s/\([|&;<>()$`"'"'"'*?[#~=% \\]\)/\\\1/g'
73 while test $# != 0; do
78 options_cscc
="$options_cscc -shared"
79 options_mcs
="$options_mcs -target:library"
80 options_csc
="$options_csc -target:library"
83 options_csc
="$options_csc -target:exe"
86 options_cscc
="$options_cscc -o "`echo "$2" | sed -e "$sed_quote_subst"`
87 options_mcs
="$options_mcs -o "`echo "$2" | sed -e "$sed_quote_subst"`
88 options_csc
="$options_csc -out:"`echo "$2" | sed -e "$sed_quote_subst"`
92 options_cscc
="$options_cscc -L "`echo "$2" | sed -e "$sed_quote_subst"`
93 options_mcs
="$options_mcs -L "`echo "$2" | sed -e "$sed_quote_subst"`
94 options_csc
="$options_csc -lib:"`echo "$2" | sed -e "$sed_quote_subst"`
98 options_cscc
="$options_cscc -l "`echo "$2" | sed -e "$sed_quote_subst"`
99 options_mcs
="$options_mcs -r "`echo "$2" | sed -e "$sed_quote_subst"`
100 options_csc
="$options_csc -reference:"`echo "$2" | sed -e "$sed_quote_subst"`".dll"
104 options_cscc
="$options_cscc -O"
105 options_csc
="$options_csc -optimize+"
108 options_cscc
="$options_cscc -g"
109 options_mcs
="$options_mcs -g"
110 options_csc
="$options_csc -debug+"
113 echo "csharpcomp: unknown option '$1'" 1>&2
117 options_cscc
="$options_cscc -fresources="`echo "$1" | sed -e "$sed_quote_subst"`
118 options_mcs
="$options_mcs -resource:"`echo "$1" | sed -e "$sed_quote_subst"`
119 options_csc
="$options_csc -resource:"`echo "$1" | sed -e "$sed_quote_subst"`
122 sources
="$sources "`echo "$1" | sed -e "$sed_quote_subst"`
125 echo "csharpcomp: unknown type of argument '$1'" 1>&2
132 if test -n "@HAVE_CSCC@"; then
133 test -z "$CSHARP_VERBOSE" ||
echo cscc
$options_cscc $sources
134 exec cscc
$options_cscc $sources
136 if test -n "@HAVE_MCS@"; then
137 # mcs prints it errors and warnings to stdout, not stderr. Furthermore it
138 # adds a useless line "Compilation succeeded..." at the end. Correct both.
139 sed_drop_success_line
='${
140 /^Compilation succeeded/d
143 trap 'rm -rf "$tmp"' 1 2 3 15
144 test -z "$CSHARP_VERBOSE" ||
echo mcs
$options_mcs $sources
145 mcs
$options_mcs $sources > "$tmp"/mcs.err
147 sed -e "$sed_drop_success_line" < "$tmp"/mcs.err
>&2
151 if test -n "@HAVE_CSC@"; then
152 test -z "$CSHARP_VERBOSE" ||
echo csc
$options_csc $sources
153 exec csc
$options_csc $sources
155 echo 'C# compiler not found, try installing pnet, then reconfigure' 1>&2