1XEN_ROOT = $(CURDIR)/../../.. 2 3all: xen-shim 4 5.PHONY: FORCE 6FORCE: 7 8D=xen-root 9 10# Minimun set of files / directories go get Xen to build 11LINK_DIRS=config xen 12LINK_FILES=Config.mk 13 14DEP_DIRS=$(foreach i, $(LINK_DIRS), $(XEN_ROOT)/$(i)) 15DEP_FILES=$(foreach i, $(LINK_FILES), $(XEN_ROOT)/$(i)) 16 17# Exclude some intermediate files and final build products 18LINK_EXCLUDES := '*.[isoa]' '*.bin' '*.chk' '*.lnk' '*.gz' '.*' 19LINK_EXCLUDES += lexer.lex.? parser.tab.? conf 20LINK_EXCLUDES += asm-offsets.h asm-macros.h compile.h '*-autogen.h' 21LINK_EXCLUDES += mkelf32 mkreloc symbols config_data.S xen.lds efi.lds 22LINK_EXCLUDES += '*.map' xen xen.gz xen.efi xen-syms check.efi 23 24# To exclude full subtrees or individual files of not sufficiently specific 25# names, regular expressions are used: 26LINK_EXCLUDE_PATHS := xen/include/compat/.* 27LINK_EXCLUDE_PATHS += xen/include/config/.* 28LINK_EXCLUDE_PATHS += xen/include/generated/.* 29LINK_EXCLUDE_PATHS += xen/arch/x86/boot/reloc[.]S 30LINK_EXCLUDE_PATHS += xen/arch/x86/boot/cmdline[.]S 31 32# This is all a giant mess and doesn't really work. 33# 34# The correct solution is to fix Xen to be able to do out-of-tree builds. 35# 36# Until that happens, we set up a linkfarm by iterating over the xen/ tree, 37# linking source files. This is repeated each time we enter this directory, 38# which poses a problem for a two-step "make; make install" build process. 39# 40# Any time the list of files to link changes, we relink all files, then 41# distclean to take out not-easy-to-classify intermediate files. This is to 42# support easy development of the shim, but has a side effect of clobbering 43# the already-built shim. 44# 45# $(LINK_EXCLUDES) and $(LINK_EXCLUDE_DIRS) should be set such that a parallel 46# build of shim and xen/ doesn't cause a subsequent `make install` to decide to 47# regenerate the linkfarm. This means that all intermediate and final build 48# artefacts must be excluded. 49linkfarm.stamp: $(DEP_DIRS) $(DEP_FILES) FORCE 50 mkdir -p $(D) 51 rm -f linkfarm.stamp.tmp 52 set -e; \ 53 $(foreach d, $(LINK_DIRS), \ 54 (mkdir -p $(D)/$(d); \ 55 cd $(D)/$(d); \ 56 find $(XEN_ROOT)/$(d)/ -type d |\ 57 sed 's,^$(XEN_ROOT)/$(d)/,,g' | xargs mkdir -p .);) \ 58 $(foreach d, $(LINK_DIRS), \ 59 (cd $(XEN_ROOT); \ 60 find $(d) ! -type l -type f $(addprefix ! -name ,$(LINK_EXCLUDES)) \ 61 | grep -v $(patsubst %,-e '^%$$',$(LINK_EXCLUDE_PATHS))) \ 62 >> linkfarm.stamp.tmp ; ) \ 63 $(foreach f, $(LINK_FILES), \ 64 echo $(f) >> linkfarm.stamp.tmp ;) 65 cmp -s linkfarm.stamp.tmp linkfarm.stamp && \ 66 rm linkfarm.stamp.tmp || { \ 67 cat linkfarm.stamp.tmp | while read f; \ 68 do rm -f "$(D)/$$f"; ln -s "$(XEN_ROOT)/$$f" "$(D)/$$f"; done; \ 69 mv linkfarm.stamp.tmp linkfarm.stamp; \ 70 } 71 72# Copy enough of the tree to build the shim hypervisor 73$(D): linkfarm.stamp 74 $(MAKE) -C $(D)/xen distclean 75 76$(D)/xen/.config: $(D) 77 $(MAKE) -C $(@D) KBUILD_DEFCONFIG=pvshim_defconfig defconfig 78 79xen-shim: $(D)/xen/.config 80 $(MAKE) -C $(<D) build 81 ln -sf $(D)/xen/xen $@ 82 ln -sf $(D)/xen/xen-syms $@-syms 83 84.PHONY: distclean clean 85distclean clean: 86 rm -f xen-shim xen-shim-syms *.old 87 rm -rf $(D) 88 rm -f linkfarm.stamp* 89