summaryrefslogtreecommitdiff
path: root/src/build/msil.xml
blob: e64c88714fe643f6622190180111ee6f895fac02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<?xml version="1.0" encoding="UTF-8"?>

<project name="sabbus-msil">

  <description>
    SuperSabbus extension for the MSIL library targeted for the dotnet framework. THIS FILE IS NOT STAND-ALONE AND SHOULD ONLY BE USED THROUGH ENTRY POINTS IN SUPERSABBUS.
  </description>

  <!-- TODO: test / make it work on Windows (use <ilasm/> task) -->
  <!-- TODO: for separate compilation: make sure only files that have been changed
             since last run are re-compiled -->
  <!-- TODO: run test suite (or at least a part of it) on .NET -->
  <!-- TODO: generate scaladoc of .NET library -->
  <!-- TODO: (?) generate the runner scripts with scala.tools.ant.ScalaTool -->

<!-- ===========================================================================
PROPERTIES
============================================================================ -->

  <!-- contains the scala-net / scalac-net commands -->
  <property name="src-mono.dir" value="${src.dir}/mono"/>

  <!-- Loads custom properties definitions -->
  <property file="${src.dir}/build/msil.properties"/>

  <!-- Sets location of build folders -->
  <property name="build-msil.dir" value="${build.dir}/msil"/>
  <property name="build-msil-src.dir" value="${build.dir}/msil-src"/>
  <property name="build-msil-pack.dir" value="${build.dir}/msil-pack"/>


<!-- ===========================================================================
INITIALISATION
============================================================================ -->
  <target name="msil.init">
    <!-- define the "ilasm" task (and others). they are in fact already there from
         antlib.xml, but in a deprecated version. -->
    <!-- <taskdef resource="org/apache/ant/dotnet/antlib.xml"
             classpath="${lib-ant.dir}/ant-dotnet-1.0.jar"/> -->

    <!-- Sets ilasm command. Search in
           - dotnet.home/ilasm.exe
           - unix.mono.home/ilasm
           - win.mono.home/lib/mono/2.0/ilasm.exe
           - path
         (the ".home"s can be set in msil.properties) -->
    <condition property="ilasm.cmd" value="${dotnet.home}/ilasm.exe">
      <and>
        <os family="windows"/><isset property="dotnet.home"/>
        <available file="${dotnet.home}/ilasm.exe"/>
      </and>
    </condition>
    <condition property="ilasm.cmd" value="${unix.mono.home}/ilasm">
      <and>
        <os family="unix"/><isset property="unix.mono.home"/>
        <available file="${unix.mono.home}/ilasm"/>
      </and>
    </condition>
    <condition property="ilasm.cmd" value="${win.mono.home}/ilasm">
      <and>
        <os family="windows"/><isset property="win.mono.home"/>
        <available file="${win.mono.home}/lib/mono/2.0/ilasm.exe"/>
      </and>
    </condition>
    <condition property="ilasm.cmd" value="ilasm">
      <and><available file="ilasm" filepath="${env.PATH}"/></and>
    </condition>
    <echo level="verbose" message="Found: ${ilasm.cmd}"/>
    <fail message="Command 'ilasm' not found">
      <condition><not><isset property="ilasm.cmd"/></not></condition>
    </fail>

    <!-- Sets ilasm arguments (either Windows or Unix) -->
    <if>
      <isset property="os.win"/>
      <then>
        <property
          name="ilasm.args"
          value="/quiet /dll /output="
        />
      </then>
      <else>
        <property
          name="ilasm.args"
          value="/dll /output:"
        />
      </else>
    </if>
  </target>


