xref: /netbsd-src/external/gpl2/gettext/dist/build-aux/csharpcomp.sh.in (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1*946379e7Schristos#!/bin/sh
2*946379e7Schristos# Compile a C# program.
3*946379e7Schristos
4*946379e7Schristos# Copyright (C) 2003-2006 Free Software Foundation, Inc.
5*946379e7Schristos# Written by Bruno Haible <bruno@clisp.org>, 2003.
6*946379e7Schristos#
7*946379e7Schristos# This program is free software; you can redistribute it and/or modify
8*946379e7Schristos# it under the terms of the GNU General Public License as published by
9*946379e7Schristos# the Free Software Foundation; either version 2, or (at your option)
10*946379e7Schristos# any later version.
11*946379e7Schristos#
12*946379e7Schristos# This program is distributed in the hope that it will be useful,
13*946379e7Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*946379e7Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*946379e7Schristos# GNU General Public License for more details.
16*946379e7Schristos#
17*946379e7Schristos# You should have received a copy of the GNU General Public License
18*946379e7Schristos# along with this program; if not, write to the Free Software Foundation,
19*946379e7Schristos# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20*946379e7Schristos
21*946379e7Schristos# This uses the same choices as csharpcomp.c, but instead of relying on the
22*946379e7Schristos# environment settings at run time, it uses the environment variables
23*946379e7Schristos# present at configuration time.
24*946379e7Schristos#
25*946379e7Schristos# This is a separate shell script, because the various C# compilers have
26*946379e7Schristos# different command line options.
27*946379e7Schristos#
28*946379e7Schristos# Usage: /bin/sh csharpcomp.sh [OPTION] SOURCE.cs ... RES.resource ...
29*946379e7Schristos# Options:
30*946379e7Schristos#   -o PROGRAM.exe  or  -o LIBRARY.dll
31*946379e7Schristos#                     set the output assembly name
32*946379e7Schristos#   -L DIRECTORY      search for C# libraries also in DIRECTORY
33*946379e7Schristos#   -l LIBRARY        reference the C# library LIBRARY.dll
34*946379e7Schristos#   -O                optimize
35*946379e7Schristos#   -g                generate debugging information
36*946379e7Schristos
37*946379e7Schristos# func_tmpdir
38*946379e7Schristos# creates a temporary directory.
39*946379e7Schristos# Sets variable
40*946379e7Schristos# - tmp             pathname of freshly created temporary directory
41*946379e7Schristosfunc_tmpdir ()
42*946379e7Schristos{
43*946379e7Schristos  # Use the environment variable TMPDIR, falling back to /tmp. This allows
44*946379e7Schristos  # users to specify a different temporary directory, for example, if their
45*946379e7Schristos  # /tmp is filled up or too small.
46*946379e7Schristos  : ${TMPDIR=/tmp}
47*946379e7Schristos  {
48*946379e7Schristos    # Use the mktemp program if available. If not available, hide the error
49*946379e7Schristos    # message.
50*946379e7Schristos    tmp=`(umask 077 && mktemp -d -q "$TMPDIR/gtXXXXXX") 2>/dev/null` &&
51*946379e7Schristos    test -n "$tmp" && test -d "$tmp"
52*946379e7Schristos  } ||
53*946379e7Schristos  {
54*946379e7Schristos    # Use a simple mkdir command. It is guaranteed to fail if the directory
55*946379e7Schristos    # already exists.  $RANDOM is bash specific and expands to empty in shells
56*946379e7Schristos    # other than bash, ksh and zsh.  Its use does not increase security;
57*946379e7Schristos    # rather, it minimizes the probability of failure in a very cluttered /tmp
58*946379e7Schristos    # directory.
59*946379e7Schristos    tmp=$TMPDIR/gt$$-$RANDOM
60*946379e7Schristos    (umask 077 && mkdir "$tmp")
61*946379e7Schristos  } ||
62*946379e7Schristos  {
63*946379e7Schristos    echo "$0: cannot create a temporary directory in $TMPDIR" >&2
64*946379e7Schristos    { (exit 1); exit 1; }
65*946379e7Schristos  }
66*946379e7Schristos}
67*946379e7Schristos
68*946379e7Schristossed_quote_subst='s/\([|&;<>()$`"'"'"'*?[#~=% 	\\]\)/\\\1/g'
69*946379e7Schristosoptions_cscc=
70*946379e7Schristosoptions_mcs=
71*946379e7Schristosoptions_csc="-nologo"
72*946379e7Schristossources=
73*946379e7Schristoswhile test $# != 0; do
74*946379e7Schristos  case "$1" in
75*946379e7Schristos    -o)
76*946379e7Schristos      case "$2" in
77*946379e7Schristos        *.dll)
78*946379e7Schristos          options_cscc="$options_cscc -shared"
79*946379e7Schristos          options_mcs="$options_mcs -target:library"
80*946379e7Schristos          options_csc="$options_csc -target:library"
81*946379e7Schristos          ;;
82*946379e7Schristos        *.exe)
83*946379e7Schristos          options_csc="$options_csc -target:exe"
84*946379e7Schristos          ;;
85*946379e7Schristos      esac
86*946379e7Schristos      options_cscc="$options_cscc -o "`echo "$2" | sed -e "$sed_quote_subst"`
87*946379e7Schristos      options_mcs="$options_mcs -out:"`echo "$2" | sed -e "$sed_quote_subst"`
88*946379e7Schristos      options_csc="$options_csc -out:"`echo "$2" | sed -e "$sed_quote_subst"`
89*946379e7Schristos      shift
90*946379e7Schristos      ;;
91*946379e7Schristos    -L)
92*946379e7Schristos      options_cscc="$options_cscc -L "`echo "$2" | sed -e "$sed_quote_subst"`
93*946379e7Schristos      options_mcs="$options_mcs -lib:"`echo "$2" | sed -e "$sed_quote_subst"`
94*946379e7Schristos      options_csc="$options_csc -lib:"`echo "$2" | sed -e "$sed_quote_subst"`
95*946379e7Schristos      shift
96*946379e7Schristos      ;;
97*946379e7Schristos    -l)
98*946379e7Schristos      options_cscc="$options_cscc -l "`echo "$2" | sed -e "$sed_quote_subst"`
99*946379e7Schristos      options_mcs="$options_mcs -reference:"`echo "$2" | sed -e "$sed_quote_subst"`
100*946379e7Schristos      options_csc="$options_csc -reference:"`echo "$2" | sed -e "$sed_quote_subst"`".dll"
101*946379e7Schristos      shift
102*946379e7Schristos      ;;
103*946379e7Schristos    -O)
104*946379e7Schristos      options_cscc="$options_cscc -O"
105*946379e7Schristos      options_csc="$options_csc -optimize+"
106*946379e7Schristos      ;;
107*946379e7Schristos    -g)
108*946379e7Schristos      options_cscc="$options_cscc -g"
109*946379e7Schristos      options_mcs="$options_mcs -debug"
110*946379e7Schristos      options_csc="$options_csc -debug+"
111*946379e7Schristos      ;;
112*946379e7Schristos    -*)
113*946379e7Schristos      echo "csharpcomp: unknown option '$1'" 1>&2
114*946379e7Schristos      exit 1
115*946379e7Schristos      ;;
116*946379e7Schristos    *.resources)
117*946379e7Schristos      options_cscc="$options_cscc -fresources="`echo "$1" | sed -e "$sed_quote_subst"`
118*946379e7Schristos      options_mcs="$options_mcs -resource:"`echo "$1" | sed -e "$sed_quote_subst"`
119*946379e7Schristos      options_csc="$options_csc -resource:"`echo "$1" | sed -e "$sed_quote_subst"`
120*946379e7Schristos      ;;
121*946379e7Schristos    *.cs)
122*946379e7Schristos      sources="$sources "`echo "$1" | sed -e "$sed_quote_subst"`
123*946379e7Schristos      ;;
124*946379e7Schristos    *)
125*946379e7Schristos      echo "csharpcomp: unknown type of argument '$1'" 1>&2
126*946379e7Schristos      exit 1
127*946379e7Schristos      ;;
128*946379e7Schristos  esac
129*946379e7Schristos  shift
130*946379e7Schristosdone
131*946379e7Schristos
132*946379e7Schristosif test -n "@HAVE_CSCC@"; then
133*946379e7Schristos  test -z "$CSHARP_VERBOSE" || echo cscc $options_cscc $sources
134*946379e7Schristos  exec cscc $options_cscc $sources
135*946379e7Schristoselse
136*946379e7Schristos  if test -n "@HAVE_MCS@"; then
137*946379e7Schristos    # mcs prints it errors and warnings to stdout, not stderr. Furthermore it
138*946379e7Schristos    # adds a useless line "Compilation succeeded..." at the end. Correct both.
139*946379e7Schristos    sed_drop_success_line='${
140*946379e7Schristos/^Compilation succeeded/d
141*946379e7Schristos}'
142*946379e7Schristos    func_tmpdir
143*946379e7Schristos    trap 'rm -rf "$tmp"' 1 2 3 15
144*946379e7Schristos    test -z "$CSHARP_VERBOSE" || echo mcs $options_mcs $sources
145*946379e7Schristos    mcs $options_mcs $sources > "$tmp"/mcs.err
146*946379e7Schristos    result=$?
147*946379e7Schristos    sed -e "$sed_drop_success_line" < "$tmp"/mcs.err >&2
148*946379e7Schristos    rm -rf "$tmp"
149*946379e7Schristos    exit $result
150*946379e7Schristos  else
151*946379e7Schristos    if test -n "@HAVE_CSC@"; then
152*946379e7Schristos      test -z "$CSHARP_VERBOSE" || echo csc $options_csc $sources
153*946379e7Schristos      exec csc $options_csc $sources
154*946379e7Schristos    else
155*946379e7Schristos      echo 'C# compiler not found, try installing pnet, then reconfigure' 1>&2
156*946379e7Schristos      exit 1
157*946379e7Schristos    fi
158*946379e7Schristos  fi
159*946379e7Schristosfi
160