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