<!-- ===========================================================================
MSIL BUILD
============================================================================ -->

  <target name="msil.start" depends="msil.init"/>

  <target name="msil.src" depends="msil.start">
    <!-- simple sync & copy overwrite is not very nice, because overwritten files
         will then have a new timestamp, and be recompiled -->
    <mkdir dir="${build-msil-src.dir}"/>
    <copy todir="${build-msil-src.dir}" overwrite="true">
      <!-- FIXME: include new collection library -->
      <fileset dir="${src.dir}/library" excludes="scalax/**">
        <and>
          <present present="srconly" targetdir="${src.dir}/dotnet-library"/>
          <different targetdir="${build-msil-src.dir}" ignoreFileTimes="true"/>
        </and>
      </fileset>
      <!-- FIXME: include new collection library -->
      <fileset dir="${src.dir}/dotnet-library" excludes="scalax/**">
        <different targetdir="${build-msil-src.dir}" ignoreFileTimes="true"/>
      </fileset>
    </copy>
    <delete verbose="true">
      <difference>
        <fileset dir="${build-msil-src.dir}"/>
        <union>
          <fileset dir="${build-msil-src.dir}">
            <present targetdir="${src.dir}/dotnet-library"/>
          </fileset>
          <fileset dir="${build-msil-src.dir}">
            <present targetdir="${src.dir}/library"/>
          </fileset>
        </union>
      </difference>
    </delete>
  </target>

  <target name="msil.lib" depends="msil.src">
    <stopwatch name="msil.lib.timer"/>
    <mkdir dir="${build-msil.dir}/library"/>
    <!-- <ilasm srcdir="${msil.dir}/il" includes="*.msil" outputfile="${msil.dir}/lib/predef.dll"/> -->

    <scalac
        srcdir="${build-msil-src.dir}"
        destdir="${build-msil.dir}/library"
        target="msil"
        assemname="predef.msil"
        assemrefs="${lib.dir}">
      <include name="**/*.scala"/>
      <exclude name="scala/ScalaObject.scala"/>
    </scalac>
    <stopwatch name="msil.lib.timer" action="total"/>
  </target>

  <target name="msil.done" depends="msil.lib"/>

  <target name="msil.clean" depends="msil-pack.clean">
    <delete dir="${build-msil.dir}" includeemptydirs="yes" quiet="yes" failonerror="no"/>
    <delete dir="${build-msil-src.dir}" includeemptydirs="yes" quiet="yes" failonerror="no"/>
  </target>

