2007-09-02 Zoltan Varga <vargaz@gmail.com>
[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 makefrag = $(depsdir)/$(PROFILE)_$(base_prog).makefrag
26 pdb = $(patsubst %.exe,%.pdb,$(PROGRAM))
27 mdb = $(patsubst %.exe,%.mdb,$(PROGRAM))
28 executable_CLEAN_FILES += $(makefrag) $(pdb) $(mdb)
29
30 all-local: $(PROGRAM) $(PROGRAM_config)
31
32 install-local: all-local
33 test-local: all-local
34 uninstall-local:
35
36 ifdef NO_INSTALL
37 install-local uninstall-local:
38         @:
39 else
40
41 ifndef PROGRAM_INSTALL_DIR
42 PROGRAM_INSTALL_DIR = $(mono_libdir)/mono/$(FRAMEWORK_VERSION)
43 endif
44
45 install-local: $(PROGRAM) $(PROGRAM_config)
46         $(MKINSTALLDIRS) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
47         $(INSTALL_BIN) $(PROGRAM) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
48         test ! -f $(PROGRAM).mdb || $(INSTALL_BIN) $(PROGRAM).mdb $(DESTDIR)$(PROGRAM_INSTALL_DIR)
49 ifdef PROGRAM_config
50         $(INSTALL_DATA) $(PROGRAM_config) $(DESTDIR)$(PROGRAM_INSTALL_DIR)
51 endif
52
53 uninstall-local:
54         -rm -f $(DESTDIR)$(PROGRAM_INSTALL_DIR)/$(base_prog) $(DESTDIR)$(PROGRAM_INSTALL_DIR)/$(base_prog).mdb $(DESTDIR)$(PROGRAM_INSTALL_DIR)/$(base_prog).config
55 endif
56
57 clean-local:
58         -rm -f $(executable_CLEAN_FILES) $(CLEAN_FILES)
59
60 test-local:
61         @:
62 run-test-local:
63         @:
64 run-test-ondotnet-local:
65         @:
66
67 DISTFILES = $(sourcefile) $(base_prog_config) $(EXTRA_DISTFILES)
68
69 dist-local: dist-default
70         for f in `cat $(sourcefile)` ; do \
71           case $$f in \
72           ../*) : ;; \
73           *) dest=`dirname $$f` ; \
74              case $$subs in *" $$dest "*) : ;; *) subs=" $$dest$$subs" ; $(MKINSTALLDIRS) $(distdir)/$$dest ;; esac ; \
75              cp -p $$f $(distdir)/$$dest || exit 1 ;; \
76           esac ; done ; \
77         for d in . $$subs ; do \
78           case $$d in .) : ;; *) test ! -f $$d/ChangeLog || cp -p $$d/ChangeLog $(distdir)/$$d ;; esac ; done
79
80 ifndef PROGRAM_COMPILE
81 PROGRAM_COMPILE = $(CSCOMPILE)
82 endif
83
84 ifdef prog_dir
85 $(prog_dir)/.stamp:
86         $(MKINSTALLDIRS) $(@D)
87         touch $@
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         mv $(base_prog) $(PROGRAM)
94         test ! -f $(base_prog).mdb || mv $(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