8acb0f5df619f789fd717207654d9178d6d9d178
[mono.git] / mcs / build / executable.make
1 # -*- makefile -*-
2 #
3 # The rules for building a program.
4
5 base_prog = $(notdir $(PROGRAM))
6 ifndef sourcefile
7 sourcefile := $(base_prog).sources
8 endif
9 base_prog_config := $(wildcard $(base_prog).config.$(PROFILE))
10 ifndef base_prog_config
11 base_prog_config := $(wildcard $(base_prog).config)
12 endif
13
14 ifeq (cat,$(PLATFORM_CHANGE_SEPARATOR_CMD))
15 response = $(sourcefile)
16 else
17 response = $(depsdir)/$(sourcefile).response
18 executable_CLEAN_FILES += $(response)
19 endif
20
21 ifndef the_libdir
22 the_libdir = $(topdir)/class/lib/$(PROFILE)/
23 ifdef PROGRAM_USE_INTERMEDIATE_FILE
24 build_libdir = $(the_libdir)tmp/
25 else
26 build_libdir = $(the_libdir)
27 endif
28 endif
29
30 ifdef base_prog_config
31 PROGRAM_config := $(build_libdir)$(PROGRAM).config
32 endif
33
34 sn = $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/sn.exe
35 SN = MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(sn) -q
36
37 the_lib = $(the_libdir)$(base_prog)
38 build_lib = $(build_libdir)$(base_prog)
39
40 executable_CLEAN_FILES += $(the_lib)   $(the_lib).so   $(the_lib).mdb   $(the_lib:.exe=.pdb)
41 executable_CLEAN_FILES += $(build_lib) $(build_lib).so $(build_lib).mdb $(build_lib:.exe=.pdb)
42
43 makefrag = $(depsdir)/$(PROFILE)_$(base_prog).makefrag
44
45 ifndef NO_BUILD
46 all-local: $(the_lib) $(PROGRAM_config)
47 endif
48
49 install-local: all-local
50 test-local: all-local
51 uninstall-local:
52
53 ifdef NO_INSTALL
54 install-local uninstall-local:
55         @:
56 else
57
58 ifndef PROGRAM_INSTALL_DIR
59 PROGRAM_INSTALL_DIR = $(mono_libdir)/mono/$(FRAMEWORK_VERSION)
60 endif
61
62 install-local:
63         $(MKINSTALLDIRS) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
64         $(INSTALL_BIN) $(the_lib) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
65         test ! -f $(the_lib).mdb || $(INSTALL_BIN) $(the_lib).mdb $(DESTDIR)$(PROGRAM_INSTALL_DIR)
66 ifdef PROGRAM_config
67         $(INSTALL_DATA) $(PROGRAM_config) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
68 endif
69 ifdef PLATFORM_AOT_SUFFIX
70         test ! -f $(PROGRAM)$(PLATFORM_AOT_SUFFIX) || $(INSTALL_LIB) $(PROGRAM)$(PLATFORM_AOT_SUFFIX) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
71 endif
72
73 uninstall-local:
74         -rm -f $(DESTDIR)$(PROGRAM_INSTALL_DIR)/$(base_prog) $(DESTDIR)$(PROGRAM_INSTALL_DIR)/$(base_prog).mdb $(DESTDIR)$(PROGRAM_INSTALL_DIR)/$(base_prog).config
75 endif
76
77 clean-local:
78         -rm -f $(executable_CLEAN_FILES) $(CLEAN_FILES) $(tests_CLEAN_FILES)
79
80 test-local:
81         @:
82 run-test-local:
83         @:
84 run-test-ondotnet-local:
85         @:
86
87 DISTFILES = $(sourcefile) $(base_prog_config) $(EXTRA_DISTFILES)
88
89 ifdef HAS_NUNIT_TEST
90 ASSEMBLY      = $(PROGRAM)
91 ASSEMBLY_EXT  = .exe
92 the_assembly  = $(PROGRAM)
93 include $(topdir)/build/tests.make
94 endif
95
96 ifdef HAVE_CS_TESTS
97 DISTFILES += $(test_sourcefile)
98 endif
99
100 dist-local: dist-default
101         for f in `cat $(sourcefile)` ; do \
102           case $$f in \
103           ../*) : ;; \
104           *) dest=`dirname "$$f"` ; \
105              case $$subs in *" $$dest "*) : ;; *) subs=" $$dest$$subs" ; $(MKINSTALLDIRS) $(distdir)/$$dest ;; esac ; \
106              cp -p "$$f" $(distdir)/$$dest || exit 1 ;; \
107           esac ; done ; \
108         for d in . $$subs ; do \
109           case $$d in .) : ;; *) test ! -f $$d/ChangeLog || cp -p $$d/ChangeLog $(distdir)/$$d ;; esac ; done
110
111 ifndef PROGRAM_COMPILE
112 PROGRAM_COMPILE = $(CSCOMPILE)
113 endif
114
115 $(the_lib): $(the_libdir)/.stamp
116
117 $(build_lib): $(BUILT_SOURCES) $(EXTRA_SOURCES) $(response) $(build_libdir:=/.stamp)
118         $(PROGRAM_COMPILE) $(MCS_REFERENCES) -target:exe -out:$@ $(BUILT_SOURCES) $(EXTRA_SOURCES) @$(response)
119 ifdef PROGRAM_SNK
120         $(Q) $(SN) -R $@ $(PROGRAM_SNK)
121 endif
122
123 ifdef PROGRAM_USE_INTERMEDIATE_FILE
124 $(the_lib): $(build_lib)
125         $(Q) cp $(build_lib) $@
126         $(Q) test ! -f $(build_lib).mdb || mv $(build_lib).mdb $@.mdb
127         $(Q) test ! -f $(build_lib:.exe=.pdb) || mv $(build_lib:.exe=.pdb) $(the_lib:.exe=.pdb)
128 endif
129
130 ifdef PROGRAM_config
131 ifneq ($(base_prog_config),$(PROGRAM_config))
132 executable_CLEAN_FILES += $(PROGRAM_config)
133 $(PROGRAM_config): $(base_prog_config) $(dir $(PROGRAM_config))/.stamp
134         cp $(base_prog_config) $(PROGRAM_config)
135 endif
136 endif
137
138 $(makefrag): $(sourcefile)
139 #       @echo Creating $@ ...
140         @sed 's,^,$(build_lib): ,' $< >$@
141         @if test ! -f $(sourcefile).makefrag; then :; else \
142            cat $(sourcefile).makefrag >> $@ ; \
143            echo '$@: $(sourcefile).makefrag' >> $@; \
144            echo '$(sourcefile).makefrag:' >> $@; fi
145
146 ifneq ($(response),$(sourcefile))
147 $(response): $(sourcefile)
148         @echo Converting $(sourcefile) to $@ ...
149         @cat $(sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
150 endif
151
152 -include $(makefrag)
153
154 MCS_REFERENCES = $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.dll,$(LIB_REFS))
155 MCS_REFERENCES += $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.exe,$(EXE_REFS))
156
157 all-local: $(makefrag) $(extra_targets)
158
159 ifdef BUILT_SOURCES
160 library_CLEAN_FILES += $(BUILT_SOURCES)
161 ifeq (cat, $(PLATFORM_CHANGE_SEPARATOR_CMD))
162 BUILT_SOURCES_cmdline = $(BUILT_SOURCES)
163 else
164 BUILT_SOURCES_cmdline = `echo $(BUILT_SOURCES) | $(PLATFORM_CHANGE_SEPARATOR_CMD)`
165 endif
166 endif
167
168 csproj-local:
169         config_file=`basename $(PROGRAM) .exe`-$(PROFILE).input; \
170         echo $(thisdir):$$config_file >> $(topdir)/../msvc/scripts/order; \
171         (echo $(is_boot); \
172         echo $(USE_MCS_FLAGS) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) $(patsubst %,-r:%,$(LIB_REFS)); \
173         echo $(PROGRAM); \
174         echo $(BUILT_SOURCES_cmdline); \
175         echo $(build_lib); \
176         echo $(FRAMEWORK_VERSION); \
177         echo $(PROFILE); \
178         echo $(RESOURCE_DEFS); \
179         echo $(response)) > $(topdir)/../msvc/scripts/inputs/$$config_file
180
181
182 ifneq ($(response),$(sourcefile))
183 $(response): $(topdir)/build/executable.make $(depsdir)/.stamp
184 endif
185 $(makefrag): $(topdir)/build/executable.make $(depsdir)/.stamp
186
187 doc-update-local:
188         @:
189
190 # Need to be here so it comes after the definition of DEP_DIRS/DEP_LIBS
191 gen-deps:
192         @echo "$(DEPS_TARGET_DIR): $(DEP_DIRS) $(DEP_LIBS)" >> $(DEPS_FILE)