1#
2# This directory is used to AOT the C# compiler to speed up the rest of the class libs build
3# It should be run after the assemblies the compiler depends on have been compiled, since
4# the AOT image has a dependency on the exact assembly versions used to produce it.
5#
6
7thisdir = class/aot-compiler
8
9include ../../build/rules.make
10
11the_libdir = $(topdir)/class/lib/$(PROFILE_DIRECTORY)/
12CSC_DIR = $(dir $(CSC_LOCATION))
13# The directory where the AOT images are stored
14images_dir = $(the_libdir)
15
16# mcs.exe is only in the build profile, but the aot image should be compiled against the current
17# profile
18mcs_exe = $(the_libdir)/mcs.exe
19mcs_aot_image = $(the_libdir)/mcs.exe$(PLATFORM_AOT_SUFFIX)
20csc_exe = $(CSC_LOCATION)
21csc_aot_image = $(images_dir)/csc.exe$(PLATFORM_AOT_SUFFIX)
22csc_MCS_dll = $(CSC_DIR)/Microsoft.CodeAnalysis.CSharp.dll
23csc_MCS_image = $(images_dir)/Microsoft.CodeAnalysis.CSharp.dll$(PLATFORM_AOT_SUFFIX)
24csc_MC_dll = $(CSC_DIR)/Microsoft.CodeAnalysis.dll
25csc_MC_image = $(images_dir)/Microsoft.CodeAnalysis.dll$(PLATFORM_AOT_SUFFIX)
26csc_SRM_dll = $(CSC_DIR)/System.Reflection.Metadata.dll
27csc_SRM_image = $(images_dir)/System.Reflection.Metadata.dll$(PLATFORM_AOT_SUFFIX)
28csc_SCI_dll = $(CSC_DIR)/System.Collections.Immutable.dll
29csc_SCI_image = $(images_dir)/System.Collections.Immutable.dll$(PLATFORM_AOT_SUFFIX)
30
31mscorlib_dll = $(the_libdir)/mscorlib.dll
32mscorlib_aot_image = $(mscorlib_dll)$(PLATFORM_AOT_SUFFIX)
33
34# The $(dir $(RUNTIME)) is necessary to get path to the mono binary in case when we cross-compile
35# or just compile from a different directory than the top source dir
36runtime_dep = $(dir $(RUNTIME))/../mono/mini/mono
37
38PROGRAM_INSTALL_DIR = $(mono_libdir)/mono/$(FRAMEWORK_VERSION)
39LIBRARY_INSTALL_DIR = $(mono_libdir)/mono/$(FRAMEWORK_VERSION)
40
41LOG_FILE = $(PROFILE_DIRECTORY)_aot.log
42
43ifndef SKIP_AOT
44
45profile_file:=$(wildcard $(topdir)/class/lib/build/csc.*.aotprofile)
46ifneq ($(profile_file),)
47comma:=,
48space:=
49space+=
50profile_arg:=$(subst $(space)$(comma),$(comma),$(foreach pf,$(profile_file),$(comma)profile=$(strip $(pf))))
51endif
52
53ifdef PLATFORM_AOT_SUFFIX
54$(mcs_aot_image): $(mcs_exe) $(mscorlib_dll) $(runtime_dep)
55	$(Q_AOT) MONO_PATH='$(the_libdir)' > $(LOG_FILE) 2>&1 $(RUNTIME) --aot=bind-to-runtime-version$(profile_arg),outfile=$(mcs_aot_image) --debug $(mcs_exe) || cat $(LOG_FILE) || (cat $(LOG_FILE); exit 1)
56
57$(csc_aot_image): $(csc_exe) $(mscorlib_dll) $(runtime_dep)
58	$(Q_AOT) MONO_PATH='$(the_libdir)' > $(LOG_FILE) 2>&1 $(RUNTIME) --aot=bind-to-runtime-version$(profile_arg),outfile=$(csc_aot_image) --debug $(csc_exe) || cat $(LOG_FILE) || (cat $(LOG_FILE); exit 1)
59
60$(mscorlib_aot_image): $(mscorlib_dll) $(runtime_dep)
61	$(Q_AOT) MONO_PATH='$(the_libdir)' > $(LOG_FILE) 2>&1 $(RUNTIME) --aot=bind-to-runtime-version$(profile_arg) --debug $(mscorlib_dll) || (cat $(LOG_FILE); exit 1)
62
63$(csc_MC_image): $(csc_MC_dll) $(runtime_dep)
64	$(Q_AOT) MONO_PATH='$(the_libdir)' > $(LOG_FILE) 2>&1 $(RUNTIME) --aot=bind-to-runtime-version$(profile_arg),outfile=$(csc_MC_image) --debug $(csc_MC_dll) || (cat $(LOG_FILE); exit 1)
65
66$(csc_MCS_image): $(csc_MCS_dll) $(runtime_dep)
67	$(Q_AOT) MONO_PATH='$(the_libdir)' > $(LOG_FILE) 2>&1 $(RUNTIME) --aot=bind-to-runtime-version$(profile_arg),outfile=$(csc_MCS_image) --debug $(csc_MCS_dll) || (cat $(LOG_FILE); exit 1)
68
69$(csc_SRM_image): $(csc_SRM_dll) $(runtime_dep)
70	$(Q_AOT) MONO_PATH='$(the_libdir)' > $(LOG_FILE) 2>&1 $(RUNTIME) --aot=bind-to-runtime-version$(profile_arg),outfile=$(csc_SRM_image) --debug --apply-bindings=$(csc_exe).config $(csc_SRM_dll) || (cat $(LOG_FILE); exit 1)
71
72$(csc_SCI_image): $(csc_SCI_dll) $(runtime_dep)
73	$(Q_AOT) MONO_PATH='$(the_libdir)' > $(LOG_FILE) 2>&1 $(RUNTIME) --aot=bind-to-runtime-version$(profile_arg),outfile=$(csc_SCI_image) --debug $(csc_SCI_dll) || (cat $(LOG_FILE); exit 1)
74
75ifdef ENABLE_AOT
76
77CSC_IMAGES = $(csc_aot_image) $(csc_SRM_image) $(csc_SCI_image) $(csc_MC_image) $(csc_MCS_image)
78
79clean-local:
80	-rm -f $(mscorlib_aot_image) $(mcs_aot_image) $(CSC_IMAGES) $(LOG_FILE)
81
82# AOT build profile to speed up build
83ifeq ($(PROFILE),build)
84
85IMAGES = $(mscorlib_aot_image)
86
87ifdef MCS_MODE
88IMAGES += $(mcs_aot_image)
89else
90IMAGES += $(CSC_IMAGES)
91endif
92
93all-local: $(IMAGES)
94install-local:
95
96endif
97
98ifeq ($(PROFILE), $(DEFAULT_PROFILE))
99
100IMAGES = $(mscorlib_aot_image) $(mcs_aot_image) $(CSC_IMAGES)
101
102all-local: $(IMAGES)
103install-local:
104	$(MKINSTALLDIRS) $(DESTDIR)$(LIBRARY_INSTALL_DIR)
105	$(INSTALL_LIB) $(IMAGES) $(DESTDIR)$(LIBRARY_INSTALL_DIR)
106
107endif
108
109endif
110
111endif
112
113endif
114
115dist-local: dist-default
116