Merge pull request #2545 from ermshiperete/Xamarin-24974
[mono.git] / mcs / build / executable.make
index f3113385a5ccf9c7cd8eeb44b56a3e17ce7246c2..29ba89909e6d397d8d2012a09999717af7561526 100644 (file)
@@ -3,37 +3,46 @@
 # The rules for building a program.
 
 base_prog = $(notdir $(PROGRAM))
-prog_dir := $(filter-out . ./, $(dir $(PROGRAM)))
-sourcefile = $(base_prog).sources
+ifndef sourcefile
+sourcefile := $(base_prog).sources
+endif
 base_prog_config := $(wildcard $(base_prog).config.$(PROFILE))
 ifndef base_prog_config
 base_prog_config := $(wildcard $(base_prog).config)
 endif
-ifdef base_prog_config
-PROGRAM_config := $(PROGRAM).config
-endif
-
-executable_CLEAN_FILES = *.exe $(PROGRAM) $(PROGRAM).mdb $(BUILT_SOURCES)
 
 ifeq (cat,$(PLATFORM_CHANGE_SEPARATOR_CMD))
 response = $(sourcefile)
 else
-response = $(depsdir)/$(base_prog).response
+response = $(depsdir)/$(sourcefile).response
 executable_CLEAN_FILES += $(response)
 endif
 
-ifdef KEEP_OUTPUT_FILE_COPY
-       COPY_CMD = cp
+ifndef the_libdir
+the_libdir = $(topdir)/class/lib/$(PROFILE)/
+ifdef PROGRAM_USE_INTERMEDIATE_FILE
+build_libdir = $(the_libdir)tmp/
 else
-       COPY_CMD = mv
+build_libdir = $(the_libdir)
+endif
+endif
+
+ifdef base_prog_config
+PROGRAM_config := $(build_libdir)$(PROGRAM).config
 endif
 
+sn = $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/sn.exe
+SN = MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(sn) -q
+
+the_lib = $(the_libdir)$(base_prog)
+build_lib = $(build_libdir)$(base_prog)
+
+executable_CLEAN_FILES += $(the_lib)   $(the_lib).so   $(the_lib).mdb   $(the_lib:.exe=.pdb)
+executable_CLEAN_FILES += $(build_lib) $(build_lib).so $(build_lib).mdb $(build_lib:.exe=.pdb)
+
 makefrag = $(depsdir)/$(PROFILE)_$(base_prog).makefrag
-pdb = $(patsubst %.exe,%.pdb,$(PROGRAM))
-mdb = $(patsubst %.exe,%.mdb,$(PROGRAM))
-executable_CLEAN_FILES += $(makefrag) $(pdb) $(mdb)
 
-all-local: $(PROGRAM) $(PROGRAM_config)
+all-local: $(the_lib) $(PROGRAM_config)
 
 install-local: all-local
 test-local: all-local
@@ -48,20 +57,23 @@ ifndef PROGRAM_INSTALL_DIR
 PROGRAM_INSTALL_DIR = $(mono_libdir)/mono/$(FRAMEWORK_VERSION)
 endif
 
-install-local: $(PROGRAM) $(PROGRAM_config)
+install-local:
        $(MKINSTALLDIRS) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
-       $(INSTALL_BIN) $(PROGRAM) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
-       test ! -f $(PROGRAM).mdb || $(INSTALL_BIN) $(PROGRAM).mdb $(DESTDIR)$(PROGRAM_INSTALL_DIR)
+       $(INSTALL_BIN) $(the_lib) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
+       test ! -f $(the_lib).mdb || $(INSTALL_BIN) $(the_lib).mdb $(DESTDIR)$(PROGRAM_INSTALL_DIR)
 ifdef PROGRAM_config
        $(INSTALL_DATA) $(PROGRAM_config) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
 endif
+ifdef PLATFORM_AOT_SUFFIX
+       test ! -f $(PROGRAM)$(PLATFORM_AOT_SUFFIX) || $(INSTALL_LIB) $(PROGRAM)$(PLATFORM_AOT_SUFFIX) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
+endif
 
 uninstall-local:
        -rm -f $(DESTDIR)$(PROGRAM_INSTALL_DIR)/$(base_prog) $(DESTDIR)$(PROGRAM_INSTALL_DIR)/$(base_prog).mdb $(DESTDIR)$(PROGRAM_INSTALL_DIR)/$(base_prog).config
 endif
 
 clean-local:
-       -rm -f $(executable_CLEAN_FILES) $(CLEAN_FILES)
+       -rm -f $(executable_CLEAN_FILES) $(CLEAN_FILES) $(tests_CLEAN_FILES)
 
 test-local:
        @:
@@ -72,13 +84,24 @@ run-test-ondotnet-local:
 
 DISTFILES = $(sourcefile) $(base_prog_config) $(EXTRA_DISTFILES)
 
