Makefile 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. #
  2. # SPDX-License-Identifier: BSD-2-Clause
  3. #
  4. # Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. #
  6. # Authors:
  7. # Anup Patel <anup.patel@wdc.com>
  8. #
  9. # Select Make Options:
  10. # o Do not use make's built-in rules
  11. # o Do not print "Entering directory ...";
  12. MAKEFLAGS += -r --no-print-directory
  13. # Readlink -f requires GNU readlink
  14. ifeq ($(shell uname -s),Darwin)
  15. READLINK ?= greadlink
  16. else
  17. READLINK ?= readlink
  18. endif
  19. # Find out source, build, and install directories
  20. src_dir=$(CURDIR)
  21. ifdef O
  22. build_dir=$(shell $(READLINK) -f $(O))
  23. else
  24. build_dir=$(CURDIR)/build
  25. endif
  26. ifeq ($(build_dir),$(CURDIR))
  27. $(error Build directory is same as source directory.)
  28. endif
  29. install_root_dir_default=$(CURDIR)/install
  30. ifdef I
  31. install_root_dir=$(shell $(READLINK) -f $(I))
  32. else
  33. install_root_dir=$(install_root_dir_default)/usr
  34. endif
  35. ifeq ($(install_root_dir),$(CURDIR))
  36. $(error Install root directory is same as source directory.)
  37. endif
  38. ifeq ($(install_root_dir),$(build_dir))
  39. $(error Install root directory is same as build directory.)
  40. endif
  41. ifdef PLATFORM_DIR
  42. platform_dir_path=$(shell $(READLINK) -f $(PLATFORM_DIR))
  43. ifdef PLATFORM
  44. platform_parent_dir=$(platform_dir_path)
  45. else
  46. PLATFORM=$(shell basename $(platform_dir_path))
  47. platform_parent_dir=$(subst $(PLATFORM),,$(platform_dir_path))
  48. endif
  49. else
  50. platform_parent_dir=$(src_dir)/platform
  51. endif
  52. # Check if verbosity is ON for build process
  53. CMD_PREFIX_DEFAULT := @
  54. ifeq ($(V), 1)
  55. CMD_PREFIX :=
  56. else
  57. CMD_PREFIX := $(CMD_PREFIX_DEFAULT)
  58. endif
  59. # Setup path of directories
  60. export platform_subdir=$(PLATFORM)
  61. export platform_src_dir=$(platform_parent_dir)/$(platform_subdir)
  62. export platform_build_dir=$(build_dir)/platform/$(platform_subdir)
  63. export include_dir=$(CURDIR)/include
  64. export libsbi_dir=$(CURDIR)/lib/sbi
  65. export libsbiutils_dir=$(CURDIR)/lib/utils
  66. export firmware_dir=$(CURDIR)/firmware
  67. # Find library version
  68. OPENSBI_VERSION_MAJOR=`grep "define OPENSBI_VERSION_MAJOR" $(include_dir)/sbi/sbi_version.h | sed 's/.*MAJOR.*\([0-9][0-9]*\)/\1/'`
  69. OPENSBI_VERSION_MINOR=`grep "define OPENSBI_VERSION_MINOR" $(include_dir)/sbi/sbi_version.h | sed 's/.*MINOR.*\([0-9][0-9]*\)/\1/'`
  70. OPENSBI_VERSION_GIT=$(shell if [ -d $(src_dir)/.git ]; then git describe 2> /dev/null; fi)
  71. # Setup compilation commands
  72. ifdef CROSS_COMPILE
  73. CC = $(CROSS_COMPILE)gcc
  74. CPP = $(CROSS_COMPILE)cpp
  75. AR = $(CROSS_COMPILE)ar
  76. LD = $(CROSS_COMPILE)ld
  77. OBJCOPY = $(CROSS_COMPILE)objcopy
  78. else
  79. CC ?= gcc
  80. CPP ?= cpp
  81. AR ?= ar
  82. LD ?= ld
  83. OBJCOPY ?= objcopy
  84. endif
  85. AS = $(CC)
  86. DTC = dtc
  87. # Guess the compillers xlen
  88. OPENSBI_CC_XLEN := $(shell TMP=`$(CC) -dumpmachine | sed 's/riscv\([0-9][0-9]\).*/\1/'`; echo $${TMP})
  89. # Setup platform XLEN
  90. ifndef PLATFORM_RISCV_XLEN
  91. ifeq ($(OPENSBI_CC_XLEN), 32)
  92. PLATFORM_RISCV_XLEN = 32
  93. else
  94. PLATFORM_RISCV_XLEN = 64
  95. endif
  96. endif
  97. # Setup list of objects.mk files
  98. ifdef PLATFORM
  99. platform-object-mks=$(shell if [ -d $(platform_src_dir)/ ]; then find $(platform_src_dir) -iname "objects.mk" | sort -r; fi)
  100. endif
  101. libsbi-object-mks=$(shell if [ -d $(libsbi_dir) ]; then find $(libsbi_dir) -iname "objects.mk" | sort -r; fi)
  102. libsbiutils-object-mks=$(shell if [ -d $(libsbiutils_dir) ]; then find $(libsbiutils_dir) -iname "objects.mk" | sort -r; fi)
  103. firmware-object-mks=$(shell if [ -d $(firmware_dir) ]; then find $(firmware_dir) -iname "objects.mk" | sort -r; fi)
  104. # Include platform specifig config.mk
  105. ifdef PLATFORM
  106. include $(platform_src_dir)/config.mk
  107. endif
  108. # Include all object.mk files
  109. ifdef PLATFORM
  110. include $(platform-object-mks)
  111. endif
  112. include $(libsbi-object-mks)
  113. include $(libsbiutils-object-mks)
  114. include $(firmware-object-mks)
  115. # Setup list of objects
  116. libsbi-objs-path-y=$(foreach obj,$(libsbi-objs-y),$(build_dir)/lib/sbi/$(obj))
  117. libsbiutils-objs-path-y=$(foreach obj,$(libsbiutils-objs-y),$(build_dir)/lib/utils/$(obj))
  118. ifdef PLATFORM
  119. platform-objs-path-y=$(foreach obj,$(platform-objs-y),$(platform_build_dir)/$(obj))
  120. firmware-bins-path-y=$(foreach bin,$(firmware-bins-y),$(platform_build_dir)/firmware/$(bin))
  121. endif
  122. firmware-elfs-path-y=$(firmware-bins-path-y:.bin=.elf)
  123. firmware-objs-path-y=$(firmware-bins-path-y:.bin=.o)
  124. # Setup list of deps files for objects
  125. deps-y=$(platform-objs-path-y:.o=.dep)
  126. deps-y+=$(libsbi-objs-path-y:.o=.dep)
  127. deps-y+=$(libsbiutils-objs-path-y:.o=.dep)
  128. deps-y+=$(firmware-objs-path-y:.o=.dep)
  129. # Setup platform ABI, ISA and Code Model
  130. ifndef PLATFORM_RISCV_ABI
  131. ifeq ($(PLATFORM_RISCV_XLEN), 32)
  132. PLATFORM_RISCV_ABI = ilp$(PLATFORM_RISCV_XLEN)
  133. else
  134. PLATFORM_RISCV_ABI = lp$(PLATFORM_RISCV_XLEN)
  135. endif
  136. endif
  137. ifndef PLATFORM_RISCV_ISA
  138. PLATFORM_RISCV_ISA = rv$(PLATFORM_RISCV_XLEN)imafdc
  139. endif
  140. ifndef PLATFORM_RISCV_CODE_MODEL
  141. PLATFORM_RISCV_CODE_MODEL = medany
  142. endif
  143. # Setup install directories
  144. ifdef INSTALL_INCLUDE_PATH
  145. install_include_path=$(INSTALL_INCLUDE_PATH)
  146. else
  147. install_include_path=include
  148. endif
  149. ifdef INSTALL_LIB_PATH
  150. install_lib_path=$(INSTALL_LIB_PATH)
  151. else
  152. ifneq ($(origin INSTALL_LIB_SUBDIR), undefined)
  153. install_lib_subdir=$(INSTALL_LIB_SUBDIR)
  154. else
  155. install_lib_subdir=$(PLATFORM_RISCV_ABI)
  156. endif
  157. install_lib_path=lib$(subst 32,,$(PLATFORM_RISCV_XLEN))/$(install_lib_subdir)
  158. endif
  159. ifdef INSTALL_FIRMWARE_PATH
  160. install_firmware_path=$(INSTALL_FIRMWARE_PATH)
  161. else
  162. install_firmware_path=share/opensbi/$(PLATFORM_RISCV_ABI)
  163. endif
  164. ifdef INSTALL_DOCS_PATH
  165. install_docs_path=$(INSTALL_DOCS_PATH)
  166. else
  167. install_docs_path=share/opensbi/docs
  168. endif
  169. # Setup compilation commands flags
  170. GENFLAGS = -I$(platform_src_dir)/include
  171. GENFLAGS += -I$(include_dir)
  172. ifneq ($(OPENSBI_VERSION_GIT),)
  173. GENFLAGS += -DOPENSBI_VERSION_GIT="\"$(OPENSBI_VERSION_GIT)\""
  174. endif
  175. GENFLAGS += $(libsbiutils-genflags-y)
  176. GENFLAGS += $(platform-genflags-y)
  177. GENFLAGS += $(firmware-genflags-y)
  178. CFLAGS = -g -Wall -Werror -ffreestanding -nostdlib -fno-strict-aliasing -O2
  179. CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
  180. CFLAGS += -mno-save-restore -mstrict-align
  181. CFLAGS += -mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA)
  182. CFLAGS += -mcmodel=$(PLATFORM_RISCV_CODE_MODEL)
  183. CFLAGS += $(GENFLAGS)
  184. CFLAGS += $(platform-cflags-y)
  185. CFLAGS += $(firmware-cflags-y)
  186. CFLAGS += -fno-pie -no-pie
  187. CPPFLAGS += $(GENFLAGS)
  188. CPPFLAGS += $(platform-cppflags-y)
  189. CPPFLAGS += $(firmware-cppflags-y)
  190. ASFLAGS = -g -Wall -nostdlib -D__ASSEMBLY__
  191. ASFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
  192. ASFLAGS += -mno-save-restore -mstrict-align
  193. ASFLAGS += -mabi=$(PLATFORM_RISCV_ABI) -march=$(PLATFORM_RISCV_ISA)
  194. ASFLAGS += -mcmodel=$(PLATFORM_RISCV_CODE_MODEL)
  195. ASFLAGS += $(GENFLAGS)
  196. ASFLAGS += $(platform-asflags-y)
  197. ASFLAGS += $(firmware-asflags-y)
  198. ARFLAGS = rcs
  199. ELFFLAGS += -Wl,--build-id=none -N -static-libgcc -lgcc
  200. ELFFLAGS += $(platform-ldflags-y)
  201. ELFFLAGS += $(firmware-ldflags-y)
  202. MERGEFLAGS += -r
  203. MERGEFLAGS += -b elf$(PLATFORM_RISCV_XLEN)-littleriscv
  204. MERGEFLAGS += -m elf$(PLATFORM_RISCV_XLEN)lriscv
  205. DTSCPPFLAGS = $(CPPFLAGS) -nostdinc -nostdlib -fno-builtin -D__DTS__ -x assembler-with-cpp
  206. # Setup functions for compilation
  207. define dynamic_flags
  208. -I$(shell dirname $(2)) -D__OBJNAME__=$(subst -,_,$(shell basename $(1) .o))
  209. endef
  210. merge_objs = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  211. echo " MERGE $(subst $(build_dir)/,,$(1))"; \
  212. $(LD) $(MERGEFLAGS) $(2) -o $(1)
  213. merge_deps = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  214. echo " MERGE-DEP $(subst $(build_dir)/,,$(1))"; \
  215. cat $(2) > $(1)
  216. copy_file = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  217. echo " COPY $(subst $(build_dir)/,,$(1))"; \
  218. cp -f $(2) $(1)
  219. inst_file = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  220. echo " INSTALL $(subst $(install_root_dir)/,,$(1))"; \
  221. cp -f $(2) $(1)
  222. inst_file_list = $(CMD_PREFIX)if [ ! -z "$(4)" ]; then \
  223. mkdir -p $(1)/$(3); \
  224. for file in $(4) ; do \
  225. rel_file=`echo $$file | sed -e 's@$(2)/$(subst $(install_firmware_path),platform,$(3))@@'`; \
  226. dest_file=$(1)"/"$(3)"/"`echo $$rel_file`; \
  227. dest_dir=`dirname $$dest_file`; \
  228. echo " INSTALL "$(3)"/"`echo $$rel_file`; \
  229. mkdir -p $$dest_dir; \
  230. cp -f $$file $$dest_file; \
  231. done \
  232. fi
  233. inst_header_dir = $(CMD_PREFIX)mkdir -p $(1); \
  234. echo " INSTALL $(subst $(install_root_dir)/,,$(1))"; \
  235. cp -rf $(2) $(1)
  236. compile_cpp = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  237. echo " CPP $(subst $(build_dir)/,,$(1))"; \
  238. $(CPP) $(CPPFLAGS) -x c $(2) | grep -v "\#" > $(1)
  239. compile_cc_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  240. echo " CC-DEP $(subst $(build_dir)/,,$(1))"; \
  241. printf %s `dirname $(1)`/ > $(1) && \
  242. $(CC) $(CFLAGS) $(call dynamic_flags,$(1),$(2)) \
  243. -MM $(2) >> $(1) || rm -f $(1)
  244. compile_cc = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  245. echo " CC $(subst $(build_dir)/,,$(1))"; \
  246. $(CC) $(CFLAGS) $(call dynamic_flags,$(1),$(2)) -c $(2) -o $(1)
  247. compile_as_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  248. echo " AS-DEP $(subst $(build_dir)/,,$(1))"; \
  249. printf %s `dirname $(1)`/ > $(1) && \
  250. $(AS) $(ASFLAGS) $(call dynamic_flags,$(1),$(2)) \
  251. -MM $(2) >> $(1) || rm -f $(1)
  252. compile_as = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  253. echo " AS $(subst $(build_dir)/,,$(1))"; \
  254. $(AS) $(ASFLAGS) $(call dynamic_flags,$(1),$(2)) -c $(2) -o $(1)
  255. compile_elf = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  256. echo " ELF $(subst $(build_dir)/,,$(1))"; \
  257. $(CC) $(CFLAGS) $(3) $(ELFFLAGS) -Wl,-T$(2) -o $(1)
  258. compile_ar = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  259. echo " AR $(subst $(build_dir)/,,$(1))"; \
  260. $(AR) $(ARFLAGS) $(1) $(2)
  261. compile_objcopy = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  262. echo " OBJCOPY $(subst $(build_dir)/,,$(1))"; \
  263. $(OBJCOPY) -S -O binary $(2) $(1)
  264. compile_dts = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  265. echo " DTC $(subst $(build_dir)/,,$(1))"; \
  266. $(CPP) $(DTSCPPFLAGS) $(2) | $(DTC) -O dtb -i `dirname $(2)` -o $(1)
  267. compile_d2c = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  268. echo " D2C $(subst $(build_dir)/,,$(1))"; \
  269. $(if $($(2)-varalign-$(3)),$(eval D2C_ALIGN_BYTES := $($(2)-varalign-$(3))),$(eval D2C_ALIGN_BYTES := $(4))) \
  270. $(if $($(2)-varprefix-$(3)),$(eval D2C_NAME_PREFIX := $($(2)-varprefix-$(3))),$(eval D2C_NAME_PREFIX := $(5))) \
  271. $(if $($(2)-padding-$(3)),$(eval D2C_PADDING_BYTES := $($(2)-padding-$(3))),$(eval D2C_PADDING_BYTES := 0)) \
  272. $(src_dir)/scripts/d2c.sh -i $(6) -a $(D2C_ALIGN_BYTES) -p $(D2C_NAME_PREFIX) -t $(D2C_PADDING_BYTES) > $(1)
  273. compile_gen_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \
  274. echo " GEN-DEP $(subst $(build_dir)/,,$(1))"; \
  275. echo "$(1:.dep=$(2)): $(3)" >> $(1)
  276. targets-y = $(build_dir)/lib/libsbi.a
  277. targets-y += $(build_dir)/lib/libsbiutils.a
  278. ifdef PLATFORM
  279. targets-y += $(platform_build_dir)/lib/libplatsbi.a
  280. endif
  281. targets-y += $(firmware-bins-path-y)
  282. # Default rule "make" should always be first rule
  283. .PHONY: all
  284. all: $(targets-y)
  285. # Preserve all intermediate files
  286. .SECONDARY:
  287. $(build_dir)/lib/libsbi.a: $(libsbi-objs-path-y)
  288. $(call compile_ar,$@,$^)
  289. $(build_dir)/lib/libsbiutils.a: $(libsbi-objs-path-y) $(libsbiutils-objs-path-y)
  290. $(call compile_ar,$@,$^)
  291. $(platform_build_dir)/lib/libplatsbi.a: $(libsbi-objs-path-y) $(libsbiutils-objs-path-y) $(platform-objs-path-y)
  292. $(call compile_ar,$@,$^)
  293. $(build_dir)/%.dep: $(src_dir)/%.c
  294. $(call compile_cc_dep,$@,$<)
  295. $(build_dir)/%.o: $(src_dir)/%.c
  296. $(call compile_cc,$@,$<)
  297. $(build_dir)/%.dep: $(src_dir)/%.S
  298. $(call compile_as_dep,$@,$<)
  299. $(build_dir)/%.o: $(src_dir)/%.S
  300. $(call compile_as,$@,$<)
  301. $(platform_build_dir)/%.bin: $(platform_build_dir)/%.elf
  302. $(call compile_objcopy,$@,$<)
  303. $(platform_build_dir)/%.elf: $(platform_build_dir)/%.o $(platform_build_dir)/%.elf.ld $(platform_build_dir)/lib/libplatsbi.a
  304. $(call compile_elf,$@,$@.ld,$< $(platform_build_dir)/lib/libplatsbi.a)
  305. $(platform_build_dir)/%.ld: $(src_dir)/%.ldS
  306. $(call compile_cpp,$@,$<)
  307. $(platform_build_dir)/%.dep: $(platform_src_dir)/%.c
  308. $(call compile_cc_dep,$@,$<)
  309. $(platform_build_dir)/%.o: $(platform_src_dir)/%.c
  310. $(call compile_cc,$@,$<)
  311. $(platform_build_dir)/%.o: $(platform_build_dir)/%.c
  312. $(call compile_cc,$@,$<)
  313. $(platform_build_dir)/%.dep: $(platform_src_dir)/%.S
  314. $(call compile_as_dep,$@,$<)
  315. $(platform_build_dir)/%.o: $(platform_src_dir)/%.S
  316. $(call compile_as,$@,$<)
  317. $(platform_build_dir)/%.dep: $(platform_src_dir)/%.dts
  318. $(call compile_gen_dep,$@,.dtb,$<)
  319. $(call compile_gen_dep,$@,.c,$(@:.dep=.dtb))
  320. $(call compile_gen_dep,$@,.o,$(@:.dep=.c))
  321. $(platform_build_dir)/%.c: $(platform_build_dir)/%.dtb
  322. $(call compile_d2c,$@,platform,$(subst .dtb,.o,$(subst /,-,$(subst $(platform_build_dir)/,,$<))),16,dt,$<)
  323. $(platform_build_dir)/%.dtb: $(platform_src_dir)/%.dts
  324. $(call compile_dts,$@,$<)
  325. $(platform_build_dir)/%.dep: $(src_dir)/%.c
  326. $(call compile_cc_dep,$@,$<)
  327. $(platform_build_dir)/%.o: $(src_dir)/%.c
  328. $(call compile_cc,$@,$<)
  329. $(platform_build_dir)/%.dep: $(src_dir)/%.S
  330. $(call compile_as_dep,$@,$<)
  331. $(platform_build_dir)/%.o: $(src_dir)/%.S
  332. $(call compile_as,$@,$<)
  333. # Rule for "make docs"
  334. $(build_dir)/docs/latex/refman.pdf: $(build_dir)/docs/latex/refman.tex
  335. $(CMD_PREFIX)mkdir -p $(build_dir)/docs
  336. $(CMD_PREFIX)$(MAKE) -C $(build_dir)/docs/latex
  337. $(build_dir)/docs/latex/refman.tex: $(build_dir)/docs/doxygen.cfg
  338. $(CMD_PREFIX)mkdir -p $(build_dir)/docs
  339. $(CMD_PREFIX)doxygen $(build_dir)/docs/doxygen.cfg
  340. $(build_dir)/docs/doxygen.cfg: $(src_dir)/docs/doxygen.cfg
  341. $(CMD_PREFIX)mkdir -p $(build_dir)/docs
  342. $(CMD_PREFIX)cat docs/doxygen.cfg | sed -e "s#@@SRC_DIR@@#$(src_dir)#" -e "s#@@BUILD_DIR@@#$(build_dir)#" -e "s#@@OPENSBI_MAJOR@@#$(OPENSBI_VERSION_MAJOR)#" -e "s#@@OPENSBI_MINOR@@#$(OPENSBI_VERSION_MINOR)#" > $(build_dir)/docs/doxygen.cfg
  343. .PHONY: docs
  344. docs: $(build_dir)/docs/latex/refman.pdf
  345. # Dependency files should only be included after default Makefile rules
  346. # They should not be included for any "xxxconfig" or "xxxclean" rule
  347. all-deps-1 = $(if $(findstring config,$(MAKECMDGOALS)),,$(deps-y))
  348. all-deps-2 = $(if $(findstring clean,$(MAKECMDGOALS)),,$(all-deps-1))
  349. -include $(all-deps-2)
  350. # Include external dependency of firmwares after default Makefile rules
  351. include $(src_dir)/firmware/external_deps.mk
  352. # Convenient "make run" command for emulated platforms
  353. .PHONY: run
  354. run: all
  355. ifneq ($(platform-runcmd),)
  356. $(platform-runcmd) $(RUN_ARGS)
  357. else
  358. ifdef PLATFORM
  359. @echo "Platform $(PLATFORM) doesn't specify a run command"
  360. @false
  361. else
  362. @echo Run command only available when targeting a platform
  363. @false
  364. endif
  365. endif
  366. install_targets-y = install_libsbi
  367. install_targets-y += install_libsbiutils
  368. ifdef PLATFORM
  369. install_targets-y += install_libplatsbi
  370. install_targets-y += install_firmwares
  371. endif
  372. # Rule for "make install"
  373. .PHONY: install
  374. install: $(install_targets-y)
  375. .PHONY: install_libsbi
  376. install_libsbi: $(build_dir)/lib/libsbi.a
  377. $(call inst_header_dir,$(install_root_dir)/$(install_include_path),$(include_dir)/sbi)
  378. $(call inst_file,$(install_root_dir)/$(install_lib_path)/libsbi.a,$(build_dir)/lib/libsbi.a)
  379. .PHONY: install_libsbiutils
  380. install_libsbiutils: $(build_dir)/lib/libsbiutils.a
  381. $(call inst_header_dir,$(install_root_dir)/$(install_include_path),$(include_dir)/sbi_utils)
  382. $(call inst_file,$(install_root_dir)/$(install_lib_path)/libsbiutils.a,$(build_dir)/lib/libsbiutils.a)
  383. .PHONY: install_libplatsbi
  384. install_libplatsbi: $(platform_build_dir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a $(build_dir)/lib/libsbiutils.a
  385. $(call inst_file,$(install_root_dir)/$(install_lib_path)/opensbi/$(platform_subdir)/lib/libplatsbi.a,$(platform_build_dir)/lib/libplatsbi.a)
  386. .PHONY: install_firmwares
  387. install_firmwares: $(platform_build_dir)/lib/libplatsbi.a $(build_dir)/lib/libsbi.a $(build_dir)/lib/libsbiutils.a $(firmware-bins-path-y)
  388. $(call inst_file_list,$(install_root_dir),$(build_dir),$(install_firmware_path)/$(platform_subdir)/firmware,$(firmware-elfs-path-y))
  389. $(call inst_file_list,$(install_root_dir),$(build_dir),$(install_firmware_path)/$(platform_subdir)/firmware,$(firmware-bins-path-y))
  390. .PHONY: install_docs
  391. install_docs: $(build_dir)/docs/latex/refman.pdf
  392. $(call inst_file,$(install_root_dir)/$(install_docs_path)/refman.pdf,$(build_dir)/docs/latex/refman.pdf)
  393. # Rule for "make clean"
  394. .PHONY: clean
  395. clean:
  396. $(CMD_PREFIX)mkdir -p $(build_dir)
  397. $(if $(V), @echo " RM $(build_dir)/*.o")
  398. $(CMD_PREFIX)find $(build_dir) -type f -name "*.o" -exec rm -rf {} +
  399. $(if $(V), @echo " RM $(build_dir)/*.a")
  400. $(CMD_PREFIX)find $(build_dir) -type f -name "*.a" -exec rm -rf {} +
  401. $(if $(V), @echo " RM $(build_dir)/*.elf")
  402. $(CMD_PREFIX)find $(build_dir) -type f -name "*.elf" -exec rm -rf {} +
  403. $(if $(V), @echo " RM $(build_dir)/*.bin")
  404. $(CMD_PREFIX)find $(build_dir) -type f -name "*.bin" -exec rm -rf {} +
  405. $(if $(V), @echo " RM $(build_dir)/*.dtb")
  406. $(CMD_PREFIX)find $(build_dir) -type f -name "*.dtb" -exec rm -rf {} +
  407. # Rule for "make distclean"
  408. .PHONY: distclean
  409. distclean: clean
  410. $(CMD_PREFIX)mkdir -p $(build_dir)
  411. $(if $(V), @echo " RM $(build_dir)/*.dep")
  412. $(CMD_PREFIX)find $(build_dir) -type f -name "*.dep" -exec rm -rf {} +
  413. ifeq ($(build_dir),$(CURDIR)/build)
  414. $(if $(V), @echo " RM $(build_dir)")
  415. $(CMD_PREFIX)rm -rf $(build_dir)
  416. endif
  417. ifeq ($(install_root_dir),$(install_root_dir_default)/usr)
  418. $(if $(V), @echo " RM $(install_root_dir_default)")
  419. $(CMD_PREFIX)rm -rf $(install_root_dir_default)
  420. endif