2009-12-10 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 HOST_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 HOST_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 HOST_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         $(LLVM_LDFLAGS)
119
120 mono_LDFLAGS = \
121         $(static_flags) -export-dynamic $(monobinldflags) $(monobin_platform_ldflags)
122
123 if DTRACE_G_REQUIRED
124
125 mono-dtrace.$(OBJEXT): $(top_srcdir)/data/mono.d mini.lo $(monodir)/mono/metadata/libmonoruntime-static.la
126         DTRACE="$(DTRACE)" DTRACEFLAGS="$(DTRACEFLAGS)" AR="$(AR)" $(SHELL) $(top_srcdir)/data/dtrace-prelink.sh \
127         $@ $(top_srcdir)/data/mono.d $(monodir)/mono/metadata/libmonoruntime-static.la mini.lo
128
129 .libs/mono-dtrace.$(OBJEXT): $(top_srcdir)/data/mono.d mini.lo $(monodir)/mono/metadata/libmonoruntime.la
130         DTRACE="$(DTRACE)" DTRACEFLAGS="$(DTRACEFLAGS)" AR="$(AR)" $(SHELL) $(top_srcdir)/data/dtrace-prelink.sh \
131         --pic $@ $(top_srcdir)/data/mono.d $(monodir)/mono/metadata/libmonoruntime.la mini.lo
132
133 endif
134
135 # Create monow.exe, linked for the 'windows' subsystem
136 if HOST_WIN32
137 monow_LDADD = $(mono_LDADD)
138 monow_LDFLAGS = $(mono_LDFLAGS) -mwindows
139 monow_SOURCES = $(mono_SOURCES)
140 endif
141
142 genmdesc_SOURCES = \
143         mini.h          \
144         genmdesc.c      \
145         helpers.c
146
147 # Don't link this against libmonoruntime to speed up rebuilds
148 genmdesc_LDADD = \
149         $(monodir)/mono/utils/libmonoutils.la $(monodir)/mono/metadata/opcodes.lo -lm   \
150         $(GLIB_LIBS)
151
152 x86_sources = \
153         mini-x86.c              \
154         mini-x86.h              \
155         exceptions-x86.c        \
156         tramp-x86.c
157
158 amd64_sources = \
159         mini-amd64.c            \
160         mini-amd64.h            \
161         exceptions-amd64.c      \
162         tramp-amd64.c
163
164 ppc_sources = \
165         mini-ppc.c              \
166         mini-ppc.h              \
167         exceptions-ppc.c        \
168         tramp-ppc.c
169
170 arm_sources = \
171         mini-arm.c              \
172         mini-arm.h              \
173         exceptions-arm.c        \
174         tramp-arm.c
175
176 mips_sources = \
177         mini-mips.c             \
178         mini-mips.h             \
179         exceptions-mips.c       \
180         tramp-mips.c
181
182 sparc_sources = \
183         mini-sparc.c            \
184         mini-sparc.h            \
185         exceptions-sparc.c      \
186         tramp-sparc.c
187
188 s390_sources = \
189         mini-s390.c             \
190         mini-s390.h             \
191         exceptions-s390.c       \
192         tramp-s390.c
193
194 s390x_sources = \
195         mini-s390x.c            \
196         mini-s390x.h            \
197         exceptions-s390x.c      \
198         tramp-s390x.c
199
200 ia64_sources = \
201         mini-ia64.c             \
202         mini-ia64.h             \
203         exceptions-ia64.c       \
204         tramp-ia64.c
205
206 alpha_sources = \
207         mini-alpha.c            \
208         mini-alpha.h            \
209         exceptions-alpha.c      \
210         tramp-alpha.c
211
212 hppa_sources = \
213         mini-hppa.c             \
214         mini-hppa.h             \
215         exceptions-hppa.c       \
216         tramp-hppa.c
217
218 darwin_sources = \
219         mini-darwin.c
220
221 windows_sources = \
222         mini-windows.c
223
224 posix_sources = \
225         mini-posix.c
226
227 if ENABLE_LLVM
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         mini-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         debugger-agent.h \
289         debugger-agent.c
290
291 test_sources =                  \
292         basic-calls.cs          \
293         basic-long.cs           \
294         bench.cs                \
295         objects.cs              \
296         arrays.cs               \
297         basic-float.cs          \
298         basic-math.cs           \
299         basic.cs                \
300         exceptions.cs           \
301         devirtualization.cs     \
302         iltests.il.in           \
303         test.cs                 \
304         generics.cs             \
305         generics-variant-types.il\
306         basic-simd.cs
307
308 if MONO_DEBUGGER_SUPPORTED
309 if PLATFORM_DARWIN
310 mono_debugger_arch_sources = mdb-debug-info32-darwin.s
311 else
312 if AMD64
313 mono_debugger_arch_sources = mdb-debug-info64.s
314 else
315 if X86
316 mono_debugger_arch_sources = mdb-debug-info32.s
317 endif
318 endif
319 endif
320 mono_debugger_sources = debug-debugger.c debug-debugger.h $(mono_debugger_arch_sources)
321 else
322 mono_debugger_sources =
323 endif
324
325 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
326
327 if X86
328 arch_sources = $(x86_sources) $(mono_debugger_sources)
329 arch_built=cpu-x86.h
330 arch_define=__i386__
331 endif
332
333 if AMD64
334 arch_sources = $(amd64_sources) $(mono_debugger_sources)
335 arch_built=cpu-amd64.h
336 arch_define=__x86_64__
337 endif
338
339 if POWERPC
340 arch_sources = $(ppc_sources)
341 arch_built=cpu-ppc.h
342 arch_define=__ppc__
343 endif
344
345 if POWERPC64
346 arch_sources = $(ppc_sources)
347 arch_built=cpu-ppc64.h
348 arch_define=__ppc64__
349 endif
350
351 if MIPS
352 arch_sources = $(mips_sources)
353 arch_built=cpu-mips.h
354 arch_define=__mips__
355 endif
356
357 if ARM
358 # pick up arm_dpimacros.h and arm_fpamacros.h
359 ARCH_CFLAGS = -I../arch/arm
360 arch_sources = $(arm_sources)
361 arch_built=cpu-arm.h
362 arch_define=__arm__
363 endif
364
365 if SPARC
366 arch_sources = $(sparc_sources)
367 arch_built=cpu-sparc.h
368 arch_define=__sparc__
369 endif
370
371 if SPARC64
372 arch_sources = $(sparc_sources)
373 arch_built=cpu-sparc.h
374 arch_define=__sparc__
375 endif
376
377 if S390
378 arch_sources = $(s390_sources)
379 arch_built=cpu-s390.h
380 arch_define=__s390__
381 endif
382
383 if S390x
384 arch_sources = $(s390x_sources)
385 arch_built=cpu-s390x.h
386 arch_define=__s390__
387 endif
388
389 if IA64
390 arch_sources = $(ia64_sources)
391 arch_built = cpu-ia64.h
392 arch_define=__ia64__
393 endif
394
395 if ALPHA
396 arch_sources = $(alpha_sources) $(mono_debugger_sources)
397 arch_built = cpu-alpha.h
398 arch_define=__alpha__
399 endif
400
401 if HPPA
402 # Only support 32-bit targets for now
403 arch_sources = $(hppa_sources)
404 arch_built = cpu-hppa.h
405 arch_define=__hppa__
406 endif
407
408 if HOST_WIN32
409 os_sources = $(windows_sources)
410 monobin_platform_ldflags=
411 endif
412
413 if PLATFORM_SIGPOSIX
414 os_sources = $(posix_sources)
415 monobin_platform_ldflags=
416 endif
417
418 if PLATFORM_DARWIN
419 os_sources = $(darwin_sources) $(posix_sources)
420 monobin_platform_ldflags=-sectcreate __TEXT __info_plist $(top_srcdir)/mono/mini/Info.plist
421 endif
422
423 libmono_la_SOURCES = $(common_sources) $(llvm_sources) $(arch_sources) $(os_sources)
424
425 libmono_static_la_SOURCES = $(libmono_la_SOURCES)
426 nodist_libmono_static_la_SOURCES = $(nodist_libmono_la_SOURCES)
427 libmono_static_la_LDFLAGS = -static
428 libmono_static_la_LIBADD = $(static_libs) $(MONO_DTRACE_OBJECT)
429
430 BURGSRC= $(common_BURGSRC) $(arch_BURGSRC)
431
432 libmonoincludedir = $(includedir)/mono-$(API_VER)/mono/jit
433
434 libmonoinclude_HEADERS = jit.h
435
436 libmono_la_LIBADD = \
437         $(libs) $(LIBMONO_DTRACE_OBJECT)
438
439 basic-simd.exe: basic-simd.cs
440         $(MCS) -out:$@ $< -r:TestDriver.dll -r:Mono.Simd.dll
441
442 generics.exe: generics.cs TestDriver.dll generics-variant-types.dll
443         $(MCS) -out:$@ $< -r:TestDriver.dll -r:generics-variant-types.dll
444
445 %.exe: %.cs TestDriver.dll
446         $(MCS) -out:$@ -unsafe $< -r:TestDriver.dll
447
448 iltests.il: iltests.il.in Makefile.am
449         echo '// DO NOT EDIT: This file has been generated from iltests.il.in' > iltests.il
450         cpp -Darch=$(arch_define) < $(srcdir)/iltests.il.in | sed 's/^#.*//' >> iltests.il
451
452 %.exe: %.il
453         $(ILASM) -output=$@ $<
454
455 TestDriver.dll: $(srcdir)/TestDriver.cs
456         $(MCS) -out:$@ -target:library $<
457
458 generics-variant-types.dll: generics-variant-types.il
459         $(ILASM) -dll -output=$@ $<
460
461 # we don't always use the perl impl because it's an additional
462 # build dependency for the poor windows users
463 # $(arch_define) is the preprocessor symbol that enables all the opcodes
464 # for the specific platform in mini-ops.h
465 if CROSS_COMPILING
466 GENMDESC_PRG=perl $(srcdir)/genmdesc.pl $(arch_define) $(srcdir)
467 else !CROSS_COMPILING
468 GENMDESC_PRG=./genmdesc
469 endif !CROSS_COMPILING
470
471 cpu-x86.h: cpu-x86.md genmdesc$(EXEEXT)
472         $(GENMDESC_PRG) cpu-x86.h x86_desc $(srcdir)/cpu-x86.md
473
474 cpu-amd64.h: cpu-amd64.md genmdesc$(EXEEXT)
475         $(GENMDESC_PRG) cpu-amd64.h amd64_desc $(srcdir)/cpu-amd64.md
476
477 cpu-ppc.h: cpu-ppc.md genmdesc$(EXEEXT)
478         $(GENMDESC_PRG) cpu-ppc.h ppcg4 $(srcdir)/cpu-ppc.md
479
480 cpu-ppc64.h: cpu-ppc64.md genmdesc$(EXEEXT)
481         $(GENMDESC_PRG) cpu-ppc64.h ppc64_cpu_desc $(srcdir)/cpu-ppc64.md
482
483 cpu-arm.h: cpu-arm.md genmdesc$(EXEEXT)
484         $(GENMDESC_PRG) cpu-arm.h arm_cpu_desc $(srcdir)/cpu-arm.md
485
486 cpu-sparc.h: cpu-sparc.md genmdesc$(EXEEXT)
487         $(GENMDESC_PRG) cpu-sparc.h sparc_desc $(srcdir)/cpu-sparc.md
488
489 cpu-s390.h: cpu-s390.md genmdesc$(EXEEXT)
490         $(GENMDESC_PRG) cpu-s390.h s390_cpu_desc $(srcdir)/cpu-s390.md
491
492 cpu-s390x.h: cpu-s390x.md genmdesc$(EXEEXT)
493         $(GENMDESC_PRG) cpu-s390x.h s390x_cpu_desc $(srcdir)/cpu-s390x.md
494
495 cpu-ia64.h: cpu-ia64.md genmdesc$(EXEEXT)
496         $(GENMDESC_PRG) cpu-ia64.h ia64_desc $(srcdir)/cpu-ia64.md
497
498 cpu-alpha.h: cpu-alpha.md genmdesc$(EXEEXT)
499         $(GENMDESC_PRG) cpu-alpha.h alpha_desc $(srcdir)/cpu-alpha.md
500
501 cpu-hppa.h: cpu-hppa.md genmdesc$(EXEEXT)
502         $(GENMDESC_PRG) cpu-hppa.h hppa_desc $(srcdir)/cpu-hppa.md
503
504 cpu-mips.h: cpu-mips.md genmdesc$(EXEEXT)
505         $(GENMDESC_PRG) cpu-mips.h mips_desc $(srcdir)/cpu-mips.md
506
507 testi: mono test.exe
508         $(RUNTIME) -v -v --ncompile 1 --compile Test:$(mtest) test.exe
509
510 # ensure the tests are actually correct
511 checktests: $(regtests)
512         for i in $(regtests); do $(RUNTIME) $$i; done
513
514 rcheck: mono $(regtests)
515         $(RUNTIME) --regression $(regtests)
516
517 aotcheck: mono $(regtests)
518         rm -f *.exe.so
519         $(RUNTIME) --aot $(regtests) || exit 1
520         for i in $(regtests); do $(RUNTIME_AOTCHECK) --regression $$i || exit 1; done
521         rm -f *.exe.so
522
523 # This currently only works on amd64/arm
524 fullaotcheck: mono $(regtests)
525         rm -rf fullaot-tmp
526         mkdir fullaot-tmp
527         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/
528         cp $(regtests) fullaot-tmp/
529         MONO_PATH=fullaot-tmp $(top_builddir)/runtime/mono-wrapper --aot=full fullaot-tmp/* || exit 1
530         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
531
532 bench: mono test.exe
533         time env $(RUNTIME) --ncompile $(count) --compile Test:$(mtest) test.exe
534
535 mbench: test.exe
536         time $(monodir)/mono/jit/mono --ncompile $(count) --compile Test:$(mtest) test.exe
537
538 stat1: mono bench.exe
539         $(RUNTIME) --verbose --statfile stats.pl --regression bench.exe
540         perl viewstat.pl stats.pl
541
542 stat2: mono basic.exe
543         $(RUNTIME) --verbose --statfile stats.pl --regression basic.exe
544         perl viewstat.pl -e stats.pl
545
546 stat3: mono bench.exe
547         $(RUNTIME) --statfile stats.pl --ncompile 1000 --compile Tests:test_0_many_nested_loops bench.exe 
548         perl viewstat.pl stats.pl
549
550 docu: mini.sgm
551         docbook2txt mini.sgm
552
553 check-local: rcheck
554
555 clean-local:
556         rm -f mono a.out gmon.out *.o buildver.h test.exe
557
558 pkgconfigdir = $(libdir)/pkgconfig
559
560 if JIT_SUPPORTED
561 BUILT_SOURCES = version.h $(arch_built)
562 else
563 BUILT_SOURCES = version.h
564 endif
565
566 CLEANFILES= $(BUILT_SOURCES) *.exe *.dll
567 EXTRA_DIST = $(common_BURGSRC) TestDriver.cs ldscript ldscript.mono \
568         genmdesc.pl     \
569         $(test_sources) \
570         $(x86_sources) cpu-x86.md \
571         $(amd64_sources) cpu-amd64.md \
572         $(ppc_sources) cpu-ppc.md cpu-ppc64.md \
573         $(arm_sources) cpu-arm.md \
574         $(mips_sources) cpu-mips.md \
575         $(sparc_sources) cpu-sparc.md \
576         $(s390_sources) cpu-s390.md \
577         $(s390x_sources) cpu-s390x.md \
578         $(ia64_sources) cpu-ia64.md \
579         $(alpha_sources) cpu-alpha.md \
580         $(hppa_sources) cpu-hppa.md     \
581         $(windows_sources)              \
582         $(darwin_sources) Info.plist    \
583         $(posix_sources)
584
585 version.h: Makefile
586         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; \
587         if test -d $(srcdir)/.svn; then svn_info='svn info'; fi; \
588         if test -n "$$svn_info"; then \
589                 (cd $(top_srcdir); \
590                         LANG=C; export LANG; \
591                         branch=`eval $$svn_info | sed -n -e '/URL/ s,.*source/\(.*\)/mono.*,/\1/mono,p'`; \
592                         version=`eval $$svn_info | sed -n -e '/Revision/ s/.*: //p'`; \
593                         echo "#define FULL_VERSION \"$$branch r$$version\""; \
594                 ); \
595         else \
596                 echo "#define FULL_VERSION \"tarball\""; \
597         fi > version.h
598
599 # Utility target for patching libtool to speed up linking
600 patch-libtool:
601         sed -e 's,if (for obj in $$oldobjs,if (for obj in "",g' < ../../libtool > 2; mv 2 ../../libtool
602         chmod a+x ../../libtool
603
604 tags:
605         etags -o TAGS `find .. -name "*.h" -o -name "*.c"`