import os

class MonoMasterEncryptedPackage(Package):

	def __init__(self):
		Package.__init__(self, 'mono', '3.0.8',
      sources = ['git://github.com/mono/mono', 'git@github.com:xamarin/mono-extensions.git'],
			revision = os.getenv('MONO_BUILD_REVISION'),
			configure_flags = [
				'--enable-nls=no',
				'--prefix=' + Package.profile.prefix,
				'--with-ikvm=yes',
				'--with-moonlight=no'
			]
		)
		if Package.profile.name == 'darwin':
			self.configure_flags.extend([
					# fix build on lion, it uses 64-bit host even with -m32
					'--build=i386-apple-darwin11.2.0',
					'--enable-loadedllvm'
					])

			self.sources.extend ([
					# Fixes up pkg-config usage on the Mac
					'patches/mcs-pkgconfig.patch'
					])

		self.configure = 'CFLAGS=-O2 ./autogen.sh'
		self.make = 'make'

	def apply_extensions(self):
		# Copied from Package#prep, makes sure we get teh latest
		# extensions
		print self.sources
		extension = self.sources[1]
		build_root = os.path.join (os.getcwd (), "..")
		dirname = os.path.join (build_root, os.path.basename (extension))
		if (os.path.exists(dirname)):
			self.cd (dirname)
			self.sh ('git clean -xfd')
			self.sh ('git reset --hard HEAD')
			self.sh ('git pull')
		else:
			self.sh ('git clone --local --shared "%s" "%s"' % (extension, dirname))

		# Use quilt to apply the patch queue
		self.cd (build_root)

		mono = os.path.join (build_root, "mono")
		full_mono = os.path.join (build_root, "%s-%s" % (self.name, self.version))
		if not (os.path.exists (mono) and os.path.join (os.path.dirname (mono), os.readlink (mono)) == full_mono):
			if os.path.exists(mono): os.remove (mono)
			os.symlink (full_mono, mono)

		self.sh ("export QUILT_PATCHES=%s-%s-mono-extensions" % (self.name, self.version))
		self.sh ('/usr/local/bin/quilt pop -af || true') # ignore its return code
		self.sh ('/usr/local/bin/quilt push -a')

	def prep (self):
		Package.prep (self)
		self.apply_extensions()
		self.cd ('%{source_dir_name}')
		if Package.profile.name == 'darwin':
			for p in range (2, len (self.sources)):
				self.sh ('patch -p1 < "%{sources[' + str (p) + ']}"')

MonoMasterEncryptedPackage()

@@ -958,16 +958,33 @@
 _root = 
+os.path.abspath (
 os.path.
@@ -1008,16 +1008,17 @@
 ), %22..%22)
+)
 %0A%09%09dirna
@@ -1485,24 +1485,134 @@
 f.version))%0A
+%09%09full_mono_extensions = os.path.join (build_root, %22%25s-%25s-%25s%22 %25 (self.name, self.version, %22mono-extensions%22))%0A
 %09%09if not (os
@@ -1825,17 +1825,22 @@
 S=%25s
--%25s-
+%22 %25 full_
 mono
--
+_
 exte
@@ -1849,37 +1849,8 @@
 ions
-%22 %25 (self.name, self.version)
 )%0A%09%09
@@ -1850,33 +1850,40 @@
 ons)%0A%09%09self.sh (
-'
+%22cd %25s; 
 /usr/local/bin/q
@@ -1902,17 +1902,30 @@
  %7C%7C true
-'
+%22 %25 build_root
 ) # igno
@@ -1954,17 +1954,24 @@
 elf.sh (
-'
+%22cd %25s; 
 /usr/loc
@@ -1990,17 +1990,30 @@
  push -a
-'
+%22 %25 build_root
 )%0A%0A%09def 

Use absolute path to reference mono-extensions.