* rules.make (%/.stamp): Unify all directory creation targets here.
[mono.git] / mcs / build / executable.make
1 # -*- makefile -*-
2 #
3 # The rules for building a program.
4
5 base_prog = $(notdir $(PROGRAM))
6 prog_dir := $(filter-out . ./, $(dir $(PROGRAM)))
7 sourcefile = $(base_prog).sources
8 base_prog_config := $(wildcard $(base_prog).config.$(PROFILE))
9 ifndef base_prog_config
10 base_prog_config := $(wildcard $(base_prog).config)
11 endif
12 ifdef base_prog_config
13 PROGRAM_config := $(PROGRAM).config
14 endif
15
16 executable_CLEAN_FILES = *.exe $(PROGRAM) $(PROGRAM).mdb $(BUILT_SOURCES)
17
18 ifeq (cat,$(PLATFORM_CHANGE_SEPARATOR_CMD))
19 response = $(sourcefile)
20 else
21 response = $(depsdir)/$(base_prog).response
22 executable_CLEAN_FILES += $(response)
23 endif
24
25 ifdef KEEP_OUTPUT_FILE_COPY
26         COPY_CMD = cp
27 else
28         COPY_CMD = mv
29 endif
30
31 makefrag = $(depsdir)/$(PROFILE)_$(base_prog).makefrag
32 pdb = $(patsubst %.exe,%.pdb,$(PROGRAM))
33 mdb = $(patsubst %.exe,%.mdb,$(PROGRAM))
34 executable_CLEAN_FILES += $(makefrag) $(pdb) $(mdb)
35
36 all-local: $(PROGRAM) $(PROGRAM_config)
37
38 install-local: all-local
39 test-local: all-local
40 uninstall-local:
41
42 ifdef NO_INSTALL
43 install-local uninstall-local:
44         @:
45 else
46
47 ifndef PROGRAM_INSTALL_DIR
48 PROGRAM_INSTALL_DIR = $(mono_libdir)/mono/$(FRAMEWORK_VERSION)
49 endif
50
51 install-local: $(PROGRAM) $(PROGRAM_config)
52         $(MKINSTALLDIRS) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
53         $(INSTALL_BIN) $(PROGRAM) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
54         test ! -f $(PROGRAM).mdb || $(INSTALL_BIN) $(PROGRAM).mdb $(DESTDIR)$(PROGRAM_INSTALL_DIR)
55 ifdef PROGRAM_config
56         $(INSTALL_DATA) $(PROGRAM_config) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
57 endif
58
59 uninstall-local:
60         -rm -f $(DESTDIR)$(PROGRAM_INSTALL_DIR)/$(base_prog) $(DESTDIR)$(PROGRAM_INSTALL_DIR)/$(base_prog).mdb $(DESTDIR)$(PROGRAM_INSTALL_DIR)/$(base_prog).config
61 endif
62
63 clean-local:
64         -rm -f $(executable_CLEAN_FILES) $(CLEAN_FILES)
65
66 test-local:
67         @:
68 run-test-local:
69         @:
70 run-test-ondotnet-local:
71         @:
72
73 DISTFILES = $(sourcefile) $(base_prog_config) $(EXTRA_DISTFILES)
74
75 dist-local: dist-default
76         for f in `cat $(sourcefile)` ; do \
77           case $$f in \
78           ../*) : ;; \
79           *) dest=`dirname $$f` ; \
80              case $$subs in *" $$dest "*) : ;; *) subs=" $$dest$$subs" ; $(MKINSTALLDIRS) $(distdir)/$$dest ;; esac ; \
81              cp -p $$f $(distdir)/$$dest || exit 1 ;; \
82           esac ; done ; \
83         for d in . $$subs ; do \
84           case $$d in .) : ;; *) test ! -f $$d/ChangeLog || cp -p $$d/ChangeLog $(distdir)/$$d ;; esac ; done
85
86 ifndef PROGRAM_COMPILE
87 PROGRAM_COMPILE = $(CSCOMPILE)
88 endif
89
90 $(PROGRAM): $(BUILT_SOURCES) $(EXTRA_SOURCES) $(response) $(prog_dir:=/.stamp)
91         $(PROGRAM_COMPILE) -target:exe -out:$(base_prog) $(BUILT_SOURCES) $(EXTRA_SOURCES) @$(response)
92 ifneq ($(base_prog),$(PROGRAM))
93         $(COPY_CMD) $(base_prog) $(PROGRAM)
94         test ! -f $(base_prog).mdb || $(COPY_CMD) $(base_prog).mdb $(PROGRAM).mdb
95 endif
96
97 ifdef PROGRAM_config
98 ifneq ($(base_prog_config),$(PROGRAM_config))
99 executable_CLEAN_FILES += $(PROGRAM_config)
100 $(PROGRAM_config): $(base_prog_config)
101         cp $(base_prog_config) $(PROGRAM_config)
102 endif
103 endif
104
105 $(makefrag): $(sourcefile)
106         @echo Creating $@ ...
107         @sed 's,^,$(PROGRAM): ,' $< > $@
108
109 ifneq ($(response),$(sourcefile))
110 $(response): $(sourcefile)
111         @echo Creating $@ ...
112         @( $(PLATFORM_CHANGE_SEPARATOR_CMD) ) <$< >$@
113 endif
114
115 -include $(makefrag)
116
117 all-local: $(makefrag)
118
119 ifneq ($(response),$(sourcefile))
120 $(response): $(topdir)/build/executable.make $(depsdir)/.stamp
121 endif
122 $(makefrag): $(topdir)/build/executable.make $(depsdir)/.stamp