Bump version to 0.36.9
[cygport.git] / cygclass / mono.cygclass
blob943779a277d35e250d9ddb617c70ab97810e12de
1 ################################################################################
3 # mono.cygclass - functions for building Mono assemblies
5 # Part of cygport - Cygwin packaging application
6 # Copyright (C) 2006-2020 Cygport authors
7 # Provided by the Cygwin project <https://cygwin.com/>
9 # cygport is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # cygport is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with cygport.  If not, see <https://www.gnu.org/licenses/>.
22 ################################################################################
24 #****ih* Cygclasses/mono.cygclass
25 #  SYNOPSIS
26 #  inherit mono
27 #  DESCRIPTION
28 #  Mono is an open-source implementation of the C# compiler, Common
29 #  Language Runtime (the Windows version of which is known as the .NET
30 #  Framework), and related tools.  The most common FOSS usage of Mono is
31 #  Gtk#, a group of bindings for the GTK+ and GNOME libraries which is used
32 #  by several GNOME applications written in C#.  There are also a number of
33 #  other programming languages implemented on the CLR, some unique (such as
34 #  Boo, Cobra, Nemerle, and VB.NET) and some previously existing (such as
35 #  Java/IKVM, Lua2IL, and mPHP).
37 #  This cygclass sets definitions for downloading and building Mono components,
38 #  and provides functions for installing CLR assemblies and programs.
39 #  INHERITED BY
40 #  nant.cygclass
41 #  REQUIRES
42 #  mono
43 #****
45 #****id* mono.cygclass/MONO
46 #  DESCRIPTION
47 #  Absolute path to the Mono JIT interpreter.
48 #****
49 MONO=/usr/bin/mono
51 #****id* mono.cygclass/MCS
52 #  DESCRIPTION
53 #  Absolute path to the default Mono C# compiler.
54 #****
55 MCS=/usr/bin/mcs
57 #****id* mono.cygclass/GMCS
58 #  DESCRIPTION
59 #  Absolute path to the Mono C# 2.0/3.0 compiler.
60 #****
61 GMCS=/usr/bin/gmcs
63 #****id* mono.cygclass/DMCS
64 #  DESCRIPTION
65 #  Absolute path to the Mono C# 4.0 compiler.
66 #****
67 DMCS=/usr/bin/dmcs
69 #****id* mono.cygclass/GACUTIL
70 #  DESCRIPTION
71 #  Absolute path to the Mono Global Assembly Cache tool.
72 #****
73 GACUTIL=/usr/bin/gacutil
75 #****id* mono.cygclass/MONO_SNK
76 #  DESCRIPTION
77 #  Path to a strongname key that can be used to sign assemblies for installation
78 #  into the GAC which do not ship with their own key.  This key should only
79 #  be used if an upstream key is not available.
80 #****
81 MONO_SNK=${_privdatadir}/mono.snk
83 #****io* mono.cygclass/HOMEPAGE (mono)
84 #  DEFINITION
85 HOMEPAGE="https://www.mono-project.com/"
86 #****
88 #****io* mono.cygclass/SRC_URI (mono)
89 #  DESCRIPTION
90 #  Download location for sources from the Mono project.
91 #****
92 #****io* mono.cygclass/GIT_URI (mono)
93 #  DESCRIPTION
94 #  Location of Git repository for Mono projects.
95 #****
96 if ! defined GIT_URI
97 then
98         SRC_URI="https://download.mono-project.com/sources/${ORIG_PN:-${PN}}/${ORIG_PN:-${PN}}-${PV}.${MONO_SOURCE_TYPE:-tar.bz2}"
99         GIT_URI="git://github.com/mono/${GIT_MODULE:-${ORIG_PN:-${PN}}}.git"
100         SRC_DIR="${SRC_DIR:-${ORIG_PN:-${PN}}-${PV}}"
103 #****iI* mono.cygclass/gacinto
104 #  SYNOPSIS
105 #  gacinto SUBDIRECTORY
106 #  DESCRIPTION
107 #  Package name to use when installing assemblies into the GAC with dogac.
108 #  Symlinks to the assemblies installed with dogac will be created in
109 #  /usr/lib/mono/SUBDIRECTORY.
110 #****
111 gacinto() {
112         if (( $# != 1 ))
113         then
114                 error "gacinto accepts exactly one argument";
115         fi
117         case ${1} in
118                 /*|*/*) error "gacinto: argument must be a single subdirectory name" ;;
119         esac
121         _gacinto_dir=${1};
124 #****iI* mono.cygclass/dogac
125 #  SYNOPSIS
126 #  [gacinto SUBDIRECTORY]
127 #  dogac ASSEMBLY [ASSEMBLY2] ...
128 #  DESCRIPTION
129 #  Installs the given assembly libraries into the GAC under $D, using the
130 #  package name from the previous call to gacinto.
131 #  NOTE
132 #  Assemblies must be strongname signed in order to be installed into the
133 #  GAC.  If an assembly is meant for general consumption but a strongname
134 #  key is not available from upstream, MONO_SNK can be used to sign the
135 #  assembly.
136 #****
137 dogac() {
138         local gacdll gacpkg
140         check_prog_req ${GACUTIL} mono
142         if defined _gacinto_dir
143         then
144                 gacpkg="-package ${_gacinto_dir}"
145         fi
147         for gacdll in $@
148         do
149                 if [ ! -f ${gacdll} ]
150                 then
151                         error "dogac: ${gacdll}: File not found"
152                 fi
154                 ${GACUTIL} -i ${gacdll} ${gacpkg} -gacdir ${D}/usr/lib || error "dogac ${gacdll} failed"
155         done
158 #****iI* mono.cygclass/mono_create_policy
159 #  SYNOPSIS
160 #  mono_create_policy ASSEMBLY_NAME "OLD_VERSIONS" NEW_VERSION STRONGNAME_KEY
161 #  DESCRIPTION
162 #  Creates a policy file within the GAC.  Policy files are used to redirect
163 #  assembly dependencies on (usually) older versions to a new version which is
164 #  still API-compatible.  Versions are in the form of major.minor.micro.patch;
165 #  the old versions argument can be a range (x.y.z.a-x.y.z.a) or use wildcards
166 #  (x.y.*).
167 #****
168 mono_create_policy() {
169         local assembly=${1%.dll}
170         local oldv="$2"
171         local newv=$3
172         local snk=$4
173         local polv
174         local token
176         if (( $# != 4 ))
177         then
178                 error "mono_create_policy: requires exactly four arguments"
179         fi
181         if [ ! -e ${snk} ]
182         then
183                 error "mono_create_policy: ${snk}: file not found"
184         fi
186         polv=$(echo ${oldv} | sed -e 's|\([^\.]*\.[^\.]*\)\..*|\1|')
187         token=$(sn -t ${snk} | grep Token: | cut -d' ' -f4)
189         pushd ${T}
191         cat > policy.${polv}.${assembly}.config <<_EOF
192 <configuration>
193   <runtime>
194     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
195       <dependentAssembly>
196         <assemblyIdentity name="${assembly}" publicKeyToken="${token}"/>
197         <bindingRedirect oldVersion="${oldv}" newVersion="${newv}"/>
198       </dependentAssembly>
199     </assemblyBinding>
200   </runtime>
201 </configuration>
202 _EOF
204         /usr/bin/al -link:policy.${polv}.${assembly}.config -out:policy.${polv}.${assembly}.dll -keyfile:${snk} || error "mono_create_policy: al link failed"
205         ${GACUTIL} -i policy.${polv}.${assembly}.dll -gacdir ${D}/usr/lib || error "mono_create_policy: gacutil install failed"
207         popd # ${T}
210 #****iI* mono.cygclass/mono_wrapper
211 #  SYNOPSIS
212 #  mono_wrapper SCRIPT_NAME PATH_TO_ASSEMBLY
213 #  DESCRIPTION
214 #  Creates a wrapper script to launch the given assembly path (as it will be
215 #  installed on the system) with Mono.
216 #****
217 mono_wrapper() {
218         local massembly massemblyfile massemblypath
219         local mscript mscriptfile mscriptpath
221         if (( $# != 2 ))
222         then
223                 error "mono_wrapper requires exactly two arguments"
224         fi
226         mscript=${1}
227         mscriptfile=${mscript##*/}
228         case "${mscriptfile}" in
229                 "${mscript}")
230                         mscriptpath=/usr/bin
231                         mscript=/usr/bin/${mscriptfile} ;;
232                 *)      mscriptpath=${mscript%/*} ;;
233         esac
235         massembly=${2}
236         massemblyfile=${massembly##*/}
237         massemblypath=${massembly%/*}
239         dodir ${mscriptpath}
241         if [ -x ${D}${mscriptpath}/${massemblyfile} ]
242         then
243                 dodir ${massemblypath}
244                 mv ${D}${mscriptpath}/${massemblyfile} ${D}${massemblypath}
245         fi
247         if [ ! -f ${D}${massembly} ]
248         then
249                 error "${massemblyfile} is not installed into ${massemblypath}"
250         fi
252         echo -e "#!/bin/sh\nexec /usr/bin/mono ${massembly} \"\$@\"" > ${D}${mscript}
253         chmod +x ${D}${mscript}
256 readonly -f gacinto dogac mono_create_policy mono_wrapper