log10l: Work around inaccurate implementation on NetBSD.
[gnulib.git] / build-aux / csharpcomp.sh.in
blob09eada3a5fbeb1c4d9d39d6f2fb41b55adf4e10b
1 #!/bin/sh
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 ...
28 # Options:
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
33 # -O optimize
34 # -g generate debugging information
36 # func_tmpdir
37 # creates a temporary directory.
38 # Sets variable
39 # - tmp pathname of freshly created temporary directory
40 func_tmpdir ()
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.
45 : ${TMPDIR=/tmp}
47 # Use the mktemp program if available. If not available, hide the error
48 # message.
49 tmp=`(umask 077 && mktemp -d -q "$TMPDIR/gtXXXXXX") 2>/dev/null` &&
50 test -n "$tmp" && test -d "$tmp"
51 } ||
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
57 # directory.
58 tmp=$TMPDIR/gt$$-$RANDOM
59 (umask 077 && mkdir "$tmp")
60 } ||
62 echo "$0: cannot create a temporary directory in $TMPDIR" >&2
63 { (exit 1); exit 1; }
67 sed_quote_subst='s/\([|&;<>()$`"'"'"'*?[#~=% \\]\)/\\\1/g'
68 options_mcs=
69 options_csc="-nologo"
70 sources=
71 while test $# != 0; do
72 case "$1" in
73 -o)
74 case "$2" in
75 *.dll)
76 options_mcs="$options_mcs -target:library"
77 options_csc="$options_csc -target:library"
79 *.exe)
80 options_csc="$options_csc -target:exe"
82 esac
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"`
85 shift
87 -L)
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"`
90 shift
92 -l)
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"
95 shift
97 -O)
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
106 exit 1
108 *.resources)
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"`
112 *.cs)
113 sources="$sources "`echo "$1" | sed -e "$sed_quote_subst"`
116 echo "csharpcomp: unknown type of argument '$1'" 1>&2
117 exit 1
119 esac
120 shift
121 done
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
129 func_tmpdir
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
133 result=$?
134 sed -e "$sed_drop_success_line" < "$tmp"/mcs.err >&2
135 rm -rf "$tmp"
136 exit $result
137 else
138 if test -n "@HAVE_CSC@"; then
139 test -z "$CSHARP_VERBOSE" || echo csc $options_csc $sources
140 exec csc $options_csc $sources
141 else
142 echo 'C# compiler not found, try installing mono, then reconfigure' 1>&2
143 exit 1