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