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
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.
45 #****id* mono.cygclass/MONO
47 # Absolute path to the Mono JIT interpreter.
51 #****id* mono.cygclass/MCS
53 # Absolute path to the default Mono C# compiler.
57 #****id* mono.cygclass/GMCS
59 # Absolute path to the Mono C# 2.0/3.0 compiler.
63 #****id* mono.cygclass/DMCS
65 # Absolute path to the Mono C# 4.0 compiler.
69 #****id* mono.cygclass/GACUTIL
71 # Absolute path to the Mono Global Assembly Cache tool.
73 GACUTIL=/usr/bin/gacutil
75 #****id* mono.cygclass/MONO_SNK
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.
81 MONO_SNK=${_privdatadir}/mono.snk
83 #****io* mono.cygclass/HOMEPAGE (mono)
85 HOMEPAGE="https://www.mono-project.com/"
88 #****io* mono.cygclass/SRC_URI (mono)
90 # Download location for sources from the Mono project.
92 #****io* mono.cygclass/GIT_URI (mono)
94 # Location of Git repository for Mono projects.
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
105 # gacinto SUBDIRECTORY
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.
114 error "gacinto accepts exactly one argument";
118 /*|*/*) error "gacinto: argument must be a single subdirectory name" ;;
124 #****iI* mono.cygclass/dogac
126 # [gacinto SUBDIRECTORY]
127 # dogac ASSEMBLY [ASSEMBLY2] ...
129 # Installs the given assembly libraries into the GAC under $D, using the
130 # package name from the previous call to gacinto.
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
140 check_prog_req ${GACUTIL} mono
142 if defined _gacinto_dir
144 gacpkg="-package ${_gacinto_dir}"
149 if [ ! -f ${gacdll} ]
151 error "dogac: ${gacdll}: File not found"
154 ${GACUTIL} -i ${gacdll} ${gacpkg} -gacdir ${D}/usr/lib || error "dogac ${gacdll} failed"
158 #****iI* mono.cygclass/mono_create_policy
160 # mono_create_policy ASSEMBLY_NAME "OLD_VERSIONS" NEW_VERSION STRONGNAME_KEY
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
168 mono_create_policy() {
169 local assembly=${1%.dll}
178 error "mono_create_policy: requires exactly four arguments"
183 error "mono_create_policy: ${snk}: file not found"
186 polv=$(echo ${oldv} | sed -e 's|\([^\.]*\.[^\.]*\)\..*|\1|')
187 token=$(sn -t ${snk} | grep Token: | cut -d' ' -f4)
191 cat > policy.${polv}.${assembly}.config <<_EOF
194 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
196 <assemblyIdentity name="${assembly}" publicKeyToken="${token}"/>
197 <bindingRedirect oldVersion="${oldv}" newVersion="${newv}"/>
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"
210 #****iI* mono.cygclass/mono_wrapper
212 # mono_wrapper SCRIPT_NAME PATH_TO_ASSEMBLY
214 # Creates a wrapper script to launch the given assembly path (as it will be
215 # installed on the system) with Mono.
218 local massembly massemblyfile massemblypath
219 local mscript mscriptfile mscriptpath
223 error "mono_wrapper requires exactly two arguments"
227 mscriptfile=${mscript##*/}
228 case "${mscriptfile}" in
231 mscript=/usr/bin/${mscriptfile} ;;
232 *) mscriptpath=${mscript%/*} ;;
236 massemblyfile=${massembly##*/}
237 massemblypath=${massembly%/*}
241 if [ -x ${D}${mscriptpath}/${massemblyfile} ]
243 dodir ${massemblypath}
244 mv ${D}${mscriptpath}/${massemblyfile} ${D}${massemblypath}
247 if [ ! -f ${D}${massembly} ]
249 error "${massemblyfile} is not installed into ${massemblypath}"
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