2007-10-08 Mark Probst <mark.probst@gmail.com>
[mono.git] / mono / mini / Makefile.am
1 count=100000
2 mtest=for_loop
3 monodir=$(top_builddir)
4
5 # This is needed for automake dependency generation
6 if INCLUDED_LIBGC
7 libgc_libs=$(monodir)/libgc/libmonogc.la
8 libgc_static_libs=$(monodir)/libgc/libmonogc-static.la
9 else
10 libgc_libs=$(LIBGC_LIBS)
11 libgc_static_libs=$(LIBGC_STATIC_LIBS)
12 endif
13
14 libs=   \
15         $(monodir)/mono/metadata/libmonoruntime.la      \
16         $(monodir)/mono/io-layer/libwapi.la     \
17         $(monodir)/mono/utils/libmonoutils.la \
18         $(GLIB_LIBS)    \
19         $(libgc_libs)
20
21 static_libs=    \
22         $(monodir)/mono/metadata/libmonoruntime-static.la       \
23         $(monodir)/mono/io-layer/libwapi.la     \
24         $(monodir)/mono/utils/libmonoutils.la \
25         $(GLIB_LIBS)    \
26         $(libgc_static_libs)
27
28 CLASS1=$(mcs_topdir)/class/lib/default
29 CLASS2=$(mcs_topdir)/class/lib/net_2_0
30
31 RUNTIME = MONO_PATH=$(CLASS1) $(top_builddir)/runtime/mono-wrapper
32 RUNTIME2 = MONO_PATH=$(CLASS2) $(top_builddir)/runtime/mono-wrapper
33 RUNTIME_AOTCHECK = MONO_PATH=$(CLASS1):. $(top_builddir)/runtime/mono-wrapper
34 RUNTIME_AOTCHECK2 = MONO_PATH=$(CLASS2):. $(top_builddir)/runtime/mono-wrapper
35
36 MCS = $(RUNTIME) $(CLASS1)/mcs.exe -unsafe -nowarn:0162
37 GMCS = $(RUNTIME2) $(CLASS2)/gmcs.exe -unsafe -nowarn:0162
38 ILASM = $(RUNTIME) $(CLASS1)/ilasm.exe
39 ILASM2 = $(RUNTIME2) $(CLASS2)/ilasm.exe
40
41 AM_CFLAGS = \
42         -I$(top_srcdir)         \
43         $(LIBGC_CFLAGS)         \
44         $(GLIB_CFLAGS)
45         $(PLATFORM_CFLAGS) $(ARCH_CFLAGS)
46
47 if PLATFORM_WIN32
48 export HOST_CC
49 # The mingw math.h has "extern inline" functions that dont appear in libs, so
50 # optimisation is required to actually inline them
51 PLATFORM_CFLAGS = -O
52 endif
53
54 # hack for automake to have the same source file in a library and a bin
55 genmdesc_CFLAGS = $(AM_CFLAGS)
56
57 if NO_VERSION_SCRIPT
58 monoldflags=$(export_ldflags)
59 monobinldflags=$(export_ldflags)
60 else
61 monoldflags=-Wl,-version-script=$(srcdir)/ldscript $(export_ldflags)
62 monobinldflags=-Wl,-version-script=$(srcdir)/ldscript.mono $(export_ldflags)
63 endif
64
65 if PLATFORM_WIN32
66 libmono_la_LDFLAGS=-no-undefined -avoid-version $(monoldflags)
67 else
68 libmono_la_LDFLAGS=$(monoldflags)
69 endif
70
71 if JIT_SUPPORTED
72
73 if PLATFORM_WIN32
74 bin_PROGRAMS = mono monow
75 else
76 bin_PROGRAMS = mono
77 endif
78
79 noinst_PROGRAMS = genmdesc
80
81 lib_LTLIBRARIES = libmono.la
82 noinst_LTLIBRARIES = libmono-static.la
83 endif
84
85 mono_SOURCES = \
86         main.c
87
88 if STATIC_MONO
89 # Link libmono into mono statically
90 # This leads to higher performance, especially with TLS
91 MONO_LIB=libmono-static.la
92 else 
93 MONO_LIB=libmono.la
94 endif
95
96 mono_LDADD = \
97         $(MONO_LIB)                     \
98         $(GLIB_LIBS)            \
99         -lm
100
101 mono_LDFLAGS = \
102         $(static_flags) -export-dynamic $(monobinldflags)
103
104 # Create monow.exe, linked for the 'windows' subsystem
105 if PLATFORM_WIN32
106 monow_LDADD = $(mono_LDADD)
107 monow_LDFLAGS = $(mono_LDFLAGS) -mwindows
108 monow_SOURCES = $(mono_SOURCES)
109 endif
110
111 genmdesc_SOURCES = \
112         mini.h          \
113         genmdesc.c      \
114         helpers.c
115
116 # Don't link this against libmonoruntime to speed up rebuilds
117 genmdesc_LDADD = \
118         $(monodir)/mono/utils/libmonoutils.la $(monodir)/mono/metadata/opcodes.lo -lm   \
119         $(GLIB_LIBS)
120
121 x86_sources = \
122         mini-x86.c              \
123         mini-x86.h              \
124         exceptions-x86.c        \
125         tramp-x86.c                     \
126         mini-trampolines.c
127
128 amd64_sources = \
129         mini-amd64.c            \
130         mini-amd64.h            \
131         exceptions-amd64.c      \
132         tramp-amd64.c           \
133         mini-trampolines.c
134
135 ppc_sources = \
136         mini-ppc.c              \
137         mini-ppc.h              \
138         exceptions-ppc.c        \
139         mini-trampolines.c      \
140         tramp-ppc.c
141
142 arm_sources = \
143         mini-arm.c              \
144         mini-arm.h              \
145         exceptions-arm.c        \
146         tramp-arm.c
147
148 mips_sources = \
149         mini-mips.c             \
150         mini-mips.h             \
151         exceptions-mips.c       \
152         tramp-mips.c
153
154 sparc_sources = \
155         mini-sparc.c            \
156         mini-sparc.h            \
157         exceptions-sparc.c      \
158         tramp-sparc.c           \
159         mini-trampolines.c
160
161 s390_sources = \
162         mini-s390.c             \
163         mini-s390.h             \
164         exceptions-s390.c       \
165         tramp-s390.c
166
167 s390x_sources = \
168         mini-s390x.c            \
169         mini-s390x.h            \
170         exceptions-s390x.c      \
171         tramp-s390x.c
172
173 ia64_sources = \
174         mini-ia64.c                     \
175         mini-ia64.h                     \
176         exceptions-ia64.c       \
177         tramp-ia64.c            \
178         mini-trampolines.c
179
180 alpha_sources = \
181         mini-alpha.c    \
182         mini-alpha.h    \
183         exceptions-alpha.c      \
184         tramp-alpha.c   \
185         mini-trampolines.c
186
187 hppa_sources = \
188         mini-hppa.c     \
189         mini-hppa.h     \
190         exceptions-hppa.c       \
191         tramp-hppa.c    \
192         mini-trampolines.c
193
194 common_sources = \
195         mini.c          \
196         mini.h          \
197         version.h       \
198         optflags-def.h          \
199         jit-icalls.h \
200         jit-icalls.c \
201         trace.c         \
202         trace.h         \
203         patch-info.h    \
204         mini-ops.h      \
205         mini-arch.h     \
206         dominators.c    \
207         cfold.c         \
208         regalloc.c      \
209         regalloc.h      \
210         helpers.c       \
211         liveness.c      \
212         ssa.c           \
213         abcremoval.c    \
214         abcremoval.h    \
215         ssapre.c        \
216         ssapre.h        \
217         aliasing.c      \
218         aliasing.h      \
219         local-propagation.c     \
220         simple-cee-ops.h \
221         simple-mini-ops.h \
222         driver.c        \
223         debug-mini.c    \
224         debug-mini.h    \
225         linear-scan.c   \
226         aot-compiler.c          \
227         aot-runtime.c           \
228         graph.c         \
229         mini-exceptions.c       \
230         mini-codegen.c          \
231         declsec.c       \
232         declsec.h       \
233         wapihandles.c   \
234         branch-opts.c   \
235         generic-sharing.c
236
237 test_sources =          \
238         basic-calls.cs  \
239         basic-long.cs   \
240         bench.cs                \
241         objects.cs              \
242         arrays.cs               \
243         basic-float.cs  \
244         basic-math.cs   \
245         basic.cs                \
246         exceptions.cs   \
247         devirtualization.cs     \
248         iltests.il.in           \
249         test.cs
250
251 test_sources2 = generics.2.cs il2tests.2.il generics-variant-types.2.il
252
253 if MONO_DEBUGGER_SUPPORTED
254 if AMD64
255 mono_debugger_arch_sources = mdb-debug-info64.s
256 else
257 if ALPHA
258 mono_debugger_arch_sources = mdb-debug-info64.s
259 else
260 mono_debugger_arch_sources = mdb-debug-info32.s
261 endif
262 endif
263 mono_debugger_sources = debug-debugger.c debug-debugger.h $(mono_debugger_arch_sources)
264 else
265 mono_debugger_sources =
266 endif
267
268 regtests=basic.exe arrays.exe basic-float.exe basic-math.exe basic-long.exe objects.exe basic-calls.exe iltests.exe exceptions.exe bench.exe devirtualization.exe
269 regtests2=generics.exe il2tests.exe
270
271 common_BURGSRC= $(srcdir)/inssel.brg $(srcdir)/inssel-float.brg
272
273 if X86
274 arch_sources = $(x86_sources) $(mono_debugger_sources)
275 arch_BURGSRC= $(srcdir)/inssel-long32.brg $(srcdir)/inssel-x86.brg
276 arch_built=cpu-x86.h
277 arch_define=__i386__
278 endif
279
280 if AMD64
281 arch_sources = $(amd64_sources) $(mono_debugger_sources)
282 arch_BURGSRC= $(srcdir)/inssel-long.brg $(srcdir)/inssel-amd64.brg
283 arch_built=cpu-amd64.h
284 arch_define=__x86_64__
285 endif
286
287 if POWERPC
288 arch_sources = $(ppc_sources)
289 arch_BURGSRC= $(srcdir)/inssel-long32.brg $(srcdir)/inssel-ppc.brg
290 arch_built=cpu-g4.h
291 arch_define=__ppc__
292 endif
293
294 if MIPS
295 arch_sources = $(mips_sources)
296 arch_BURGSRC= $(srcdir)/inssel-long32-mips.brg $(srcdir)/inssel-mips.brg
297 arch_built=cpu-mips.h
298 arch_define=__mips__
299 endif
300
301 if ARM
302 # pick up arm_dpimacros.h and arm_fpamacros.h
303 ARCH_CFLAGS = -I../arch/arm
304 arch_sources = $(arm_sources)
305 arch_BURGSRC= $(srcdir)/inssel-long32.brg $(srcdir)/inssel-arm.brg $(srcdir)/inssel-softfloat.brg
306 arch_built=cpu-arm.h
307 arch_define=__arm__
308 endif
309
310 if SPARC
311 arch_sources = $(sparc_sources)
312 arch_BURGSRC= $(srcdir)/inssel-long32.brg $(srcdir)/inssel-sparc.brg
313 arch_built=cpu-sparc.h
314 arch_define=__sparc__
315 endif
316
317 if SPARC64
318 arch_sources = $(sparc_sources)
319 arch_BURGSRC= $(srcdir)/inssel-long.brg $(srcdir)/inssel-sparc.brg
320 arch_built=cpu-sparc.h
321 arch_define=__sparc__
322 endif
323
324 if S390
325 arch_sources = $(s390_sources)
326 arch_BURGSRC= $(srcdir)/inssel-long32.brg $(srcdir)/inssel-s390.brg
327 arch_built=cpu-s390.h
328 arch_define=__s390__
329 endif
330
331 if S390x
332 arch_sources = $(s390x_sources)
333 arch_BURGSRC= $(srcdir)/inssel-long.brg $(srcdir)/inssel-s390x.brg
334 arch_built=cpu-s390x.h
335 arch_define=__s390__
336 endif
337
338 if IA64
339 arch_sources = $(ia64_sources)
340 arch_BURGSRC = $(srcdir)/inssel-long.brg $(srcdir)/inssel-ia64.brg
341 arch_built = cpu-ia64.h
342 arch_define=__ia64__
343 endif
344
345 if ALPHA
346 arch_sources = $(alpha_sources) $(mono_debugger_sources)
347 arch_BURGSRC = $(srcdir)/inssel-long.brg $(srcdir)/inssel-alpha.brg
348 arch_built = cpu-alpha.h
349 arch_define=__alpha__
350 endif
351
352 if HPPA
353 # Only support 32-bit targets for now
354 arch_sources = $(hppa_sources)
355 arch_BURGSRC = $(srcdir)/inssel-long32.brg $(srcdir)/inssel-hppa.brg
356 arch_built = cpu-hppa.h
357 arch_define=__hppa__
358 endif
359
360 libmono_la_SOURCES = $(common_sources) $(arch_sources)
361
362 nodist_libmono_la_SOURCES = inssel.c inssel.h
363
364 libmono_static_la_SOURCES = $(libmono_la_SOURCES)
365 nodist_libmono_static_la_SOURCES = $(nodist_libmono_la_SOURCES)
366 libmono_static_la_LDFLAGS = -static
367 libmono_static_la_LIBADD = $(static_libs)
368
369 BURGSRC= $(common_BURGSRC) $(arch_BURGSRC)
370
371 libmonoincludedir = $(includedir)/mono-$(API_VER)/mono/jit
372
373 libmonoinclude_HEADERS = jit.h
374
375 libmono_la_LIBADD = \
376         $(libs)
377
378 %.exe: %.2.cs TestDriver.dll generics-variant-types.dll
379         $(GMCS) -out:$@ $< -r:TestDriver.dll -r:generics-variant-types.dll
380
381 %.exe: %.cs TestDriver.dll
382         $(MCS) -out:$@ -unsafe $< -r:TestDriver.dll
383
384 %.exe: %.2.il
385         $(ILASM2) -output=$@ $<
386
387 iltests.il: iltests.il.in Makefile.am
388         echo '// DO NOT EDIT: This file has been generated from iltests.il.in' > iltests.il
389         cpp -Darch=$(arch_define) < $(srcdir)/iltests.il.in | sed 's/^#.*//' >> iltests.il
390
391 %.exe: %.il
392         $(ILASM) -output=$@ $<
393
394 TestDriver.dll: $(srcdir)/TestDriver.cs
395         $(MCS) -out:$@ -target:library $<
396
397 generics-variant-types.dll: generics-variant-types.2.il
398         $(ILASM2) -dll -output=$@ $<
399
400 # we don't always use the perl impl because it's an additional
401 # build dependency for the poor windows users
402 # $(arch_define) is the preprocessor symbol that enables all the opcodes
403 # for the specific platform in mini-ops.h
404 if CROSS_COMPILING
405 GENMDESC_PRG=perl genmdesc.pl $(arch_define) $(srcdir)
406 else !CROSS_COMPILING
407 GENMDESC_PRG=./genmdesc
408 endif !CROSS_COMPILING
409
410 cpu-x86.h: cpu-x86.md genmdesc$(EXEEXT)
411         $(GENMDESC_PRG) $(srcdir)/cpu-x86.md cpu-x86.h x86_desc
412
413 cpu-amd64.h: cpu-amd64.md genmdesc$(EXEEXT)
414         $(GENMDESC_PRG) $(srcdir)/cpu-amd64.md cpu-amd64.h amd64_desc
415
416 cpu-g4.h: cpu-g4.md genmdesc$(EXEEXT)
417         $(GENMDESC_PRG) $(srcdir)/cpu-g4.md cpu-g4.h ppcg4
418
419 cpu-arm.h: cpu-arm.md genmdesc$(EXEEXT)
420         $(GENMDESC_PRG) $(srcdir)/cpu-arm.md cpu-arm.h arm_cpu_desc
421
422 cpu-sparc.h: cpu-sparc.md genmdesc$(EXEEXT)
423         $(GENMDESC_PRG) $(srcdir)/cpu-sparc.md cpu-sparc.h sparc_desc
424
425 cpu-s390.h: cpu-s390.md genmdesc$(EXEEXT)
426         $(GENMDESC_PRG) $(srcdir)/cpu-s390.md cpu-s390.h s390_cpu_desc
427
428 cpu-s390x.h: cpu-s390x.md genmdesc$(EXEEXT)
429         $(GENMDESC_PRG) $(srcdir)/cpu-s390x.md cpu-s390x.h s390x_cpu_desc
430
431 cpu-ia64.h: cpu-ia64.md genmdesc$(EXEEXT)
432         $(GENMDESC_PRG) $(srcdir)/cpu-ia64.md cpu-ia64.h ia64_desc
433
434 cpu-alpha.h: cpu-alpha.md genmdesc$(EXEEXT)
435         $(GENMDESC_PRG) $(srcdir)/cpu-alpha.md cpu-alpha.h alpha_desc
436
437 cpu-hppa.h: cpu-hppa.md genmdesc$(EXEEXT)
438         $(GENMDESC_PRG) $(srcdir)/cpu-hppa.md cpu-hppa.h hppa_desc
439
440 cpu-mips.h: cpu-mips.md genmdesc$(EXEEXT)
441         $(GENMDESC_PRG) $(srcdir)/cpu-mips.md cpu-mips.h mips_desc
442
443 inssel.c inssel.h: $(BURGSRC)
444         $(monodir)/mono/monoburg/monoburg -c 1 -p -e $(BURGSRC) -d inssel.h -s inssel.c
445
446 testi: mono test.exe
447         $(RUNTIME) -v -v --ncompile 1 --compile Test:$(mtest) test.exe
448
449 # ensure the tests are actually correct
450 checktests: $(regtests)
451         for i in $(regtests); do $(RUNTIME) $$i; done
452
453 checktests2: $(regtests2)
454         for i in $(regtests); do $(RUNTIME2) $$i; done
455
456 rcheck: mono $(regtests) $(regtests2)
457         $(RUNTIME) --regression $(regtests)
458         $(RUNTIME2) --regression $(regtests2)
459
460 aotcheck: mono $(regtests)
461         for i in $(regtests); do $(RUNTIME) --aot $$i || exit 1; done
462         for i in $(regtests2); do $(RUNTIME2) --aot $$i || exit 1; done
463         for i in $(regtests); do $(RUNTIME_AOTCHECK) --regression $$i || exit 1; done
464         for i in $(regtests2); do $(RUNTIME_AOTCHECK2) --regression $$i || exit 1; done
465         rm -f *.exe.so
466
467 bench: mono test.exe
468         time env $(RUNTIME) --ncompile $(count) --compile Test:$(mtest) test.exe
469
470 mbench: test.exe
471         time $(monodir)/mono/jit/mono --ncompile $(count) --compile Test:$(mtest) test.exe
472
473 stat1: mono bench.exe
474         $(RUNTIME) --verbose --statfile stats.pl --regression bench.exe
475         perl viewstat.pl stats.pl
476
477 stat2: mono basic.exe
478         $(RUNTIME) --verbose --statfile stats.pl --regression basic.exe
479         perl viewstat.pl -e stats.pl
480
481 stat3: mono bench.exe
482         $(RUNTIME) --statfile stats.pl --ncompile 1000 --compile Tests:test_0_many_nested_loops bench.exe 
483         perl viewstat.pl stats.pl
484
485 docu: mini.sgm
486         docbook2txt mini.sgm
487
488 check-local: rcheck
489
490 clean-local:
491         rm -f mono a.out gmon.out *.o test.exe
492
493 pkgconfigdir = $(libdir)/pkgconfig
494
495 if JIT_SUPPORTED
496 BUILT_SOURCES = version.h inssel.c inssel.h $(arch_built)
497 else
498 BUILT_SOURCES = version.h
499 endif
500
501 CLEANFILES= $(BUILT_SOURCES) *.exe *.dll
502 EXTRA_DIST = $(common_BURGSRC) cprop.c TestDriver.cs ldscript ldscript.mono \
503         genmdesc.pl     \
504         $(test_sources) $(test_sources2) \
505         inssel-long.brg inssel-long32.brg \
506         inssel-softfloat.brg    \
507         $(x86_sources) inssel-x86.brg cpu-x86.md \
508         $(amd64_sources) inssel-amd64.brg cpu-amd64.md \
509         $(ppc_sources) inssel-ppc.brg cpu-g4.md \
510         $(arm_sources) inssel-arm.brg cpu-arm.md \
511         $(mips_sources) inssel-mips.brg inssel-long32-mips.brg cpu-mips.md \
512         $(sparc_sources) inssel-sparc.brg cpu-sparc.md \
513         $(s390_sources) inssel-s390.brg cpu-s390.md \
514         $(s390x_sources) inssel-s390x.brg cpu-s390x.md \
515         $(ia64_sources) inssel-ia64.brg cpu-ia64.md \
516         $(alpha_sources) inssel-alpha.brg cpu-alpha.md \
517         $(hppa_sources) inssel-hppa.brg cpu-hppa.md
518
519 version.h: Makefile
520         if test -d $(srcdir)/.svn; then \
521                 (cd $(srcdir);  \
522                         export LANG=C;  \
523                         branch=`svn info | grep URL | sed -e 's/.*source//' -e 's,mono/mono/mini,,'`; \
524                         version=`svn info | grep Revision | sed 's/.*: //'`; \
525                         echo "#define FULL_VERSION \"$$branch r$$version\""; \
526                 ); \
527         else \
528                 echo "#define FULL_VERSION \"tarball\""; \
529         fi > version.h