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