+ifdef HAS_NUNIT_TEST
+ASSEMBLY      = $(PROGRAM)
+ASSEMBLY_EXT  = .exe
+the_assembly  = $(PROGRAM)
+include $(topdir)/build/tests.make
+endif
+
+ifdef HAVE_CS_TESTS
+DISTFILES += $(test_sourcefile)
+endif
+
 dist-local: dist-default
        for f in `cat $(sourcefile)` ; do \
          case $$f in \
          ../*) : ;; \
-         *) dest=`dirname $$f` ; \
+         *) dest=`dirname "$$f"` ; \
             case $$subs in *" $$dest "*) : ;; *) subs=" $$dest$$subs" ; $(MKINSTALLDIRS) $(distdir)/$$dest ;; esac ; \
-            cp -p $$f $(distdir)/$$dest || exit 1 ;; \
+            cp -p "$$f" $(distdir)/$$dest || exit 1 ;; \
          esac ; done ; \
        for d in . $$subs ; do \
          case $$d in .) : ;; *) test ! -f $$d/ChangeLog || cp -p $$d/ChangeLog $(distdir)/$$d ;; esac ; done
@@ -87,42 +110,71 @@ ifndef PROGRAM_COMPILE
 PROGRAM_COMPILE = $(CSCOMPILE)
 endif
 
-ifdef prog_dir
-$(prog_dir)/.stamp:
-       $(MKINSTALLDIRS) $(@D)
-       touch $@
+$(the_lib): $(the_libdir)/.stamp
+
+$(build_lib): $(BUILT_SOURCES) $(EXTRA_SOURCES) $(response) $(build_libdir:=/.stamp)
+       $(PROGRAM_COMPILE) $(MCS_REFERENCES) -target:exe -out:$@ $(BUILT_SOURCES) $(EXTRA_SOURCES) @$(response)
+ifdef PROGRAM_SNK
+       $(Q) $(SN) -R $@ $(PROGRAM_SNK)
 endif
 
-$(PROGRAM): $(BUILT_SOURCES) $(EXTRA_SOURCES) $(response) $(prog_dir:=/.stamp)
-       $(PROGRAM_COMPILE) -target:exe -out:$(base_prog) $(BUILT_SOURCES) $(EXTRA_SOURCES) @$(response)
-ifneq ($(base_prog),$(PROGRAM))
-       $(COPY_CMD) $(base_prog) $(PROGRAM)
-       test ! -f $(base_prog).mdb || $(COPY_CMD) $(base_prog).mdb $(PROGRAM).mdb
+ifdef PROGRAM_USE_INTERMEDIATE_FILE
+$(the_lib): $(build_lib)
+       $(Q) cp $(build_lib) $@
+       $(Q) test ! -f $(build_lib).mdb || mv $(build_lib).mdb $@.mdb
+       $(Q) test ! -f $(build_lib:.exe=.pdb) || mv $(build_lib:.exe=.pdb) $(the_lib:.exe=.pdb)
 endif
 
 ifdef PROGRAM_config
 ifneq ($(base_prog_config),$(PROGRAM_config))
 executable_CLEAN_FILES += $(PROGRAM_config)
-$(PROGRAM_config): $(base_prog_config)
+$(PROGRAM_config): $(base_prog_config) $(dir $(PROGRAM_config))/.stamp
        cp $(base_prog_config) $(PROGRAM_config)
 endif
 endif
 
 $(makefrag): $(sourcefile)
-       @echo Creating $@ ...
-       @sed 's,^,$(PROGRAM): ,' $< > $@
+#      @echo Creating $@ ...
+       @sed 's,^,$(build_lib): ,' $< >$@
+       @if test ! -f $(sourcefile).makefrag; then :; else \
+          cat $(sourcefile).makefrag >> $@ ; \
+          echo '$@: $(sourcefile).makefrag' >> $@; \
+          echo '$(sourcefile).makefrag:' >> $@; fi
 
 ifneq ($(response),$(sourcefile))
 $(response): $(sourcefile)
-       @echo Creating $@ ...
-       @( $(PLATFORM_CHANGE_SEPARATOR_CMD) ) <$< >$@
+       @echo Converting $(sourcefile) to $@ ...
+       @cat $(sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
 endif
 
 -include $(makefrag)
 
-all-local: $(makefrag)
+MCS_REFERENCES = $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.dll,$(LIB_REFS))
+MCS_REFERENCES += $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE)/%.exe,$(EXE_REFS))
+
+all-local: $(makefrag) $(extra_targets)
+
+csproj-local:
+       config_file=`basename $(PROGRAM) .exe`-$(PROFILE).input; \
+       echo $(thisdir):$$config_file >> $(topdir)/../msvc/scripts/order; \
+       (echo $(is_boot); \
+       echo $(USE_MCS_FLAGS) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) $(patsubst %,-r:%,$(LIB_REFS)); \
+       echo $(PROGRAM); \
+       echo $(BUILT_SOURCES_cmdline); \
+       echo $(build_lib); \
+       echo $(FRAMEWORK_VERSION); \
+       echo $(PROFILE); \
+       echo $(response)) > $(topdir)/../msvc/scripts/inputs/$$config_file
+
 
 ifneq ($(response),$(sourcefile))
 $(response): $(topdir)/build/executable.make $(depsdir)/.stamp
 endif
 $(makefrag): $(topdir)/build/executable.make $(depsdir)/.stamp
+
+doc-update-local:
+       @:
+
+# Need to be here so it comes after the definition of DEP_DIRS/DEP_LIBS
+gen-deps:
+       @echo "$(DEPS_TARGET_DIR): $(DEP_DIRS) $(DEP_LIBS)" >> $(DEPS_FILE)