2009-07-02 jonas echterhoff <jonas@unity3d.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) $(monobin_platform_ldflags)
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 # Disabled for now to fix the windows build
228 #llvm_sources = \
229 #       mini-llvm.c             \
230 #       mini-llvm-cpp.cpp
231 endif
232
233 common_sources = \
234         mini.c                  \
235         ir-emit.h               \
236         method-to-ir.c          \
237         decompose.c             \
238         mini.h                  \
239         version.h               \
240         optflags-def.h          \
241         jit-icalls.h            \
242         jit-icalls.c            \
243         trace.c                 \
244         trace.h                 \
245         patch-info.h            \
246         mini-ops.h              \
247         mini-arch.h             \
248         dominators.c            \
249         cfold.c                 \
250         regalloc.c              \
251         regalloc.h              \
252         helpers.c               \
253         liveness.c              \
254         ssa.c                   \
255         abcremoval.c            \
256         abcremoval.h            \
257         ssapre.c                \
258         ssapre.h                \
259         local-propagation.c     \
260         driver.c                \
261         debug-mini.c            \
262         debug-mini.h            \
263         linear-scan.c           \
264         aot-compiler.c          \
265         aot-runtime.c           \
266         graph.c                 \
267         mini-codegen.c          \
268         mini-exceptions.c       \
269         mini-trampolines.c      \
270         declsec.c               \
271         declsec.h               \
272         wapihandles.c           \
273         branch-opts.c           \
274         mini-generic-sharing.c  \
275         regalloc2.c             \
276         simd-methods.h          \
277         tasklets.c              \
278         tasklets.h              \
279         simd-intrinsics.c       \
280         unwind.h                \
281         unwind.c                \
282         image-writer.h  \
283         image-writer.c  \
284         dwarfwriter.h   \
285         dwarfwriter.c   \
286         mini-gc.h               \
287         mini-gc.c
288
289 test_sources =                  \
290         basic-calls.cs          \
291         basic-long.cs           \
292         bench.cs                \
293         objects.cs              \
294         arrays.cs               \
295         basic-float.cs          \
296         basic-math.cs           \
297         basic.cs                \
298         exceptions.cs           \
299         devirtualization.cs     \
300         iltests.il.in           \
301         test.cs                 \
302         generics.cs             \
303         generics-variant-types.il\
304         basic-simd.cs
305
306 if MONO_DEBUGGER_SUPPORTED
307 if PLATFORM_DARWIN
308 mono_debugger_arch_sources = mdb-debug-info32-darwin.s
309 else
310 if AMD64
311 mono_debugger_arch_sources = mdb-debug-info64.s
312 else
313 if X86
314 mono_debugger_arch_sources = mdb-debug-info32.s
315 endif
316 endif
317 endif
318 mono_debugger_sources = debug-debugger.c debug-debugger.h $(mono_debugger_arch_sources)
319 else
320 mono_debugger_sources =
321 endif
322
323 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
324
325 if X86
326 arch_sources = $(x86_sources) $(mono_debugger_sources)
327 arch_built=cpu-x86.h
328 arch_define=__i386__
329 endif
330
331 if AMD64
332 arch_sources = $(amd64_sources) $(mono_debugger_sources)
333 arch_built=cpu-amd64.h
334 arch_define=__x86_64__
335 endif
336
337 if POWERPC
338 arch_sources = $(ppc_sources)
339 arch_built=cpu-ppc.h
340 arch_define=__ppc__
341 endif
342
343 if POWERPC64
344 arch_sources = $(ppc_sources)
345 arch_built=cpu-ppc64.h
346 arch_define=__ppc64__
347 endif
348
349 if MIPS
350 arch_sources = $(mips_sources)
351 arch_built=cpu-mips.h
352 arch_define=__mips__
353 endif
354
355 if ARM
356 # pick up arm_dpimacros.h and arm_fpamacros.h
357 ARCH_CFLAGS = -I../arch/arm
358 arch_sources = $(arm_sources)
359 arch_built=cpu-arm.h
360 arch_define=__arm__
361 endif
362
363 if SPARC
364 arch_sources = $(sparc_sources)
365 arch_built=cpu-sparc.h
366 arch_define=__sparc__
367 endif
368
369 if SPARC64
370 arch_sources = $(sparc_sources)
371 arch_built=cpu-sparc.h
372 arch_define=__sparc__
373 endif
374
375 if S390
376 arch_sources = $(s390_sources)
377 arch_built=cpu-s390.h
378 arch_define=__s390__
379 endif
380
381 if S390x
382 arch_sources = $(s390x_sources)
383 arch_built=cpu-s390x.h
384 arch_define=__s390__
385 endif
386
387 if IA64
388 arch_sources = $(ia64_sources)
389 arch_built = cpu-ia64.h
390 arch_define=__ia64__
391 endif
392
393 if ALPHA
394 arch_sources = $(alpha_sources) $(mono_debugger_sources)
395 arch_built = cpu-alpha.h
396 arch_define=__alpha__
397 endif
398
399 if HPPA
400 # Only support 32-bit targets for now
401 arch_sources = $(hppa_sources)
402 arch_built = cpu-hppa.h
403 arch_define=__hppa__
404 endif
405
406 if PLATFORM_WIN32
407 os_sources = $(windows_sources)
408 endif
409
410 if PLATFORM_SIGPOSIX
411 os_sources = $(posix_sources)
412 endif
413
414 if PLATFORM_DARWIN
415 os_sources = $(darwin_sources) $(posix_sources)
416 endif
417
418 libmono_la_SOURCES = $(common_sources) $(llvm_sources) $(arch_sources) $(os_sources)
419
420 libmono_static_la_SOURCES = $(libmono_la_SOURCES)
421 nodist_libmono_static_la_SOURCES = $(nodist_libmono_la_SOURCES)
422 libmono_static_la_LDFLAGS = -static
423 libmono_static_la_LIBADD = $(static_libs) $(MONO_DTRACE_OBJECT)
424
425 BURGSRC= $(common_BURGSRC) $(arch_BURGSRC)
426
427 libmonoincludedir = $(includedir)/mono-$(API_VER)/mono/jit
428
429 libmonoinclude_HEADERS = jit.h
430
431 libmono_la_LIBADD = \
432         $(libs) $(LIBMONO_DTRACE_OBJECT)
433
434 basic-simd.exe: basic-simd.cs
435         $(MCS) -out:$@ $< -r:TestDriver.dll -r:Mono.Simd.dll
436
437 generics.exe: generics.cs TestDriver.dll generics-variant-types.dll
438         $(MCS) -out:$@ $< -r:TestDriver.dll -r:generics-variant-types.dll
439
440 %.exe: %.cs TestDriver.dll
441         $(MCS) -out:$@ -unsafe $< -r:TestDriver.dll
442
443 iltests.il: iltests.il.in Makefile.am
444         echo '// DO NOT EDIT: This file has been generated from iltests.il.in' > iltests.il
445         cpp -Darch=$(arch_define) < $(srcdir)/iltests.il.in | sed 's/^#.*//' >> iltests.il
446
447 %.exe: %.il
448         $(ILASM) -output=$@ $<
449
450 TestDriver.dll: $(srcdir)/TestDriver.cs
451         $(MCS) -out:$@ -target:library $<
452
453 generics-variant-types.dll: generics-variant-types.il
454         $(ILASM) -dll -output=$@ $<
455
456 # we don't always use the perl impl because it's an additional
457 # build dependency for the poor windows users
458 # $(arch_define) is the preprocessor symbol that enables all the opcodes
459 # for the specific platform in mini-ops.h
460 if CROSS_COMPILING
461 GENMDESC_PRG=perl $(srcdir)/genmdesc.pl $(arch_define) $(srcdir)
462 else !CROSS_COMPILING
463 GENMDESC_PRG=./genmdesc
464 endif !CROSS_COMPILING
465
466 cpu-x86.h: cpu-x86.md genmdesc$(EXEEXT)
467         $(GENMDESC_PRG) cpu-x86.h x86_desc $(srcdir)/cpu-x86.md
468
469 cpu-amd64.h: cpu-amd64.md genmdesc$(EXEEXT)
470         $(GENMDESC_PRG) cpu-amd64.h amd64_desc $(srcdir)/cpu-amd64.md
471
472 cpu-ppc.h: cpu-ppc.md genmdesc$(EXEEXT)
473         $(GENMDESC_PRG) cpu-ppc.h ppcg4 $(srcdir)/cpu-ppc.md
474
475 cpu-ppc64.h: cpu-ppc64.md genmdesc$(EXEEXT)
476         $(GENMDESC_PRG) cpu-ppc64.h ppc64_cpu_desc $(srcdir)/cpu-ppc64.md
477
478 cpu-arm.h: cpu-arm.md genmdesc$(EXEEXT)
479         $(GENMDESC_PRG) cpu-arm.h arm_cpu_desc $(srcdir)/cpu-arm.md
480
481 cpu-sparc.h: cpu-sparc.md genmdesc$(EXEEXT)
482         $(GENMDESC_PRG) cpu-sparc.h sparc_desc $(srcdir)/cpu-sparc.md
483
484 cpu-s390.h: cpu-s390.md genmdesc$(EXEEXT)
485         $(GENMDESC_PRG) cpu-s390.h s390_cpu_desc $(srcdir)/cpu-s390.md
486
487 cpu-s390x.h: cpu-s390x.md genmdesc$(EXEEXT)
488         $(GENMDESC_PRG) cpu-s390x.h s390x_cpu_desc $(srcdir)/cpu-s390x.md
489
490 cpu-ia64.h: cpu-ia64.md genmdesc$(EXEEXT)
491         $(GENMDESC_PRG) cpu-ia64.h ia64_desc $(srcdir)/cpu-ia64.md
492
493 cpu-alpha.h: cpu-alpha.md genmdesc$(EXEEXT)
494         $(GENMDESC_PRG) cpu-alpha.h alpha_desc $(srcdir)/cpu-alpha.md
495
496 cpu-hppa.h: cpu-hppa.md genmdesc$(EXEEXT)
497         $(GENMDESC_PRG) cpu-hppa.h hppa_desc $(srcdir)/cpu-hppa.md
498
499 cpu-mips.h: cpu-mips.md genmdesc$(EXEEXT)
500         $(GENMDESC_PRG) cpu-mips.h mips_desc $(srcdir)/cpu-mips.md
501
502 testi: mono test.exe
503         $(RUNTIME) -v -v --ncompile 1 --compile Test:$(mtest) test.exe
504
505 # ensure the tests are actually correct
506 checktests: $(regtests)
507         for i in $(regtests); do $(RUNTIME) $$i; done
508
509 rcheck: mono $(regtests)
510         $(RUNTIME) --regression $(regtests)
511
512 aotcheck: mono $(regtests)
513         rm -f *.exe.so
514         $(RUNTIME) --aot $(regtests) || exit 1
515         for i in $(regtests); do $(RUNTIME_AOTCHECK) --regression $$i || exit 1; done
516         rm -f *.exe.so
517
518 # This currently only works on amd64/arm
519 fullaotcheck: mono $(regtests)
520         rm -rf fullaot-tmp
521         mkdir fullaot-tmp
522         cp $(CLASS)/mscorlib.dll $(CLASS)/Mono.Simd.dll $(regtests) generics-variant-types.dll TestDriver.dll fullaot-tmp/
523         cp $(regtests) fullaot-tmp/
524         MONO_PATH=fullaot-tmp $(top_builddir)/runtime/mono-wrapper --aot=full fullaot-tmp/* || exit 1
525         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
526
527 bench: mono test.exe
528         time env $(RUNTIME) --ncompile $(count) --compile Test:$(mtest) test.exe
529
530 mbench: test.exe
531         time $(monodir)/mono/jit/mono --ncompile $(count) --compile Test:$(mtest) test.exe
532
533 stat1: mono bench.exe
534         $(RUNTIME) --verbose --statfile stats.pl --regression bench.exe
535         perl viewstat.pl stats.pl
536
537 stat2: mono basic.exe
538         $(RUNTIME) --verbose --statfile stats.pl --regression basic.exe
539         perl viewstat.pl -e stats.pl
540
541 stat3: mono bench.exe
542         $(RUNTIME) --statfile stats.pl --ncompile 1000 --compile Tests:test_0_many_nested_loops bench.exe 
543         perl viewstat.pl stats.pl
544
545 docu: mini.sgm
546         docbook2txt mini.sgm
547
548 check-local: rcheck
549
550 clean-local:
551         rm -f mono a.out gmon.out *.o buildver.h test.exe
552
553 pkgconfigdir = $(libdir)/pkgconfig
554
555 if JIT_SUPPORTED
556 BUILT_SOURCES = version.h $(arch_built)
557 else
558 BUILT_SOURCES = version.h
559 endif
560
561 CLEANFILES= $(BUILT_SOURCES) *.exe *.dll
562 EXTRA_DIST = $(common_BURGSRC) cprop.c TestDriver.cs ldscript ldscript.mono \
563         genmdesc.pl     \
564         $(test_sources) \
565         $(x86_sources) cpu-x86.md \
566         $(amd64_sources) cpu-amd64.md \
567         $(ppc_sources) cpu-ppc.md cpu-ppc64.md \
568         $(arm_sources) cpu-arm.md \
569         $(mips_sources) cpu-mips.md \
570         $(sparc_sources) cpu-sparc.md \
571         $(s390_sources) cpu-s390.md \
572         $(s390x_sources) cpu-s390x.md \
573         $(ia64_sources) cpu-ia64.md \
574         $(alpha_sources) cpu-alpha.md \
575         $(hppa_sources) cpu-hppa.md     \
576         $(windows_sources)              \
577         $(darwin_sources)               \
578         $(posix_sources)
579
580 version.h: Makefile
581         if test -d $(top_srcdir)/.git/svn; then svn_info="echo \"`git log --no-color --first-parent --pretty=format:%b|grep -m1 git-svn-id|sed -e 's,git-svn-id: \(.*\)@\(.*\) .*,URL: \1 Revision: \2,'`"; fi; \
582         if test -d $(srcdir)/.svn; then svn_info='svn info'; fi; \
583         if test -n "$$svn_info"; then \
584                 (cd $(top_srcdir); \
585                         LANG=C; export LANG; \
586                         branch=`$$svn_info | grep URL | sed -e 's,.*source/\(.*\)/mono.*,/\1/mono,'`; \
587                         version=`$$svn_info | grep Revision | sed 's/.*: //'`; \
588                         echo "#define FULL_VERSION \"$$branch r$$version\""; \
589                 ); \
590         else \
591                 echo "#define FULL_VERSION \"tarball\""; \
592         fi > version.h
593
594 # Utility target for patching libtool to speed up linking
595 patch-libtool:
596         sed -e 's,if (for obj in $$oldobjs,if (for obj in "",g' < ../../libtool > 2; mv 2 ../../libtool
597         chmod a+x ../../libtool