2007-09-20 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         tramp-ppc.c
140
141 arm_sources = \
142         mini-arm.c              \
143         mini-arm.h              \
144         exceptions-arm.c        \
145         tramp-arm.c
146
147 mips_sources = \
148         mini-mips.c             \
149         mini-mips.h             \
150         exceptions-mips.c       \
151         tramp-mips.c
152
153 sparc_sources = \
154         mini-sparc.c            \
155         mini-sparc.h            \
156         exceptions-sparc.c      \
157         tramp-sparc.c           \
158         mini-trampolines.c
159
160 s390_sources = \
161         mini-s390.c             \
162         mini-s390.h             \
163         exceptions-s390.c       \
164         tramp-s390.c
165
166 s390x_sources = \
167         mini-s390x.c            \
168         mini-s390x.h            \
169         exceptions-s390x.c      \
170         tramp-s390x.c
171
172 ia64_sources = \
173         mini-ia64.c                     \
174         mini-ia64.h                     \
175         exceptions-ia64.c       \
176         tramp-ia64.c            \
177         mini-trampolines.c
178
179 alpha_sources = \
180         mini-alpha.c    \
181         mini-alpha.h    \
182         exceptions-alpha.c      \
183         tramp-alpha.c   \
184         mini-trampolines.c
185
186 hppa_sources = \
187         mini-hppa.c     \
188         mini-hppa.h     \
189         exceptions-hppa.c       \
190         tramp-hppa.c    \
191         mini-trampolines.c
192
193 common_sources = \
194         mini.c          \
195         mini.h          \
196         version.h       \
197         optflags-def.h          \
198         jit-icalls.h \
199         jit-icalls.c \
200         trace.c         \
201         trace.h         \
202         patch-info.h    \
203         mini-ops.h      \
204         mini-arch.h     \
205         dominators.c    \
206         cfold.c         \
207         regalloc.c      \
208         regalloc.h      \
209         helpers.c       \
210         liveness.c      \
211         ssa.c           \
212         abcremoval.c    \
213         abcremoval.h    \
214         ssapre.c        \
215         ssapre.h        \
216         aliasing.c      \
217         aliasing.h      \
218         local-propagation.c     \
219         simple-cee-ops.h \
220         simple-mini-ops.h \
221         driver.c        \
222         debug-mini.c    \
223         debug-mini.h    \
224         linear-scan.c   \
225         aot-compiler.c          \
226         aot-runtime.c           \
227         graph.c         \
228         mini-exceptions.c       \
229         mini-codegen.c          \
230         declsec.c       \
231         declsec.h       \
232         wapihandles.c   \
233         branch-opts.c   \
234         generic-sharing.c
235
236 test_sources =          \
237         basic-calls.cs  \
238         basic-long.cs   \
239         bench.cs                \
240         objects.cs              \
241         arrays.cs               \
242         basic-float.cs  \
243         basic-math.cs   \
244         basic.cs                \
245         exceptions.cs   \
246         devirtualization.cs     \
247         iltests.il.in           \
248         test.cs
249
250 test_sources2 = generics.2.cs il2tests.2.il generics-variant-types.2.il
251
252 if MONO_DEBUGGER_SUPPORTED
253 if AMD64
254 mono_debugger_arch_sources = mdb-debug-info64.s
255 else
256 if ALPHA
257 mono_debugger_arch_sources = mdb-debug-info64.s
258 else
259 mono_debugger_arch_sources = mdb-debug-info32.s
260 endif
261 endif
262 mono_debugger_sources = debug-debugger.c debug-debugger.h $(mono_debugger_arch_sources)
263 else
264 mono_debugger_sources =
265 endif
266
267 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
268 regtests2=generics.exe il2tests.exe
269
270 common_BURGSRC= $(srcdir)/inssel.brg $(srcdir)/inssel-float.brg
271
272 if X86
273 arch_sources = $(x86_sources) $(mono_debugger_sources)
274 arch_BURGSRC= $(srcdir)/inssel-long32.brg $(srcdir)/inssel-x86.brg
275 arch_built=cpu-x86.h
276 arch_define=__i386__
277 endif
278
279 if AMD64
280 arch_sources = $(amd64_sources) $(mono_debugger_sources)
281 arch_BURGSRC= $(srcdir)/inssel-long.brg $(srcdir)/inssel-amd64.brg
282 arch_built=cpu-amd64.h
283 arch_define=__x86_64__
284 endif
285
286 if POWERPC
287 arch_sources = $(ppc_sources)
288 arch_BURGSRC= $(srcdir)/inssel-long32.brg $(srcdir)/inssel-ppc.brg
289 arch_built=cpu-g4.h
290 arch_define=__ppc__
291 endif
292
293 if MIPS
294 arch_sources = $(mips_sources)
295 arch_BURGSRC= $(srcdir)/inssel-long32-mips.brg $(srcdir)/inssel-mips.brg
296 arch_built=cpu-mips.h
297 arch_define=__mips__
298 endif
299
300 if ARM
301 # pick up arm_dpimacros.h and arm_fpamacros.h
302 ARCH_CFLAGS = -I../arch/arm
303 arch_sources = $(arm_sources)
304 arch_BURGSRC= $(srcdir)/inssel-long32.brg $(srcdir)/inssel-arm.brg $(srcdir)/inssel-softfloat.brg
305 arch_built=cpu-arm.h
306 arch_define=__arm__
307 endif
308
309 if SPARC
310 arch_sources = $(sparc_sources)
311 arch_BURGSRC= $(srcdir)/inssel-long32.brg $(srcdir)/inssel-sparc.brg
312 arch_built=cpu-sparc.h
313 arch_define=__sparc__
314 endif
315
316 if SPARC64
317 arch_sources = $(sparc_sources)
318 arch_BURGSRC= $(srcdir)/inssel-long.brg $(srcdir)/inssel-sparc.brg
319 arch_built=cpu-sparc.h
320 arch_define=__sparc__
321 endif
322
323 if S390
324 arch_sources = $(s390_sources)
325 arch_BURGSRC= $(srcdir)/inssel-long32.brg $(srcdir)/inssel-s390.brg
326 arch_built=cpu-s390.h
327 arch_define=__s390__
328 endif
329
330 if S390x
331 arch_sources = $(s390x_sources)
332 arch_BURGSRC= $(srcdir)/inssel-long.brg $(srcdir)/inssel-s390x.brg
333 arch_built=cpu-s390x.h
334 arch_define=__s390__
335 endif
336
337 if IA64
338 arch_sources = $(ia64_sources)
339 arch_BURGSRC = $(srcdir)/inssel-long.brg $(srcdir)/inssel-ia64.brg
340 arch_built = cpu-ia64.h
341 arch_define=__ia64__
342 endif
343
344 if ALPHA
345 arch_sources = $(alpha_sources) $(mono_debugger_sources)
346 arch_BURGSRC = $(srcdir)/inssel-long.brg $(srcdir)/inssel-alpha.brg
347 arch_built = cpu-alpha.h
348 arch_define=__alpha__
349 endif
350
351 if HPPA
352 # Only support 32-bit targets for now
353 arch_sources = $(hppa_sources)
354 arch_BURGSRC = $(srcdir)/inssel-long32.brg $(srcdir)/inssel-hppa.brg
355 arch_built = cpu-hppa.h
356 arch_define=__hppa__
357 endif
358
359 libmono_la_SOURCES = $(common_sources) $(arch_sources)
360
361 nodist_libmono_la_SOURCES = inssel.c inssel.h
362
363 libmono_static_la_SOURCES = $(libmono_la_SOURCES)
364 nodist_libmono_static_la_SOURCES = $(nodist_libmono_la_SOURCES)
365 libmono_static_la_LDFLAGS = -static
366 libmono_static_la_LIBADD = $(static_libs)
367
368 BURGSRC= $(common_BURGSRC) $(arch_BURGSRC)
369
370 libmonoincludedir = $(includedir)/mono-$(API_VER)/mono/jit
371
372 libmonoinclude_HEADERS = jit.h
373
374 libmono_la_LIBADD = \
375         $(libs)
376
377 %.exe: %.2.cs TestDriver.dll generics-variant-types.dll
378         $(GMCS) -out:$@ $< -r:TestDriver.dll -r:generics-variant-types.dll
379
380 %.exe: %.cs TestDriver.dll
381         $(MCS) -out:$@ -unsafe $< -r:TestDriver.dll
382
383 %.exe: %.2.il
384         $(ILASM2) -output=$@ $<
385
386 iltests.il: iltests.il.in Makefile.am
387         echo '// DO NOT EDIT: This file has been generated from iltests.il.in' > iltests.il
388         cpp -Darch=$(arch_define) < $(srcdir)/iltests.il.in | sed 's/^#.*//' >> iltests.il
389
390 %.exe: %.il
391         $(ILASM) -output=$@ $<
392
393 TestDriver.dll: $(srcdir)/TestDriver.cs
394         $(MCS) -out:$@ -target:library $<
395
396 generics-variant-types.dll: generics-variant-types.2.il
397         $(ILASM2) -dll -output=$@ $<
398
399 # we don't always use the perl impl because it's an additional
400 # build dependency for the poor windows users
401 # $(arch_define) is the preprocessor symbol that enables all the opcodes
402 # for the specific platform in mini-ops.h
403 if CROSS_COMPILING
404 GENMDESC_PRG=perl genmdesc.pl $(arch_define) $(srcdir)
405 else !CROSS_COMPILING
406 GENMDESC_PRG=./genmdesc
407 endif !CROSS_COMPILING
408
409 cpu-x86.h: cpu-x86.md genmdesc$(EXEEXT)
410         $(GENMDESC_PRG) $(srcdir)/cpu-x86.md cpu-x86.h x86_desc
411
412 cpu-amd64.h: cpu-amd64.md genmdesc$(EXEEXT)
413         $(GENMDESC_PRG) $(srcdir)/cpu-amd64.md cpu-amd64.h amd64_desc
414
415 cpu-g4.h: cpu-g4.md genmdesc$(EXEEXT)
416         $(GENMDESC_PRG) $(srcdir)/cpu-g4.md cpu-g4.h ppcg4
417
418 cpu-arm.h: cpu-arm.md genmdesc$(EXEEXT)
419         $(GENMDESC_PRG) $(srcdir)/cpu-arm.md cpu-arm.h arm_cpu_desc
420
421 cpu-sparc.h: cpu-sparc.md genmdesc$(EXEEXT)
422         $(GENMDESC_PRG) $(srcdir)/cpu-sparc.md cpu-sparc.h sparc_desc
423
424 cpu-s390.h: cpu-s390.md genmdesc$(EXEEXT)
425         $(GENMDESC_PRG) $(srcdir)/cpu-s390.md cpu-s390.h s390_cpu_desc
426
427 cpu-s390x.h: cpu-s390x.md genmdesc$(EXEEXT)
428         $(GENMDESC_PRG) $(srcdir)/cpu-s390x.md cpu-s390x.h s390x_cpu_desc
429
430 cpu-ia64.h: cpu-ia64.md genmdesc$(EXEEXT)
431         $(GENMDESC_PRG) $(srcdir)/cpu-ia64.md cpu-ia64.h ia64_desc
432
433 cpu-alpha.h: cpu-alpha.md genmdesc$(EXEEXT)
434         $(GENMDESC_PRG) $(srcdir)/cpu-alpha.md cpu-alpha.h alpha_desc
435
436 cpu-hppa.h: cpu-hppa.md genmdesc$(EXEEXT)
437         $(GENMDESC_PRG) $(srcdir)/cpu-hppa.md cpu-hppa.h hppa_desc
438
439 cpu-mips.h: cpu-mips.md genmdesc$(EXEEXT)
440         $(GENMDESC_PRG) $(srcdir)/cpu-mips.md cpu-mips.h mips_desc
441
442 inssel.c inssel.h: $(BURGSRC)
443         $(monodir)/mono/monoburg/monoburg -c 1 -p -e $(BURGSRC) -d inssel.h -s inssel.c
444
445 testi: mono test.exe
446         $(RUNTIME) -v -v --ncompile 1 --compile Test:$(mtest) test.exe
447
448 # ensure the tests are actually correct
449 checktests: $(regtests)
450         for i in $(regtests); do $(RUNTIME) $$i; done
451
452 checktests2: $(regtests2)
453         for i in $(regtests); do $(RUNTIME2) $$i; done
454
455 rcheck: mono $(regtests) $(regtests2)
456         $(RUNTIME) --regression $(regtests)
457         $(RUNTIME2) --regression $(regtests2)
458
459 aotcheck: mono $(regtests)
460         for i in $(regtests); do $(RUNTIME) --aot $$i || exit 1; done
461         for i in $(regtests2); do $(RUNTIME2) --aot $$i || exit 1; done
462         for i in $(regtests); do $(RUNTIME_AOTCHECK) --regression $$i || exit 1; done
463         for i in $(regtests2); do $(RUNTIME_AOTCHECK2) --regression $$i || exit 1; done
464         rm -f *.exe.so
465
466 bench: mono test.exe
467         time env $(RUNTIME) --ncompile $(count) --compile Test:$(mtest) test.exe
468
469 mbench: test.exe
470         time $(monodir)/mono/jit/mono --ncompile $(count) --compile Test:$(mtest) test.exe
471
472 stat1: mono bench.exe
473         $(RUNTIME) --verbose --statfile stats.pl --regression bench.exe
474         perl viewstat.pl stats.pl
475
476 stat2: mono basic.exe
477         $(RUNTIME) --verbose --statfile stats.pl --regression basic.exe
478         perl viewstat.pl -e stats.pl
479
480 stat3: mono bench.exe
481         $(RUNTIME) --statfile stats.pl --ncompile 1000 --compile Tests:test_0_many_nested_loops bench.exe 
482         perl viewstat.pl stats.pl
483
484 docu: mini.sgm
485         docbook2txt mini.sgm
486
487 check-local: rcheck
488
489 clean-local:
490         rm -f mono a.out gmon.out *.o test.exe
491
492 pkgconfigdir = $(libdir)/pkgconfig
493
494 if JIT_SUPPORTED
495 BUILT_SOURCES = version.h inssel.c inssel.h $(arch_built)
496 else
497 BUILT_SOURCES = version.h
498 endif
499
500 CLEANFILES= $(BUILT_SOURCES) *.exe *.dll
501 EXTRA_DIST = $(common_BURGSRC) cprop.c TestDriver.cs ldscript ldscript.mono \
502         genmdesc.pl     \
503         $(test_sources) $(test_sources2) \
504         inssel-long.brg inssel-long32.brg \
505         inssel-softfloat.brg    \
506         $(x86_sources) inssel-x86.brg cpu-x86.md \
507         $(amd64_sources) inssel-amd64.brg cpu-amd64.md \
508         $(ppc_sources) inssel-ppc.brg cpu-g4.md \
509         $(arm_sources) inssel-arm.brg cpu-arm.md \
510         $(mips_sources) inssel-mips.brg inssel-long32-mips.brg cpu-mips.md \
511         $(sparc_sources) inssel-sparc.brg cpu-sparc.md \
512         $(s390_sources) inssel-s390.brg cpu-s390.md \
513         $(s390x_sources) inssel-s390x.brg cpu-s390x.md \
514         $(ia64_sources) inssel-ia64.brg cpu-ia64.md \
515         $(alpha_sources) inssel-alpha.brg cpu-alpha.md \
516         $(hppa_sources) inssel-hppa.brg cpu-hppa.md
517
518 version.h: Makefile
519         if test -d $(srcdir)/.svn; then \
520                 (cd $(srcdir);  \
521                         export LANG=C;  \
522                         branch=`svn info | grep URL | sed -e 's/.*source//' -e 's,mono/mono/mini,,'`; \
523                         version=`svn info | grep Revision | sed 's/.*: //'`; \
524                         echo "#define FULL_VERSION \"$$branch r$$version\""; \
525                 ); \
526         else \
527                 echo "#define FULL_VERSION \"tarball\""; \
528         fi > version.h