1# This is the correct place to edit the build version.
2# All other places this is stored (eg. compile.h) should be autogenerated.
3export XEN_VERSION       = 4
4export XEN_SUBVERSION    = 10
5export XEN_EXTRAVERSION ?= .1-pre$(XEN_VENDORVERSION)
6export XEN_FULLVERSION   = $(XEN_VERSION).$(XEN_SUBVERSION)$(XEN_EXTRAVERSION)
7-include xen-version
8
9export XEN_WHOAMI	?= $(USER)
10export XEN_DOMAIN	?= $(shell ([ -x /bin/dnsdomainname ] && /bin/dnsdomainname) || ([ -x /bin/domainname ] && /bin/domainname || echo [unknown]))
11export XEN_BUILD_DATE	?= $(shell LC_ALL=C date)
12export XEN_BUILD_TIME	?= $(shell LC_ALL=C date +%T)
13export XEN_BUILD_HOST	?= $(shell hostname)
14export XEN_CONFIG_EXPERT ?= n
15
16export BASEDIR := $(CURDIR)
17export XEN_ROOT := $(BASEDIR)/..
18
19# Do not use make's built-in rules and variables
20MAKEFLAGS += -rR
21
22EFI_MOUNTPOINT ?= $(BOOT_DIR)/efi
23
24ARCH=$(XEN_TARGET_ARCH)
25SRCARCH=$(shell echo $(ARCH) | sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g')
26
27# Don't break if the build process wasn't called from the top level
28# we need XEN_TARGET_ARCH to generate the proper config
29include $(XEN_ROOT)/Config.mk
30
31# Allow someone to change their config file
32export KCONFIG_CONFIG ?= .config
33
34.PHONY: default
35default: build
36
37.PHONY: dist
38dist: install
39
40build install build-shim:: include/config/auto.conf
41
42.PHONY: build install uninstall clean distclean cscope TAGS tags MAP gtags tests install-shim build-shim
43build install uninstall debug clean distclean cscope TAGS tags MAP gtags tests install-shim build-shim::
44ifneq ($(XEN_TARGET_ARCH),x86_32)
45	$(MAKE) -f Rules.mk _$@
46else
47	echo "*** Xen x86/32 target no longer supported!"
48endif
49
50.PHONY: _build
51_build: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
52
53.PHONY: _install
54_install: D=$(DESTDIR)
55_install: T=$(notdir $(TARGET))
56_install: Z=$(CONFIG_XEN_INSTALL_SUFFIX)
57_install: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
58	[ -d $(D)$(BOOT_DIR) ] || $(INSTALL_DIR) $(D)$(BOOT_DIR)
59	$(INSTALL_DATA) $(TARGET)$(Z) $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION)$(Z)
60	ln -f -s $(T)-$(XEN_FULLVERSION)$(Z) $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION)$(Z)
61	ln -f -s $(T)-$(XEN_FULLVERSION)$(Z) $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION)$(Z)
62	ln -f -s $(T)-$(XEN_FULLVERSION)$(Z) $(D)$(BOOT_DIR)/$(T)$(Z)
63	[ -d "$(D)$(DEBUG_DIR)" ] || $(INSTALL_DIR) $(D)$(DEBUG_DIR)
64	$(INSTALL_DATA) $(TARGET)-syms $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION)
65	$(INSTALL_DATA) $(TARGET)-syms.map $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION).map
66	$(INSTALL_DATA) $(KCONFIG_CONFIG) $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION).config
67	if [ -r $(TARGET).efi -a -n '$(EFI_DIR)' ]; then \
68		[ -d $(D)$(EFI_DIR) ] || $(INSTALL_DIR) $(D)$(EFI_DIR); \
69		$(INSTALL_DATA) $(TARGET).efi $(D)$(EFI_DIR)/$(T)-$(XEN_FULLVERSION).efi; \
70		if [ -e $(TARGET).efi.map ]; then \
71			$(INSTALL_DATA) $(TARGET).efi.map $(D)$(DEBUG_DIR)/$(T)-$(XEN_FULLVERSION).efi.map; \
72		fi; \
73		ln -sf $(T)-$(XEN_FULLVERSION).efi $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION).efi; \
74		ln -sf $(T)-$(XEN_FULLVERSION).efi $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).efi; \
75		ln -sf $(T)-$(XEN_FULLVERSION).efi $(D)$(EFI_DIR)/$(T).efi; \
76		if [ -n '$(EFI_MOUNTPOINT)' -a -n '$(EFI_VENDOR)' ]; then \
77			$(INSTALL_DATA) $(TARGET).efi $(D)$(EFI_MOUNTPOINT)/efi/$(EFI_VENDOR)/$(T)-$(XEN_FULLVERSION).efi; \
78		elif [ "$(D)" = "$(patsubst $(shell cd $(XEN_ROOT) && pwd)/%,%,$(D))" ]; then \
79			echo 'EFI installation only partially done (EFI_VENDOR not set)' >&2; \
80		fi; \
81	fi
82
83.PHONY: _build-shim
84_build-shim: $(TARGET)-shim
85
86.PHONY: _install-shim
87_install-shim: build-shim
88	$(INSTALL_DATA) $(TARGET)-shim $(DESTDIR)
89
90.PHONY: _tests
91_tests:
92	$(MAKE) -f $(BASEDIR)/Rules.mk -C test tests
93
94.PHONY: _uninstall
95_uninstall: D=$(DESTDIR)
96_uninstall: T=$(notdir $(TARGET))
97_uninstall: Z=$(CONFIG_XEN_INSTALL_SUFFIX)
98_uninstall:
99	rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION).config
100	rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION)$(Z)
101	rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION)$(Z)
102	rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION)$(Z)
103	rm -f $(D)$(BOOT_DIR)/$(T)$(Z)
104	rm -f $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION)
105	rm -f $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION).map
106	rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_FULLVERSION).efi
107	rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION).efi
108	rm -f $(D)$(DEBUG_DIR)/$(T)-$(XEN_FULLVERSION).efi.map
109	rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).efi
110	rm -f $(D)$(EFI_DIR)/$(T).efi
111	rm -f $(D)$(EFI_MOUNTPOINT)/efi/$(EFI_VENDOR)/$(T)-$(XEN_FULLVERSION).efi
112
113.PHONY: _debug
114_debug:
115	$(OBJDUMP) -D -S $(TARGET)-syms > $(TARGET).s
116
117.PHONY: _clean
118_clean: delete-unfresh-files
119	$(MAKE) -C tools clean
120	$(MAKE) -f $(BASEDIR)/Rules.mk -C include clean
121	$(MAKE) -f $(BASEDIR)/Rules.mk -C common clean
122	$(MAKE) -f $(BASEDIR)/Rules.mk -C drivers clean
123	$(MAKE) -f $(BASEDIR)/Rules.mk -C xsm clean
124	$(MAKE) -f $(BASEDIR)/Rules.mk -C crypto clean
125	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/arm clean
126	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/x86 clean
127	$(MAKE) -f $(BASEDIR)/Rules.mk -C test clean
128	$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) clean
129	find . \( -name "*.o" -o -name ".*.d" -o -name "*.gcno" \) -exec rm -f {} \;
130	rm -f include/asm $(TARGET) $(TARGET).gz $(TARGET).efi $(TARGET).efi.map $(TARGET)-syms $(TARGET)-syms.map *~ core
131	rm -f include/asm-*/asm-offsets.h
132	rm -f .banner
133
134.PHONY: _distclean
135_distclean: clean
136	rm -f tags TAGS cscope.files cscope.in.out cscope.out cscope.po.out GTAGS GPATH GRTAGS GSYMS .config
137
138$(TARGET).gz: $(TARGET)
139	gzip -n -f -9 < $< > $@.new
140	mv $@.new $@
141
142$(TARGET): delete-unfresh-files
143	$(MAKE) -C tools
144	$(MAKE) -f $(BASEDIR)/Rules.mk include/xen/compile.h
145	[ -e include/asm ] || ln -sf asm-$(TARGET_ARCH) include/asm
146	[ -e arch/$(TARGET_ARCH)/efi ] && for f in boot.c runtime.c compat.c efi.h;\
147		do ln -nsf ../../../common/efi/$$f arch/$(TARGET_ARCH)/efi/; done;\
148		true
149	$(MAKE) -f $(BASEDIR)/Rules.mk -C include
150	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) asm-offsets.s
151	$(MAKE) -f $(BASEDIR)/Rules.mk include/asm-$(TARGET_ARCH)/asm-offsets.h
152	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) $(TARGET)
153
154$(TARGET)-shim: $(TARGET)
155	$(MAKE) -f $(BASEDIR)/Rules.mk -C arch/$(TARGET_ARCH) $(TARGET)-shim
156
157# drivers/char/console.o contains static banner/compile info. Blow it away.
158# Don't refresh these files during e.g., 'sudo make install'
159.PHONY: delete-unfresh-files
160delete-unfresh-files:
161	@if [ ! -r include/xen/compile.h -o -O include/xen/compile.h ]; then \
162		rm -f include/xen/compile.h; \
163	fi
164
165.banner: Makefile
166	@if which figlet >/dev/null 2>&1 ; then \
167		echo " Xen $(XEN_FULLVERSION)" | figlet -f tools/xen.flf > $@.tmp; \
168	else \
169		echo " Xen $(XEN_FULLVERSION)" > $@.tmp; \
170	fi
171	@mv -f $@.tmp $@
172
173# compile.h contains dynamic build info. Rebuilt on every 'make' invocation.
174include/xen/compile.h: include/xen/compile.h.in .banner
175	@sed -e 's/@@date@@/$(XEN_BUILD_DATE)/g' \
176	    -e 's/@@time@@/$(XEN_BUILD_TIME)/g' \
177	    -e 's/@@whoami@@/$(XEN_WHOAMI)/g' \
178	    -e 's/@@domain@@/$(XEN_DOMAIN)/g' \
179	    -e 's/@@hostname@@/$(XEN_BUILD_HOST)/g' \
180	    -e 's!@@compiler@@!$(shell $(CC) $(CFLAGS) --version 2>&1 | head -1)!g' \
181	    -e 's/@@version@@/$(XEN_VERSION)/g' \
182	    -e 's/@@subversion@@/$(XEN_SUBVERSION)/g' \
183	    -e 's/@@extraversion@@/$(XEN_EXTRAVERSION)/g' \
184	    -e 's!@@changeset@@!$(shell tools/scmversion $(XEN_ROOT) || echo "unavailable")!g' \
185	    < include/xen/compile.h.in > $@.new
186	@cat .banner
187	@$(PYTHON) tools/fig-to-oct.py < .banner >> $@.new
188	@mv -f $@.new $@
189
190include/asm-$(TARGET_ARCH)/asm-offsets.h: arch/$(TARGET_ARCH)/asm-offsets.s
191	@(set -e; \
192	  echo "/*"; \
193	  echo " * DO NOT MODIFY."; \
194	  echo " *"; \
195	  echo " * This file was auto-generated from $<"; \
196	  echo " *"; \
197	  echo " */"; \
198	  echo ""; \
199	  echo "#ifndef __ASM_OFFSETS_H__"; \
200	  echo "#define __ASM_OFFSETS_H__"; \
201	  echo ""; \
202	  sed -rne "/==>/{s:.*==>(.*)<==.*:\1:; s: [\$$#]: :; p;}"; \
203	  echo ""; \
204	  echo "#endif") <$< >$@
205
206SUBDIRS = xsm arch/$(TARGET_ARCH) common drivers test
207define all_sources
208    ( find include/asm-$(TARGET_ARCH) -name '*.h' -print; \
209      find include -name 'asm-*' -prune -o -name '*.h' -print; \
210      find $(SUBDIRS) -name '*.[chS]' -print )
211endef
212
213define set_exuberant_flags
214    exuberant_flags=`$1 --version 2>/dev/null | (grep -iq exuberant && \
215	echo "-I __initdata,__exitdata,__acquires,__releases \
216	    -I EXPORT_SYMBOL \
217	    --extra=+f --c-kinds=+px") || true`
218endef
219
220.PHONY: xenversion
221xenversion:
222	@echo $(XEN_FULLVERSION)
223
224.PHONY: _TAGS
225_TAGS:
226	set -e; rm -f TAGS; \
227	$(call set_exuberant_flags,etags); \
228	$(all_sources) | xargs etags $$exuberant_flags -a
229
230.PHONY: _tags
231_tags:
232	set -e; rm -f tags; \
233	$(call set_exuberant_flags,ctags); \
234	$(all_sources) | xargs ctags $$exuberant_flags -a
235
236.PHONY: _gtags
237_gtags:
238	set -e; rm -f GTAGS GSYMS GPATH GRTAGS
239	$(all_sources) | gtags -f -
240
241.PHONY: _cscope
242_cscope:
243	$(all_sources) > cscope.files
244	cscope -k -b -q
245
246.PHONY: _MAP
247_MAP:
248	$(NM) -n $(TARGET)-syms | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' > System.map
249
250.PHONY: FORCE
251FORCE:
252
253%.o %.i %.s: %.c FORCE
254	$(MAKE) -f $(BASEDIR)/Rules.mk -C $(*D) $(@F)
255
256%.o %.s: %.S FORCE
257	$(MAKE) -f $(BASEDIR)/Rules.mk -C $(*D) $(@F)
258
259%/: FORCE
260	$(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in.o built_in_bin.o
261
262kconfig := silentoldconfig oldconfig config menuconfig defconfig \
263	nconfig xconfig gconfig savedefconfig listnewconfig olddefconfig \
264	randconfig
265.PHONY: $(kconfig)
266$(kconfig):
267	$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) HOSTCC="$(HOSTCC)" HOSTCXX="$(HOSTCXX)" $@
268
269include/config/%.conf: include/config/auto.conf.cmd $(KCONFIG_CONFIG)
270	$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) HOSTCC="$(HOSTCC)" HOSTCXX="$(HOSTCXX)" silentoldconfig
271
272# Allow people to just run `make` as before and not force them to configure
273$(KCONFIG_CONFIG):
274	$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) HOSTCC="$(HOSTCC)" HOSTCXX="$(HOSTCXX)" defconfig
275
276# Break the dependency chain for the first run
277include/config/auto.conf.cmd: ;
278
279-include $(BASEDIR)/include/config/auto.conf.cmd
280