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