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