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