<!-- ===========================================================================
PACKED MSIL BUILD (MSIL-PACK)
============================================================================ -->

  <target name="msil-pack.start" depends="msil.done"/>

  <target name="msil-pack.lib" depends="msil-pack.start">
    <mkdir dir="${build-msil-pack.dir}/lib"/>
    <pathconvert property="ilasm.infiles" pathsep=" ">
      <fileset dir="${build-msil.dir}/library" includes="**/*.msil"/>
    </pathconvert>
    <property name="msil-pack-lib.file" value="${build-msil-pack.dir}/lib/predef.dll"/>

    <!--
        NOTE: Command line length hell on windows. The maximal command line length on
        Windows XP or later is 8191 characters (http://support.microsoft.com/kb/830473).

        BUT: this only applies for processes executed directly in the shell, which is NOT
        the case by default when using ant's "exec" command; this one uses the Java VM's
        execution facilities which allow larger command lines. Testing gives:
          - Windows XP: 32768 characters

        When the parameter (vmlauncher="false") is specified, the <exec/> command uses
        the udnerlying shell, and the smaller limit applies.

        The call to ilasm produces lots of output, which could be avoided using
        (spawn="true"). This seems to work wrt to the character limit (32768), but is
        probably not the best solution since it's incompatible with (failonerror),
        and does not produce any output at all.
    -->
    <exec executable="${ilasm.cmd}" failonerror="true">
      <arg line="${ilasm.args}${msil-pack-lib.file} ${ilasm.infiles}"/>
    </exec>
  </target>

  <target name="msil-pack.bin" depends="msil-pack.lib">
    <mkdir dir="${build-msil-pack.dir}/bin"/>
    <copy todir="${build-msil-pack.dir}/bin">
      <fileset
        dir="${src-mono.dir}/bin"
        includes="scala-net*"
      />
      <filterset>
        <filter token="VERSION" value="${version.number}"/>
        <filter token="COPYRIGHT" value="${copyright.string}"/>
        <filter token="NAME" value="Scala code runner"/>
      </filterset>
    </copy>
    <copy todir="${build-msil-pack.dir}/bin">
      <fileset
        dir="${src-mono.dir}/bin"
        includes="scalac-net*"
      />
      <filterset>
        <filter token="VERSION" value="${version.number}"/>
        <filter token="COPYRIGHT" value="${copyright.string}"/>
        <filter token="NAME" value="Scala compiler"/>
      </filterset>
    </copy>
    <chmod perm="ugo+rx" dir="${build-msil-pack.dir}/bin"
           includes="scala*-net*" excludes="*.bat"/>

    <if>
      <isset property="os.win"/>
      <then>
        <copy todir="${build-msil-pack.dir}/lib">
          <fileset
              dir="${lib.dir}"
              includes="mscorlib.dll,scalaruntime.dll"/>
          <fileset
              dir="${build-pack.dir}/lib"
              includes="scala-compiler.jar,scala-library.jar"/>
        </copy>
      </then>
      <else>
        <symlink
            link="${build-msil-pack.dir}/lib/mscorlib.dll"
            resource="${lib.dir}/mscorlib.dll"
            overwrite="yes"/>
        <symlink
            link="${build-msil-pack.dir}/lib/scalaruntime.dll"
            resource="${lib.dir}/scalaruntime.dll"
            overwrite="yes"/>
        <symlink
            link="${build-msil-pack.dir}/lib/scala-compiler.jar"
            resource="${build-pack.dir}/lib/scala-compiler.jar"
            overwrite="yes"/>
        <symlink
            link="${build-msil-pack.dir}/lib/scala-library.jar"
            resource="${build-pack.dir}/lib/scala-library.jar"
            overwrite="yes"/>
      </else>
    </if>
  </target>

  <target name="msil-pack.done" depends="msil-pack.bin"/>

  <target name="msil-pack.clean">
    <delete dir="${build-msil-pack.dir}" includeemptydirs="yes" quiet="yes" failonerror="no"/>
  </target>

<!-- ===========================================================================
DOCUMENTATION
============================================================================ -->

  <!-- see four.xml for template -->
  <target name="msil-docs.done"/>

  <target name="msil-docs.clean"/>

<!-- ===========================================================================
BOOTRAPING TEST AND TEST SUITE
============================================================================ -->

  <!-- see four.xml for template -->
  <target name="msil-test.done"/>


<!-- ===========================================================================
DISTRIBUTION
============================================================================ -->

  <target name="msil-dist.start" depends="msil-pack.done">
    <property name="msil-dist.dir" value="${dists.dir}/scala-msil-${version.number}"/>
  </target>

  <target name="msil-dist.lib" depends="msil-dist.start">
    <mkdir dir="${msil-dist.dir}/lib"/>
    <copy toDir="${msil-dist.dir}/lib">
      <fileset dir="${build-msil-pack.dir}/lib"
               includes="*.dll"/>
      <fileset dir="${build-msil-pack.dir}/lib"
               includes="scala-compiler.jar,scala-library.jar"/>
    </copy>
  </target>

  <target name="msil-dist.bin" depends="msil-dist.lib">
    <mkdir dir="${msil-dist.dir}/bin"/>
    <copy toDir="${msil-dist.dir}/bin">
      <fileset dir="${build-msil-pack.dir}/bin"
               includes="scala*-net*"/>
    </copy>
    <chmod perm="ugo+rx" dir="${msil-dist.dir}/bin"
           includes="scala*-net*" excludes="*.bat"/>
  </target>

  <target name="msil-dist.latest" depends="msil-dist.bin" unless="os.win">
    <symlink link="${dists.dir}/latest-msil" resource="${msil-dist.dir}" overwrite="yes"/>
  </target>

  <target name="msil-dist.done" depends="msil-dist.latest"/>

<!-- ===========================================================================
TEST AND DISTRIBUTION BUNDLE (ALL)
============================================================================ -->

  <target name="msil-all.done" depends="msil-dist.done, msil-test.done"/>

  <target name="msil-all.clean" depends="msil-docs.clean, msil.clean"/>

</project>