PageRenderTime 2864ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/xen/Makefile

https://gitlab.com/martyros/xen
Makefile | 718 lines | 459 code | 134 blank | 125 comment | 23 complexity | a8b3eb38698eeedfc3c6083574ebf501 MD5 | raw file
  1. # $(lastword,) for GNU Make older than 3.81
  2. lastword = $(word $(words $(1)),$(1))
  3. this-makefile := $(call lastword,$(MAKEFILE_LIST))
  4. # This is the correct place to edit the build version.
  5. # All other places this is stored (eg. compile.h) should be autogenerated.
  6. export XEN_VERSION = 4
  7. export XEN_SUBVERSION = 17
  8. export XEN_EXTRAVERSION ?= -unstable$(XEN_VENDORVERSION)
  9. export XEN_FULLVERSION = $(XEN_VERSION).$(XEN_SUBVERSION)$(XEN_EXTRAVERSION)
  10. -include xen-version
  11. export XEN_WHOAMI ?= $(USER)
  12. export XEN_DOMAIN ?= $(shell ([ -x /bin/dnsdomainname ] && /bin/dnsdomainname) || ([ -x /bin/domainname ] && /bin/domainname || echo [unknown]))
  13. export XEN_BUILD_DATE ?= $(shell LC_ALL=C date)
  14. export XEN_BUILD_TIME ?= $(shell LC_ALL=C date +%T)
  15. export XEN_BUILD_HOST ?= $(shell hostname)
  16. # Best effort attempt to find a python interpreter, defaulting to Python 3 if
  17. # available. Fall back to just `python` if `which` is nowhere to be found.
  18. PYTHON_INTERPRETER := $(word 1,$(shell which python3 python python2 2>/dev/null) python)
  19. export PYTHON ?= $(PYTHON_INTERPRETER)
  20. export CHECKPOLICY ?= checkpolicy
  21. $(if $(filter __%, $(MAKECMDGOALS)), \
  22. $(error targets prefixed with '__' are only for internal use))
  23. # That's our default target when none is given on the command line
  24. PHONY := __all
  25. __all:
  26. # Do not use make's built-in rules and variables
  27. MAKEFLAGS += -rR
  28. EFI_MOUNTPOINT ?= $(BOOT_DIR)/efi
  29. ARCH=$(XEN_TARGET_ARCH)
  30. SRCARCH=$(shell echo $(ARCH) | \
  31. sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g' \
  32. -e s'/riscv.*/riscv/g')
  33. export ARCH SRCARCH
  34. # Allow someone to change their config file
  35. export KCONFIG_CONFIG ?= .config
  36. export CC CXX LD NM OBJCOPY OBJDUMP ADDR2LINE
  37. export TARGET := xen
  38. .PHONY: dist
  39. dist: install
  40. ifneq ($(root-make-done),y)
  41. # section to run before calling Rules.mk, but only once.
  42. ifneq ($(origin crash_debug),undefined)
  43. $(error "You must use e.g. 'make menuconfig' to enable/disable crash_debug now.")
  44. endif
  45. ifeq ($(origin debug),command line)
  46. $(warning "You must use e.g. 'make menuconfig' to enable/disable debug now.")
  47. endif
  48. ifneq ($(origin frame_pointer),undefined)
  49. $(error "You must use e.g. 'make menuconfig' to enable/disable frame_pointer now.")
  50. endif
  51. ifneq ($(origin kexec),undefined)
  52. $(error "You must use e.g. 'make menuconfig' to enable/disable kexec now.")
  53. endif
  54. ifneq ($(origin lock_profile),undefined)
  55. $(error "You must use e.g. 'make menuconfig' to enable/disable lock_profile now.")
  56. endif
  57. ifneq ($(origin perfc),undefined)
  58. $(error "You must use e.g. 'make menuconfig' to enable/disable perfc now.")
  59. endif
  60. ifneq ($(origin verbose),undefined)
  61. $(error "You must use e.g. 'make menuconfig' to enable/disable verbose now.")
  62. endif
  63. # Beautify output
  64. # ---------------------------------------------------------------------------
  65. #
  66. # Normally, we echo the whole command before executing it. By making
  67. # that echo $($(quiet)$(cmd)), we now have the possibility to set
  68. # $(quiet) to choose other forms of output instead, e.g.
  69. #
  70. # quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
  71. # cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
  72. #
  73. # If $(quiet) is empty, the whole command will be printed.
  74. # If it is set to "quiet_", only the short version will be printed.
  75. # If it is set to "silent_", nothing will be printed at all, since
  76. # the variable $(silent_cmd_cc_o_c) doesn't exist.
  77. #
  78. # A simple variant is to prefix commands with $(Q) - that's useful
  79. # for commands that shall be hidden in non-verbose mode.
  80. #
  81. # $(Q)ln $@ :<
  82. #
  83. # If KBUILD_VERBOSE equals 0 then the above command will be hidden.
  84. # If KBUILD_VERBOSE equals 1 then the above command is displayed.
  85. #
  86. # To put more focus on warnings, be less verbose as default
  87. # Use 'make V=1' to see the full commands
  88. ifeq ("$(origin V)", "command line")
  89. KBUILD_VERBOSE := $(V)
  90. endif
  91. ifndef KBUILD_VERBOSE
  92. KBUILD_VERBOSE := 0
  93. endif
  94. ifeq ($(KBUILD_VERBOSE),1)
  95. quiet :=
  96. Q :=
  97. else
  98. quiet := quiet_
  99. Q := @
  100. endif
  101. # If the user is running make -s (silent mode), suppress echoing of
  102. # commands
  103. ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
  104. quiet := silent_
  105. endif
  106. export quiet Q KBUILD_VERBOSE
  107. # $(realpath,) for GNU Make older than 3.81
  108. realpath = $(wildcard $(foreach file,$(1),$(shell cd -P $(dir $(file)) && echo "$$PWD/$(notdir $(file))")))
  109. ifeq ("$(origin O)", "command line")
  110. KBUILD_OUTPUT := $(O)
  111. endif
  112. ifneq ($(KBUILD_OUTPUT),)
  113. # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
  114. # expand a shell special character '~'. We use a somewhat tedious way here.
  115. abs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
  116. $(if $(abs_objtree),, \
  117. $(error failed to create output directory "$(KBUILD_OUTPUT)"))
  118. # $(realpath ...) resolves symlinks
  119. abs_objtree := $(call realpath,$(abs_objtree))
  120. else
  121. abs_objtree := $(CURDIR)
  122. endif
  123. ifeq ($(abs_objtree),$(CURDIR))
  124. # Suppress "Entering directory ..." unless we are changing the work directory.
  125. MAKEFLAGS += --no-print-directory
  126. else
  127. need-sub-make := 1
  128. endif
  129. abs_srctree := $(call realpath,$(dir $(this-makefile)))
  130. ifneq ($(words $(subst :, ,$(abs_srctree))), 1)
  131. $(error source directory cannot contain spaces or colons)
  132. endif
  133. ifneq ($(abs_srctree),$(abs_objtree))
  134. # Look for make include files relative to root of kernel src
  135. #
  136. # This does not become effective immediately because MAKEFLAGS is re-parsed
  137. # once after the Makefile is read. We need to invoke sub-make.
  138. MAKEFLAGS += --include-dir=$(abs_srctree)
  139. need-sub-make := 1
  140. endif
  141. export abs_srctree abs_objtree
  142. export root-make-done := y
  143. ifeq ($(need-sub-make),1)
  144. PHONY += $(MAKECMDGOALS) __sub-make
  145. $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
  146. @:
  147. # Invoke a second make in the output directory, passing relevant variables
  148. __sub-make:
  149. $(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
  150. endif # need-sub-make
  151. endif # root-make-done
  152. # We process the rest of the Makefile if this is the final invocation of make
  153. ifeq ($(need-sub-make),)
  154. ifeq ($(abs_srctree),$(abs_objtree))
  155. # building in the source tree
  156. srctree := .
  157. building_out_of_srctree :=
  158. else
  159. ifeq ($(abs_srctree)/,$(dir $(abs_objtree)))
  160. # building in a subdirectory of the source tree
  161. srctree := ..
  162. else
  163. srctree := $(abs_srctree)
  164. endif
  165. building_out_of_srctree := 1
  166. endif
  167. objtree := .
  168. VPATH := $(srctree)
  169. export building_out_of_srctree srctree objtree VPATH
  170. export XEN_ROOT := $(abs_srctree)/..
  171. # To make sure we do not include .config for any of the *config targets
  172. # catch them early, and hand them over to tools/kconfig/Makefile
  173. clean-targets := %clean
  174. no-dot-config-targets := $(clean-targets) \
  175. uninstall debug cloc \
  176. cscope TAGS tags gtags \
  177. xenversion
  178. config-build := n
  179. need-config := y
  180. ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
  181. ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
  182. need-config := n
  183. endif
  184. endif
  185. ifneq ($(filter %config,$(MAKECMDGOALS)),)
  186. config-build := y
  187. endif
  188. include scripts/Kbuild.include
  189. # Don't break if the build process wasn't called from the top level
  190. # we need XEN_TARGET_ARCH to generate the proper config
  191. include $(XEN_ROOT)/Config.mk
  192. # Set ARCH/SUBARCH appropriately.
  193. export TARGET_SUBARCH := $(XEN_TARGET_ARCH)
  194. export TARGET_ARCH := $(shell echo $(XEN_TARGET_ARCH) | \
  195. sed -e 's/x86.*/x86/' -e s'/arm\(32\|64\)/arm/g' \
  196. -e s'/riscv.*/riscv/g')
  197. export CONFIG_SHELL := $(SHELL)
  198. export YACC = $(if $(BISON),$(BISON),bison)
  199. export LEX = $(if $(FLEX),$(FLEX),flex)
  200. # Default file for 'make defconfig'.
  201. export KBUILD_DEFCONFIG := $(ARCH)_defconfig
  202. # Copy CFLAGS generated by "Config.mk" so they can be reused later without
  203. # reparsing Config.mk by e.g. arch/x86/boot/.
  204. export XEN_TREEWIDE_CFLAGS := $(CFLAGS)
  205. # CLANG_FLAGS needs to be calculated before calling Kconfig
  206. ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
  207. CLANG_FLAGS :=
  208. ifeq ($(TARGET_ARCH),x86)
  209. # The tests to select whether the integrated assembler is usable need to happen
  210. # before testing any assembler features, or else the result of the tests would
  211. # be stale if the integrated assembler is not used.
  212. # Older clang's built-in assembler doesn't understand .skip with labels:
  213. # https://bugs.llvm.org/show_bug.cgi?id=27369
  214. t1 = $(call as-insn,$(CC),".L0: .L1: .skip (.L1 - .L0)",,-no-integrated-as)
  215. # Check whether clang asm()-s support .include.
  216. t2 = $(call as-insn,$(CC) -I$(srctree)/arch/x86/include,".include \"asm/asm-defns.h\"",,-no-integrated-as)
  217. # Check whether clang keeps .macro-s between asm()-s:
  218. # https://bugs.llvm.org/show_bug.cgi?id=36110
  219. t3 = $(call as-insn,$(CC),".macro FOO;.endm"$(close); asm volatile $(open)".macro FOO;.endm",-no-integrated-as)
  220. CLANG_FLAGS += $(call or,$(t1),$(t2),$(t3))
  221. endif
  222. CLANG_FLAGS += -Werror=unknown-warning-option
  223. CFLAGS += $(CLANG_FLAGS)
  224. export CLANG_FLAGS
  225. endif
  226. export XEN_HAS_CHECKPOLICY := $(call success,$(CHECKPOLICY) -h 2>&1 | grep -q xen)
  227. # ===========================================================================
  228. # Rules shared between *config targets and build targets
  229. PHONY += tools_fixdep
  230. tools_fixdep:
  231. $(Q)$(MAKE) $(build)=tools tools/fixdep
  232. PHONY += outputmakefile
  233. # Before starting out-of-tree build, make sure the source tree is clean.
  234. # outputmakefile generates a Makefile in the output directory, if using a
  235. # separate output directory. This allows convenient use of make in the
  236. # output directory.
  237. # At the same time when output Makefile generated, generate .gitignore to
  238. # ignore whole output directory
  239. quiet_cmd_makefile = GEN Makefile
  240. cmd_makefile = { \
  241. echo "\# Automatically generated by $(srctree)/Makefile: don't edit"; \
  242. echo "include $(srctree)/Makefile"; \
  243. } > Makefile
  244. outputmakefile:
  245. $(Q)ln -fsn $(srctree) source
  246. ifdef building_out_of_srctree
  247. $(Q)if [ -f $(srctree)/.config -o \
  248. -d $(srctree)/include/config -o \
  249. -d $(srctree)/include/generated ]; then \
  250. echo >&2 "***"; \
  251. echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin XEN_TARGET_ARCH)), XEN_TARGET_ARCH=$(XEN_TARGET_ARCH)) distclean'"; \
  252. echo >&2 "*** in $(abs_srctree)";\
  253. echo >&2 "***"; \
  254. false; \
  255. fi
  256. $(call cmd,makefile)
  257. $(Q)test -e .gitignore || \
  258. { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
  259. endif
  260. ifeq ($(config-build),y)
  261. # ===========================================================================
  262. # *config targets only - make sure prerequisites are updated, and descend
  263. # in tools/kconfig to make the *config target
  264. # Create a file for KCONFIG_ALLCONFIG which depends on the environment.
  265. # This will be use by kconfig targets allyesconfig/allmodconfig/allnoconfig/randconfig
  266. filechk_kconfig_allconfig = \
  267. $(if $(findstring n,$(XEN_HAS_CHECKPOLICY)), echo 'CONFIG_XSM_FLASK_POLICY=n';) \
  268. $(if $(KCONFIG_ALLCONFIG), cat $(KCONFIG_ALLCONFIG);) \
  269. :
  270. .allconfig.tmp: FORCE
  271. set -e; { $(call filechk_kconfig_allconfig); } > $@
  272. config: tools_fixdep outputmakefile FORCE
  273. $(Q)$(MAKE) $(build)=tools/kconfig $@
  274. # Config.mk tries to include .config file, don't try to remake it
  275. %/.config: ;
  276. %config: .allconfig.tmp tools_fixdep outputmakefile FORCE
  277. $(Q)$(MAKE) $(build)=tools/kconfig KCONFIG_ALLCONFIG=$< $@
  278. else # !config-build
  279. ifeq ($(need-config),y)
  280. -include include/config/auto.conf
  281. # Read in dependencies to all Kconfig* files, make sure to run syncconfig if
  282. # changes are detected.
  283. -include include/config/auto.conf.cmd
  284. # Allow people to just run `make` as before and not force them to configure
  285. # Only run defconfig if $(KCONFIG_CONFIG) is missing
  286. $(KCONFIG_CONFIG): tools_fixdep
  287. $(if $(wildcard $@), , $(Q)$(MAKE) $(build)=tools/kconfig defconfig)
  288. # The actual configuration files used during the build are stored in
  289. # include/generated/ and include/config/. Update them if .config is newer than
  290. # include/config/auto.conf (which mirrors .config).
  291. #
  292. # This exploits the 'multi-target pattern rule' trick.
  293. # The syncconfig should be executed only once to make all the targets.
  294. include/config/%.conf include/config/%.conf.cmd: $(KCONFIG_CONFIG)
  295. $(Q)$(MAKE) $(build)=tools/kconfig syncconfig
  296. ifeq ($(CONFIG_DEBUG),y)
  297. CFLAGS += -O1
  298. else
  299. CFLAGS += -O2
  300. endif
  301. ifeq ($(CONFIG_FRAME_POINTER),y)
  302. CFLAGS += -fno-omit-frame-pointer
  303. else
  304. CFLAGS += -fomit-frame-pointer
  305. endif
  306. CFLAGS-$(CONFIG_CC_SPLIT_SECTIONS) += -ffunction-sections -fdata-sections
  307. CFLAGS += -nostdinc -fno-builtin -fno-common
  308. CFLAGS += -Werror -Wredundant-decls -Wno-pointer-arith
  309. $(call cc-option-add,CFLAGS,CC,-Wvla)
  310. CFLAGS += -pipe -D__XEN__ -include $(srctree)/include/xen/config.h
  311. CFLAGS-$(CONFIG_DEBUG_INFO) += -g
  312. ifneq ($(CONFIG_CC_IS_CLANG),y)
  313. # Clang doesn't understand this command line argument, and doesn't appear to
  314. # have a suitable alternative. The resulting compiled binary does function,
  315. # but has an excessively large symbol table.
  316. CFLAGS += -Wa,--strip-local-absolute
  317. endif
  318. AFLAGS += -D__ASSEMBLY__
  319. $(call cc-option-add,AFLAGS,CC,-Wa$(comma)--noexecstack)
  320. LDFLAGS-$(call ld-option,--warn-rwx-segments) += --no-warn-rwx-segments
  321. CFLAGS += $(CFLAGS-y)
  322. # allow extra CFLAGS externally via EXTRA_CFLAGS_XEN_CORE
  323. CFLAGS += $(EXTRA_CFLAGS_XEN_CORE)
  324. # Most CFLAGS are safe for assembly files:
  325. # -std=gnu{89,99} gets confused by #-prefixed end-of-line comments
  326. # -flto makes no sense and annoys clang
  327. AFLAGS += $(filter-out -std=gnu% -flto,$(CFLAGS)) $(AFLAGS-y)
  328. # LDFLAGS are only passed directly to $(LD)
  329. LDFLAGS += $(LDFLAGS_DIRECT) $(LDFLAGS-y)
  330. ifeq ($(CONFIG_UBSAN),y)
  331. CFLAGS_UBSAN := -fsanitize=undefined
  332. else
  333. CFLAGS_UBSAN :=
  334. endif
  335. ifeq ($(CONFIG_LTO),y)
  336. CFLAGS += -flto
  337. LDFLAGS-$(CONFIG_CC_IS_CLANG) += -plugin LLVMgold.so
  338. endif
  339. ifdef building_out_of_srctree
  340. CFLAGS += -I$(objtree)/include
  341. CFLAGS += -I$(objtree)/arch/$(TARGET_ARCH)/include
  342. endif
  343. CFLAGS += -I$(srctree)/include
  344. CFLAGS += -I$(srctree)/arch/$(TARGET_ARCH)/include
  345. # Note that link order matters!
  346. ALL_OBJS-y := common/built_in.o
  347. ALL_OBJS-y += drivers/built_in.o
  348. ALL_OBJS-y += lib/built_in.o
  349. ALL_OBJS-y += xsm/built_in.o
  350. ALL_OBJS-y += arch/$(TARGET_ARCH)/built_in.o
  351. ALL_OBJS-$(CONFIG_CRYPTO) += crypto/built_in.o
  352. ALL_LIBS-y := lib/lib.a
  353. include $(srctree)/arch/$(TARGET_ARCH)/arch.mk
  354. # define new variables to avoid the ones defined in Config.mk
  355. export XEN_CFLAGS := $(CFLAGS)
  356. export XEN_AFLAGS := $(AFLAGS)
  357. export XEN_LDFLAGS := $(LDFLAGS)
  358. export CFLAGS_UBSAN
  359. endif # need-config
  360. __all: build
  361. main-targets := build install uninstall clean distclean MAP cppcheck cppcheck-html
  362. .PHONY: $(main-targets)
  363. ifneq ($(XEN_TARGET_ARCH),x86_32)
  364. $(main-targets): %: _% ;
  365. else
  366. $(main-targets):
  367. echo "*** Xen x86/32 target no longer supported!"
  368. endif
  369. .PHONY: _build
  370. _build: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
  371. .PHONY: _install
  372. _install: D=$(DESTDIR)
  373. _install: T=$(notdir $(TARGET))
  374. _install: Z=$(CONFIG_XEN_INSTALL_SUFFIX)
  375. _install: $(TARGET)$(CONFIG_XEN_INSTALL_SUFFIX)
  376. [ -d $(D)$(BOOT_DIR) ] || $(INSTALL_DIR) $(D)$(BOOT_DIR)
  377. $(INSTALL_DATA) $(TARGET)$(Z) $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION)$(Z)
  378. ln -f -s $(T)-$(XEN_FULLVERSION)$(Z) $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION)$(Z)
  379. ln -f -s $(T)-$(XEN_FULLVERSION)$(Z) $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION)$(Z)
  380. ln -f -s $(T)-$(XEN_FULLVERSION)$(Z) $(D)$(BOOT_DIR)/$(T)$(Z)
  381. [ -d "$(D)$(DEBUG_DIR)" ] || $(INSTALL_DIR) $(D)$(DEBUG_DIR)
  382. $(INSTALL_DATA) $(TARGET)-syms $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION)
  383. $(INSTALL_DATA) $(TARGET)-syms.map $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION).map
  384. $(INSTALL_DATA) $(KCONFIG_CONFIG) $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION).config
  385. if [ -r $(TARGET).efi -a -n '$(EFI_DIR)' ]; then \
  386. [ -d $(D)$(EFI_DIR) ] || $(INSTALL_DIR) $(D)$(EFI_DIR); \
  387. $(INSTALL_DATA) $(TARGET).efi $(D)$(EFI_DIR)/$(T)-$(XEN_FULLVERSION).efi; \
  388. if [ -e $(TARGET).efi.map ]; then \
  389. $(INSTALL_DATA) $(TARGET).efi.map $(D)$(DEBUG_DIR)/$(T)-$(XEN_FULLVERSION).efi.map; \
  390. fi; \
  391. ln -sf $(T)-$(XEN_FULLVERSION).efi $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION).efi; \
  392. ln -sf $(T)-$(XEN_FULLVERSION).efi $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).efi; \
  393. ln -sf $(T)-$(XEN_FULLVERSION).efi $(D)$(EFI_DIR)/$(T).efi; \
  394. if [ -n '$(EFI_MOUNTPOINT)' -a -n '$(EFI_VENDOR)' ]; then \
  395. $(INSTALL_DATA) $(TARGET).efi $(D)$(EFI_MOUNTPOINT)/efi/$(EFI_VENDOR)/$(T)-$(XEN_FULLVERSION).efi; \
  396. elif [ "$(D)" = "$(patsubst $(shell cd $(XEN_ROOT) && pwd)/%,%,$(D))" ]; then \
  397. echo 'EFI installation only partially done (EFI_VENDOR not set)' >&2; \
  398. fi; \
  399. fi
  400. .PHONY: tests
  401. tests:
  402. $(Q)$(MAKE) $(build)=test
  403. .PHONY: install-tests
  404. install-tests:
  405. $(Q)$(MAKE) $(build)=test install
  406. .PHONY: _uninstall
  407. _uninstall: D=$(DESTDIR)
  408. _uninstall: T=$(notdir $(TARGET))
  409. _uninstall: Z=$(CONFIG_XEN_INSTALL_SUFFIX)
  410. _uninstall:
  411. rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION).config
  412. rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_FULLVERSION)$(Z)
  413. rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION)$(Z)
  414. rm -f $(D)$(BOOT_DIR)/$(T)-$(XEN_VERSION)$(Z)
  415. rm -f $(D)$(BOOT_DIR)/$(T)$(Z)
  416. rm -f $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION)
  417. rm -f $(D)$(DEBUG_DIR)/$(T)-syms-$(XEN_FULLVERSION).map
  418. rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_FULLVERSION).efi
  419. rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).$(XEN_SUBVERSION).efi
  420. rm -f $(D)$(DEBUG_DIR)/$(T)-$(XEN_FULLVERSION).efi.map
  421. rm -f $(D)$(EFI_DIR)/$(T)-$(XEN_VERSION).efi
  422. rm -f $(D)$(EFI_DIR)/$(T).efi
  423. if [ -n '$(EFI_MOUNTPOINT)' -a -n '$(EFI_VENDOR)' ]; then \
  424. rm -f $(D)$(EFI_MOUNTPOINT)/efi/$(EFI_VENDOR)/$(T)-$(XEN_FULLVERSION).efi; \
  425. fi
  426. .PHONY: _debug
  427. _debug:
  428. $(OBJDUMP) -D -S $(TARGET)-syms > $(TARGET).s
  429. .PHONY: _clean
  430. _clean:
  431. $(Q)$(MAKE) $(clean)=tools
  432. $(Q)$(MAKE) $(clean)=include
  433. $(Q)$(MAKE) $(clean)=common
  434. $(Q)$(MAKE) $(clean)=drivers
  435. $(Q)$(MAKE) $(clean)=lib
  436. $(Q)$(MAKE) $(clean)=xsm
  437. $(Q)$(MAKE) $(clean)=crypto
  438. $(Q)$(MAKE) $(clean)=arch/arm
  439. $(Q)$(MAKE) $(clean)=arch/riscv
  440. $(Q)$(MAKE) $(clean)=arch/x86
  441. $(Q)$(MAKE) $(clean)=test
  442. $(Q)$(MAKE) $(clean)=tools/kconfig
  443. find . \( -name "*.o" -o -name ".*.d" -o -name ".*.d2" \
  444. -o -name ".*.o.tmp" -o -name "*~" -o -name "core" \
  445. -o -name '*.lex.c' -o -name '*.tab.[ch]' -o -name '*.c.cppcheck' \
  446. -o -name "*.gcno" -o -name ".*.cmd" -o -name "lib.a" \) -exec rm -f {} \;
  447. rm -f include/asm $(TARGET) $(TARGET).gz $(TARGET).efi $(TARGET).efi.map $(TARGET)-syms $(TARGET)-syms.map
  448. rm -f asm-offsets.s arch/*/include/asm/asm-offsets.h
  449. rm -f .banner .allconfig.tmp include/xen/compile.h
  450. rm -f xen-cppcheck.xml
  451. .PHONY: _distclean
  452. _distclean: clean
  453. rm -f tags TAGS cscope.files cscope.in.out cscope.out cscope.po.out GTAGS GPATH GRTAGS GSYMS .config source
  454. rm -rf $(CPPCHECK_HTMLREPORT_OUTDIR)
  455. $(TARGET).gz: $(TARGET)
  456. gzip -n -f -9 < $< > $@.new
  457. mv $@.new $@
  458. $(TARGET): outputmakefile FORCE
  459. $(Q)$(MAKE) $(build)=tools
  460. $(Q)$(MAKE) $(build)=. include/xen/compile.h
  461. $(Q)$(MAKE) $(build)=include all
  462. $(Q)$(MAKE) $(build)=arch/$(TARGET_ARCH) include
  463. $(Q)$(MAKE) $(build)=. arch/$(TARGET_ARCH)/include/asm/asm-offsets.h
  464. $(Q)$(MAKE) $(build)=. MKRELOC=$(MKRELOC) 'ALL_OBJS=$(ALL_OBJS-y)' 'ALL_LIBS=$(ALL_LIBS-y)' $@
  465. SUBDIRS = xsm arch/$(TARGET_ARCH) common drivers lib test
  466. define all_sources
  467. ( find include -type f -name '*.h' -print; \
  468. find $(SUBDIRS) -type f -name '*.[chS]' -print )
  469. endef
  470. define set_exuberant_flags
  471. exuberant_flags=`$1 --version 2>/dev/null | (grep -iq exuberant && \
  472. echo "-I __initdata,__exitdata,__acquires,__releases \
  473. -I EXPORT_SYMBOL \
  474. --extra=+f --c-kinds=+px") || true`
  475. endef
  476. .PHONY: xenversion
  477. xenversion:
  478. @echo $(XEN_FULLVERSION)
  479. .PHONY: TAGS
  480. TAGS:
  481. set -e; rm -f TAGS; \
  482. $(call set_exuberant_flags,etags); \
  483. $(all_sources) | xargs etags $$exuberant_flags -a
  484. .PHONY: tags
  485. tags:
  486. set -e; rm -f tags; \
  487. $(call set_exuberant_flags,ctags); \
  488. $(all_sources) | xargs ctags $$exuberant_flags -a
  489. .PHONY: gtags
  490. gtags:
  491. set -e; rm -f GTAGS GSYMS GPATH GRTAGS
  492. $(all_sources) | gtags -f -
  493. .PHONY: cscope
  494. cscope:
  495. $(all_sources) > cscope.files
  496. cscope -k -b -q
  497. .PHONY: _MAP
  498. _MAP: $(TARGET)
  499. $(NM) -n $(TARGET)-syms | grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' > System.map
  500. %.o %.i %.s: %.c tools_fixdep FORCE
  501. $(Q)$(MAKE) $(build)=$(*D) $(*D)/$(@F)
  502. %.o %.s: %.S tools_fixdep FORCE
  503. $(Q)$(MAKE) $(build)=$(*D) $(*D)/$(@F)
  504. %/: tools_fixdep FORCE
  505. $(Q)$(MAKE) $(build)=$* need-builtin=1
  506. .PHONY: cloc
  507. cloc:
  508. find . -name tools -prune -o -name '*.o.cmd' -print | while read f; do \
  509. for sf in $$(grep -o "[a-zA-Z0-9_/-]*\.[cS]" $$f); do \
  510. test -f "$$sf" && echo "$$sf"; \
  511. done; \
  512. done | cloc --list-file=-
  513. # What cppcheck command to use.
  514. # To get proper results, it is recommended to build cppcheck manually from the
  515. # latest source and use CPPCHECK to give the full path to the built version.
  516. CPPCHECK ?= cppcheck
  517. # What cppcheck-htmlreport to use.
  518. # If you give the full path to a self compiled cppcheck, this should be set
  519. # to the full path to cppcheck-html in the htmlreport directory of cppcheck.
  520. # On recent distribution, this is available in the standard path.
  521. CPPCHECK_HTMLREPORT ?= cppcheck-htmlreport
  522. # By default we generate the report in cppcheck-htmlreport directory in the
  523. # build directory. This can be changed by giving a directory in this variable.
  524. CPPCHECK_HTMLREPORT_OUTDIR ?= cppcheck-htmlreport
  525. # Compile flags to pass to cppcheck:
  526. # - include directories and defines Xen Makefile is passing (from CFLAGS)
  527. # - include config.h as this is passed directly to the compiler.
  528. # - define CPPCHECK as we use to disable or enable some specific part of the
  529. # code to solve some cppcheck issues.
  530. # - explicitely enable some cppcheck checks as we do not want to use "all"
  531. # which includes unusedFunction which gives wrong positives as we check file
  532. # per file.
  533. #
  534. # Compiler defines are in compiler-def.h which is included in config.h
  535. #
  536. CPPCHECKFLAGS := -DCPPCHECK --max-ctu-depth=10 \
  537. --enable=style,information,missingInclude \
  538. --include=$(srctree)/include/xen/config.h \
  539. -I $(srctree)/xsm/flask/include \
  540. -I $(srctree)/include/xen/libfdt \
  541. $(filter -D% -I%,$(CFLAGS))
  542. # We need to find all C files (as we are not checking assembly files) so
  543. # we find all generated .o files which have a .c corresponding file.
  544. CPPCHECKFILES := $(wildcard $(patsubst $(objtree)/%.o,$(srctree)/%.c, \
  545. $(filter-out $(objtree)/tools/%, \
  546. $(shell find $(objtree) -name "*.o"))))
  547. quiet_cmd_cppcheck_xml = CPPCHECK $(patsubst $(srctree)/%,%,$<)
  548. cmd_cppcheck_xml = $(CPPCHECK) -v -q --xml $(CPPCHECKFLAGS) \
  549. --output-file=$@ $<
  550. quiet_cmd_merge_cppcheck_reports = CPPCHECK-MERGE $@
  551. cmd_merge_cppcheck_reports = $(srctree)/tools/merge_cppcheck_reports.py $^ $@
  552. quiet_cmd_cppcheck_html = CPPCHECK-HTML $<
  553. cmd_cppcheck_html = $(CPPCHECK_HTMLREPORT) --file=$< --source-dir=$(srctree) \
  554. --report-dir=$(CPPCHECK_HTMLREPORT_OUTDIR) --title=Xen
  555. PHONY += _cppcheck _cppcheck-html cppcheck-version
  556. _cppcheck-html: xen-cppcheck.xml
  557. $(call if_changed,cppcheck_html)
  558. _cppcheck: xen-cppcheck.xml
  559. xen-cppcheck.xml: $(patsubst $(srctree)/%.c,$(objtree)/%.c.cppcheck,$(CPPCHECKFILES))
  560. ifeq ($(CPPCHECKFILES),)
  561. $(error Please build Xen before running cppcheck)
  562. endif
  563. $(call if_changed,merge_cppcheck_reports)
  564. $(objtree)/%.c.cppcheck: $(srctree)/%.c $(objtree)/include/generated/autoconf.h $(objtree)/include/generated/compiler-def.h | cppcheck-version
  565. $(call if_changed,cppcheck_xml)
  566. cppcheck-version:
  567. $(Q)if ! which $(CPPCHECK) > /dev/null 2>&1; then \
  568. echo "Cannot find cppcheck executable: $(CPPCHECK)"; \
  569. exit 1; \
  570. fi
  571. $(Q)if [ "$$($(CPPCHECK) --version | awk '{print ($$2 < 2.7)}')" -eq 1 ]; then \
  572. echo "Please upgrade your cppcheck to version 2.7 or greater"; \
  573. exit 1; \
  574. fi
  575. # Put this in generated headers this way it is cleaned by include/Makefile
  576. $(objtree)/include/generated/compiler-def.h:
  577. $(Q)$(CC) -dM -E -o $@ - < /dev/null
  578. endif #config-build
  579. endif # need-sub-make
  580. PHONY += FORCE
  581. FORCE:
  582. # Declare the contents of the PHONY variable as phony. We keep that
  583. # information in a variable so we can use it in if_changed and friends.
  584. .PHONY: $(PHONY)