edb6a82771b9098a582e5e0267643449698cff00
[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 arm_sources = \
167         mini-arm.c              \
168         mini-arm.h              \
169         exceptions-arm.c        \
170         tramp-arm.c
171
172 mips_sources = \
173         mini-mips.c             \
174         mini-mips.h             \
175         exceptions-mips.c       \
176         tramp-mips.c
177
178 sparc_sources = \
179         mini-sparc.c            \
180         mini-sparc.h            \
181         exceptions-sparc.c      \
182         tramp-sparc.c
183
184 s390_sources = \
185         mini-s390.c             \
186         mini-s390.h             \
187         exceptions-s390.c       \
188         tramp-s390.c
189
190 s390x_sources = \
191         mini-s390x.c            \
192         mini-s390x.h            \
193         exceptions-s390x.c      \
194         tramp-s390x.c
195
196 ia64_sources = \
197         mini-ia64.c                     \
198         mini-ia64.h                     \
199         exceptions-ia64.c       \
200         tramp-ia64.c
201
202 alpha_sources = \
203         mini-alpha.c    \
204         mini-alpha.h    \
205         exceptions-alpha.c      \
206         tramp-alpha.c
207
208 hppa_sources = \
209         mini-hppa.c     \
210         mini-hppa.h     \
211         exceptions-hppa.c       \
212         tramp-hppa.c
213
214 common_sources = \
215         mini.c          \
216         ir-emit.h       \
217         method-to-ir.c  \
218         decompose.c     \
219         mini.h          \
220         version.h       \
221         optflags-def.h          \
222         jit-icalls.h \
223         jit-icalls.c \
224         trace.c         \
225         trace.h         \
226         patch-info.h    \
227         mini-ops.h      \
228         mini-arch.h     \
229         dominators.c    \
230         cfold.c         \
231         regalloc.c      \
232         regalloc.h      \
233         helpers.c       \
234         liveness.c      \
235         ssa.c           \
236         abcremoval.c    \
237         abcremoval.h    \
238         ssapre.c        \
239         ssapre.h        \
240         local-propagation.c     \
241         simple-cee-ops.h \
242         simple-mini-ops.h \
243         driver.c        \
244         debug-mini.c    \
245         debug-mini.h    \
246         linear-scan.c   \
247         aot-compiler.c          \
248         aot-runtime.c           \
249         graph.c         \
250         mini-exceptions.c       \
251         mini-codegen.c          \
252         mini-trampolines.c  \
253         declsec.c       \
254         declsec.h       \
255         wapihandles.c   \
256         branch-opts.c   \
257         generic-sharing.c       \
258         regalloc2.c     \
259         simd-methods.h  \
260         simd-intrinsics.c       \
261         unwind.h
262
263 test_sources =          \
264         basic-calls.cs  \
265         basic-long.cs   \
266         bench.cs                \
267         objects.cs              \
268         arrays.cs               \
269         basic-float.cs  \
270         basic-math.cs   \
271         basic.cs                \
272         exceptions.cs   \
273         devirtualization.cs     \
274         iltests.il.in           \
275         test.cs                 \
276         generics.cs     \
277         generics-variant-types.il       \
278         basic-simd.cs
279
280 if MONO_DEBUGGER_SUPPORTED
281 if AMD64
282 mono_debugger_arch_sources = mdb-debug-info64.s
283 else
284 if X86
285 mono_debugger_arch_sources = mdb-debug-info32.s
286 endif
287 endif
288 mono_debugger_sources = debug-debugger.c debug-debugger.h $(mono_debugger_arch_sources)
289 else
290 mono_debugger_sources =
291 endif
292
293 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
294
295 if X86
296 arch_sources = $(x86_sources) $(mono_debugger_sources)
297 arch_built=cpu-x86.h
298 arch_define=__i386__
299 endif
300
301 if AMD64
302 arch_sources = $(amd64_sources) $(mono_debugger_sources)
303 arch_built=cpu-amd64.h
304 arch_define=__x86_64__
305 endif
306
307 if POWERPC
308 arch_sources = $(ppc_sources)
309 arch_built=cpu-ppc.h
310 arch_define=__ppc__
311 endif
312
313 if POWERPC64
314 arch_sources = $(ppc_sources)
315 arch_built=cpu-ppc64.h
316 arch_define=__ppc__
317 endif
318
319 if MIPS
320 arch_sources = $(mips_sources)
321 arch_built=cpu-mips.h
322 arch_define=__mips__
323 endif
324
325 if ARM
326 # pick up arm_dpimacros.h and arm_fpamacros.h
327 ARCH_CFLAGS = -I../arch/arm
328 arch_sources = $(arm_sources)
329 arch_built=cpu-arm.h
330 arch_define=__arm__
331 endif
332
333 if SPARC
334 arch_sources = $(sparc_sources)
335 arch_built=cpu-sparc.h
336 arch_define=__sparc__
337 endif
338
339 if SPARC64
340 arch_sources = $(sparc_sources)
341 arch_built=cpu-sparc.h
342 arch_define=__sparc__
343 endif
344
345 if S390
346 arch_sources = $(s390_sources)
347 arch_BURGSRC= $(srcdir)/inssel-long32.brg $(srcdir)/inssel-s390.brg
348 arch_built=cpu-s390.h
349 arch_define=__s390__
350 endif
351
352 if S390x
353 arch_sources = $(s390x_sources)
354 arch_built=cpu-s390x.h
355 arch_define=__s390__
356 endif
357
358 if IA64
359 arch_sources = $(ia64_sources)
360 arch_built = cpu-ia64.h
361 arch_define=__ia64__
362 endif
363
364 if ALPHA
365 arch_sources = $(alpha_sources) $(mono_debugger_sources)
366 arch_built = cpu-alpha.h
367 arch_define=__alpha__
368 endif
369
370 if HPPA
371 # Only support 32-bit targets for now
372 arch_sources = $(hppa_sources)
373 arch_built = cpu-hppa.h
374 arch_define=__hppa__
375 endif
376
377 libmono_la_SOURCES = $(common_sources) $(arch_sources)
378
379 libmono_static_la_SOURCES = $(libmono_la_SOURCES)
380 nodist_libmono_static_la_SOURCES = $(nodist_libmono_la_SOURCES)
381 libmono_static_la_LDFLAGS = -static
382 libmono_static_la_LIBADD = $(static_libs) $(MONO_DTRACE_OBJECT)
383
384 BURGSRC= $(common_BURGSRC) $(arch_BURGSRC)
385
386 libmonoincludedir = $(includedir)/mono-$(API_VER)/mono/jit
387
388 libmonoinclude_HEADERS = jit.h
389
390 libmono_la_LIBADD = \
391         $(libs) $(LIBMONO_DTRACE_OBJECT)
392
393 basic-simd.exe: basic-simd.cs
394         $(MCS) -out:$@ $< -r:TestDriver.dll -r:Mono.Simd.dll
395
396 generics.exe: generics.cs TestDriver.dll generics-variant-types.dll
397         $(MCS) -out:$@ $< -r:TestDriver.dll -r:generics-variant-types.dll
398
399 %.exe: %.cs TestDriver.dll
400         $(MCS) -out:$@ -unsafe $< -r:TestDriver.dll
401
402 iltests.il: iltests.il.in Makefile.am
403         echo '// DO NOT EDIT: This file has been generated from iltests.il.in' > iltests.il
404         cpp -Darch=$(arch_define) < $(srcdir)/iltests.il.in | sed 's/^#.*//' >> iltests.il
405
406 %.exe: %.il
407         $(ILASM) -output=$@ $<
408
409 TestDriver.dll: $(srcdir)/TestDriver.cs
410         $(MCS) -out:$@ -target:library $<
411
412 generics-variant-types.dll: generics-variant-types.il
413         $(ILASM) -dll -output=$@ $<
414
415 # we don't always use the perl impl because it's an additional
416 # build dependency for the poor windows users
417 # $(arch_define) is the preprocessor symbol that enables all the opcodes
418 # for the specific platform in mini-ops.h
419 if CROSS_COMPILING
420 GENMDESC_PRG=perl $(srcdir)/genmdesc.pl $(arch_define) $(srcdir)
421 else !CROSS_COMPILING
422 GENMDESC_PRG=./genmdesc
423 endif !CROSS_COMPILING
424
425 cpu-x86.h: cpu-x86.md genmdesc$(EXEEXT)
426         $(GENMDESC_PRG) $(srcdir)/cpu-x86.md cpu-x86.h x86_desc
427
428 cpu-amd64.h: cpu-amd64.md genmdesc$(EXEEXT)
429         $(GENMDESC_PRG) $(srcdir)/cpu-amd64.md cpu-amd64.h amd64_desc
430
431 cpu-ppc.h: cpu-ppc.md genmdesc$(EXEEXT)
432         $(GENMDESC_PRG) $(srcdir)/cpu-ppc.md cpu-ppc.h ppcg4
433
434 cpu-ppc64.h: cpu-ppc64.md genmdesc$(EXEEXT)
435         $(GENMDESC_PRG) $(srcdir)/cpu-ppc64.md cpu-ppc64.h ppcg4
436
437 cpu-arm.h: cpu-arm.md genmdesc$(EXEEXT)
438         $(GENMDESC_PRG) $(srcdir)/cpu-arm.md cpu-arm.h arm_cpu_desc
439
440 cpu-sparc.h: cpu-sparc.md genmdesc$(EXEEXT)
441         $(GENMDESC_PRG) $(srcdir)/cpu-sparc.md cpu-sparc.h sparc_desc
442
443 cpu-s390.h: cpu-s390.md genmdesc$(EXEEXT)
444         $(GENMDESC_PRG) $(srcdir)/cpu-s390.md cpu-s390.h s390_cpu_desc
445
446 cpu-s390x.h: cpu-s390x.md genmdesc$(EXEEXT)
447         $(GENMDESC_PRG) $(srcdir)/cpu-s390x.md cpu-s390x.h s390x_cpu_desc
448
449 cpu-ia64.h: cpu-ia64.md genmdesc$(EXEEXT)
450         $(GENMDESC_PRG) $(srcdir)/cpu-ia64.md cpu-ia64.h ia64_desc
451
452 cpu-alpha.h: cpu-alpha.md genmdesc$(EXEEXT)
453         $(GENMDESC_PRG) $(srcdir)/cpu-alpha.md cpu-alpha.h alpha_desc
454
455 cpu-hppa.h: cpu-hppa.md genmdesc$(EXEEXT)
456         $(GENMDESC_PRG) $(srcdir)/cpu-hppa.md cpu-hppa.h hppa_desc
457
458 cpu-mips.h: cpu-mips.md genmdesc$(EXEEXT)
459         $(GENMDESC_PRG) $(srcdir)/cpu-mips.md cpu-mips.h mips_desc
460
461 testi: mono test.exe
462         $(RUNTIME) -v -v --ncompile 1 --compile Test:$(mtest) test.exe
463
464 # ensure the tests are actually correct
465 checktests: $(regtests)
466         for i in $(regtests); do $(RUNTIME) $$i; done
467
468 rcheck: mono $(regtests)
469         $(RUNTIME) --regression $(regtests)
470
471 aotcheck: mono $(regtests)
472         rm -f *.exe.so
473         $(RUNTIME) --aot $(regtests) || exit 1
474         for i in $(regtests); do $(RUNTIME_AOTCHECK) --regression $$i || exit 1; done
475         rm -f *.exe.so
476
477 bench: mono test.exe
478         time env $(RUNTIME) --ncompile $(count) --compile Test:$(mtest) test.exe
479
480 mbench: test.exe
481         time $(monodir)/mono/jit/mono --ncompile $(count) --compile Test:$(mtest) test.exe
482
483 stat1: mono bench.exe
484         $(RUNTIME) --verbose --statfile stats.pl --regression bench.exe
485         perl viewstat.pl stats.pl
486
487 stat2: mono basic.exe
488         $(RUNTIME) --verbose --statfile stats.pl --regression basic.exe
489         perl viewstat.pl -e stats.pl
490
491 stat3: mono bench.exe
492         $(RUNTIME) --statfile stats.pl --ncompile 1000 --compile Tests:test_0_many_nested_loops bench.exe 
493         perl viewstat.pl stats.pl
494
495 docu: mini.sgm
496         docbook2txt mini.sgm
497
498 check-local: rcheck
499
500 clean-local:
501         rm -f mono a.out gmon.out *.o buildver.h test.exe
502
503 pkgconfigdir = $(libdir)/pkgconfig
504
505 if JIT_SUPPORTED
506 BUILT_SOURCES = version.h $(arch_built)
507 else
508 BUILT_SOURCES = version.h
509 endif
510
511 CLEANFILES= $(BUILT_SOURCES) *.exe *.dll
512 EXTRA_DIST = $(common_BURGSRC) cprop.c TestDriver.cs ldscript ldscript.mono \
513         genmdesc.pl     \
514         $(test_sources) \
515         $(x86_sources) cpu-x86.md \
516         $(amd64_sources) cpu-amd64.md \
517         $(ppc_sources) cpu-ppc.md \
518         $(arm_sources) cpu-arm.md \
519         $(mips_sources) cpu-mips.md \
520         $(sparc_sources) cpu-sparc.md \
521         $(s390_sources) cpu-s390.md \
522         $(s390x_sources) cpu-s390x.md \
523         $(ia64_sources) cpu-ia64.md \
524         $(alpha_sources) cpu-alpha.md \
525         $(hppa_sources) cpu-hppa.md
526
527 version.h: Makefile
528         if test -d $(top_srcdir)/.git/svn; then svn_info='git svn info'; fi; \
529         if test -d $(srcdir)/.svn; then svn_info='svn info'; fi; \
530         if test -n "$$svn_info"; then \
531                 (cd $(top_srcdir); \
532                         LANG=C; export LANG; \
533                         branch=`$$svn_info | grep URL | sed -e 's/.*source//' -e 's,mono/?$$,,'`; \
534                         version=`$$svn_info | grep Revision | sed 's/.*: //'`; \
535                         echo "#define FULL_VERSION \"$$branch r$$version\""; \
536                 ); \
537         else \
538                 echo "#define FULL_VERSION \"tarball\""; \
539         fi > version.h
540
541 # Utility target for patching libtool to speed up linking
542 patch-libtool:
543         sed -e 's,if (for obj in $$oldobjs,if (for obj in "",g' < ../../libtool > 2; mv 2 ../../libtool
544         chmod a+x ../../libtool