1
0

target.mk 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2007-2008 OpenWrt.org
  4. # Copyright (C) 2016 LEDE Project
  5. ifneq ($(__target_inc),1)
  6. __target_inc=1
  7. # default device type
  8. DEVICE_TYPE?=router
  9. # Default packages - the really basic set
  10. DEFAULT_PACKAGES:=\
  11. base-files \
  12. ca-bundle \
  13. dropbear \
  14. fstools \
  15. libc \
  16. libgcc \
  17. libustream-wolfssl \
  18. logd \
  19. mtd \
  20. netifd \
  21. opkg \
  22. uci \
  23. uclient-fetch \
  24. urandom-seed \
  25. urngd
  26. ifneq ($(CONFIG_SELINUX),)
  27. DEFAULT_PACKAGES+=busybox-selinux procd-selinux
  28. else
  29. DEFAULT_PACKAGES+=busybox procd
  30. endif
  31. # include ujail on systems with enough storage
  32. ifeq ($(CONFIG_SMALL_FLASH),)
  33. DEFAULT_PACKAGES+=procd-ujail
  34. endif
  35. # include seccomp ld-preload hooks if kernel supports it
  36. ifneq ($(CONFIG_SECCOMP),)
  37. DEFAULT_PACKAGES+=procd-seccomp
  38. endif
  39. # For the basic set
  40. DEFAULT_PACKAGES.basic:=
  41. # For nas targets
  42. DEFAULT_PACKAGES.nas:=\
  43. block-mount \
  44. fdisk \
  45. lsblk \
  46. mdadm
  47. # For router targets
  48. DEFAULT_PACKAGES.router:=\
  49. dnsmasq \
  50. firewall4 \
  51. nftables \
  52. kmod-nft-offload \
  53. odhcp6c \
  54. odhcpd-ipv6only \
  55. ppp \
  56. ppp-mod-pppoe
  57. ifneq ($(DUMP),)
  58. all: dumpinfo
  59. endif
  60. target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
  61. ifeq ($(DUMP),)
  62. PLATFORM_DIR:=$(firstword $(wildcard $(TOPDIR)/target/linux/feeds/$(BOARD) $(TOPDIR)/target/linux/$(BOARD)))
  63. SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
  64. else
  65. PLATFORM_DIR:=${CURDIR}
  66. ifeq ($(SUBTARGETS),)
  67. SUBTARGETS:=$(strip $(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)))
  68. endif
  69. endif
  70. TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
  71. PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
  72. ifneq ($(TARGET_BUILD),1)
  73. ifndef DUMP
  74. include $(PLATFORM_DIR)/Makefile
  75. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  76. include $(PLATFORM_SUBDIR)/target.mk
  77. endif
  78. endif
  79. else
  80. ifneq ($(SUBTARGET),)
  81. -include ./$(SUBTARGET)/target.mk
  82. endif
  83. endif
  84. # Add device specific packages (here below to allow device type set from subtarget)
  85. DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
  86. filter_packages = $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
  87. extra_packages = $(if $(filter wpad wpad-% nas,$(1)),iwinfo)
  88. define ProfileDefault
  89. NAME:=
  90. PRIORITY:=
  91. PACKAGES:=
  92. endef
  93. ifndef Profile
  94. define Profile
  95. $(eval $(call ProfileDefault))
  96. $(eval $(call Profile/$(1)))
  97. dumpinfo : $(call shexport,Profile/$(1)/Description)
  98. PACKAGES := $(filter-out -%,$(PACKAGES))
  99. DUMPINFO += \
  100. echo "Target-Profile: $(1)"; \
  101. $(if $(PRIORITY), echo "Target-Profile-Priority: $(PRIORITY)"; ) \
  102. echo "Target-Profile-Name: $(NAME)"; \
  103. echo "Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
  104. echo "Target-Profile-Description:"; \
  105. echo "$$$$$$$$$(call shvar,Profile/$(1)/Description)"; \
  106. echo "@@"; \
  107. echo;
  108. endef
  109. endif
  110. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  111. define IncludeProfiles
  112. -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
  113. -include $(sort $(wildcard $(PLATFORM_SUBDIR)/profiles/*.mk))
  114. endef
  115. else
  116. define IncludeProfiles
  117. -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
  118. endef
  119. endif
  120. PROFILE?=$(call qstrip,$(CONFIG_TARGET_PROFILE))
  121. ifeq ($(TARGET_BUILD),1)
  122. ifneq ($(DUMP),)
  123. $(eval $(call IncludeProfiles))
  124. endif
  125. endif
  126. ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
  127. include $(INCLUDE_DIR)/kernel-version.mk
  128. endif
  129. GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic
  130. GENERIC_BACKPORT_DIR := $(GENERIC_PLATFORM_DIR)/backport$(if $(wildcard $(GENERIC_PLATFORM_DIR)/backport-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
  131. GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/pending$(if $(wildcard $(GENERIC_PLATFORM_DIR)/pending-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
  132. GENERIC_HACK_DIR := $(GENERIC_PLATFORM_DIR)/hack$(if $(wildcard $(GENERIC_PLATFORM_DIR)/hack-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
  133. GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
  134. __config_name_list = $(1)/config-$(KERNEL_PATCHVER) $(1)/config-default
  135. __config_list = $(firstword $(wildcard $(call __config_name_list,$(1))))
  136. find_kernel_config=$(if $(__config_list),$(__config_list),$(lastword $(__config_name_list)))
  137. GENERIC_LINUX_CONFIG = $(call find_kernel_config,$(GENERIC_PLATFORM_DIR))
  138. LINUX_TARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_DIR))
  139. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  140. LINUX_SUBTARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_SUBDIR))
  141. endif
  142. # config file list used for compiling
  143. LINUX_KCONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(TOPDIR)/env/kernel-config)
  144. # default config list for reconfiguring
  145. # defaults to subtarget if subtarget exists and target does not
  146. # defaults to target otherwise
  147. USE_SUBTARGET_CONFIG = $(if $(wildcard $(LINUX_TARGET_CONFIG)),,$(if $(LINUX_SUBTARGET_CONFIG),1))
  148. LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG)))
  149. LINUX_RECONFIG_TARGET = $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG),$(LINUX_TARGET_CONFIG))
  150. CFG_TARGET = $(CONFIG_TARGET)
  151. ifeq ($(CFG_TARGET),platform)
  152. CFG_TARGET = target
  153. $(warning Deprecation warning: use CONFIG_TARGET=target instead.)
  154. else ifeq ($(CFG_TARGET),subtarget_platform)
  155. CFG_TARGET = subtarget_target
  156. $(warning Deprecation warning: use CONFIG_TARGET=subtarget_target instead.)
  157. endif
  158. # select the config file to be changed by kernel_menuconfig/kernel_oldconfig
  159. ifeq ($(CFG_TARGET),target)
  160. LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG))
  161. LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
  162. else ifeq ($(CFG_TARGET),subtarget)
  163. LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG))
  164. LINUX_RECONFIG_TARGET = $(LINUX_SUBTARGET_CONFIG)
  165. else ifeq ($(CFG_TARGET),subtarget_target)
  166. LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(LINUX_TARGET_CONFIG))
  167. LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
  168. else ifeq ($(CFG_TARGET),env)
  169. LINUX_RECONFIG_LIST = $(LINUX_KCONFIG_LIST)
  170. LINUX_RECONFIG_TARGET = $(TOPDIR)/env/kernel-config
  171. else ifneq ($(strip $(CFG_TARGET)),)
  172. $(error CONFIG_TARGET=$(CFG_TARGET) is invalid. Valid: target|subtarget|subtarget_target|env)
  173. endif
  174. __linux_confcmd = $(2) $(patsubst %,+,$(wordlist 2,9999,$(1))) $(1)
  175. LINUX_CONF_CMD = $(SCRIPT_DIR)/kconfig.pl $(call __linux_confcmd,$(LINUX_KCONFIG_LIST))
  176. LINUX_RECONF_CMD = $(SCRIPT_DIR)/kconfig.pl $(call __linux_confcmd,$(LINUX_RECONFIG_LIST))
  177. LINUX_RECONF_DIFF = $(SCRIPT_DIR)/kconfig.pl - '>' $(call __linux_confcmd,$(filter-out $(LINUX_RECONFIG_TARGET),$(LINUX_RECONFIG_LIST))) $(1) $(GENERIC_PLATFORM_DIR)/config-filter
  178. ifeq ($(DUMP),1)
  179. BuildTarget=$(BuildTargets/DumpCurrent)
  180. CPU_CFLAGS = -Os -pipe
  181. ifneq ($(findstring mips,$(ARCH)),)
  182. ifneq ($(findstring mips64,$(ARCH)),)
  183. CPU_TYPE ?= mips64
  184. else
  185. CPU_TYPE ?= mips32
  186. endif
  187. CPU_CFLAGS += -mno-branch-likely
  188. CPU_CFLAGS_mips32 = -mips32 -mtune=mips32
  189. CPU_CFLAGS_mips64 = -mips64 -mtune=mips64 -mabi=64
  190. CPU_CFLAGS_mips64r2 = -mips64r2 -mtune=mips64r2 -mabi=64
  191. CPU_CFLAGS_4kec = -mips32r2 -mtune=4kec
  192. CPU_CFLAGS_24kc = -mips32r2 -mtune=24kc
  193. CPU_CFLAGS_74kc = -mips32r2 -mtune=74kc
  194. CPU_CFLAGS_octeonplus = -march=octeon+ -mabi=64
  195. endif
  196. ifeq ($(ARCH),i386)
  197. CPU_TYPE ?= pentium-mmx
  198. CPU_CFLAGS_pentium-mmx = -march=pentium-mmx
  199. CPU_CFLAGS_pentium4 = -march=pentium4
  200. endif
  201. ifneq ($(findstring arm,$(ARCH)),)
  202. CPU_TYPE ?= xscale
  203. endif
  204. ifeq ($(ARCH),powerpc)
  205. CPU_CFLAGS_603e:=-mcpu=603e
  206. CPU_CFLAGS_8540:=-mcpu=8540
  207. CPU_CFLAGS_8548:=-mcpu=8548
  208. CPU_CFLAGS_405:=-mcpu=405
  209. CPU_CFLAGS_440:=-mcpu=440
  210. CPU_CFLAGS_464fp:=-mcpu=464fp
  211. endif
  212. ifeq ($(ARCH),powerpc64)
  213. CPU_TYPE ?= powerpc64
  214. CPU_CFLAGS_e5500:=-mcpu=e5500
  215. CPU_CFLAGS_powerpc64:=-mcpu=powerpc64
  216. endif
  217. ifeq ($(ARCH),sparc)
  218. CPU_TYPE = sparc
  219. CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc
  220. endif
  221. ifeq ($(ARCH),aarch64)
  222. CPU_TYPE ?= generic
  223. CPU_CFLAGS_generic = -mcpu=generic
  224. CPU_CFLAGS_cortex-a53 = -mcpu=cortex-a53
  225. endif
  226. ifeq ($(ARCH),arc)
  227. CPU_TYPE ?= arc700
  228. CPU_CFLAGS += -matomic
  229. CPU_CFLAGS_arc700 = -mcpu=arc700
  230. CPU_CFLAGS_archs = -mcpu=archs
  231. endif
  232. ifeq ($(ARCH),riscv64)
  233. CPU_TYPE ?= riscv64
  234. CPU_CFLAGS_riscv64:=-mabi=lp64d -march=rv64imafdc
  235. endif
  236. ifneq ($(CPU_TYPE),)
  237. ifndef CPU_CFLAGS_$(CPU_TYPE)
  238. $(warning CPU_TYPE "$(CPU_TYPE)" doesn't correspond to a known type)
  239. endif
  240. endif
  241. DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
  242. ifneq ($(BOARD),)
  243. TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
  244. $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
  245. $(LINUX_CONF_CMD) > $@ || rm -f $@
  246. -include $(TMP_CONFIG)
  247. .SILENT: $(TMP_CONFIG)
  248. .PRECIOUS: $(TMP_CONFIG)
  249. ifdef KERNEL_TESTING_PATCHVER
  250. ifneq ($(KERNEL_TESTING_PATCHVER),$(KERNEL_PATCHVER))
  251. FEATURES += testing-kernel
  252. endif
  253. endif
  254. ifneq ($(CONFIG_OF),)
  255. FEATURES += dt
  256. endif
  257. ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
  258. FEATURES += gpio
  259. endif
  260. ifneq ($(CONFIG_PCI),)
  261. FEATURES += pci
  262. endif
  263. ifneq ($(CONFIG_PCIEPORTBUS),)
  264. FEATURES += pcie
  265. endif
  266. ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
  267. ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
  268. FEATURES += usb
  269. endif
  270. endif
  271. ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
  272. FEATURES += pcmcia
  273. endif
  274. ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
  275. FEATURES += display
  276. endif
  277. ifneq ($(CONFIG_RTC_CLASS),)
  278. FEATURES += rtc
  279. endif
  280. ifneq ($(CONFIG_VIRTIO),)
  281. FEATURES += virtio
  282. endif
  283. ifneq ($(CONFIG_CPU_MIPS32_R2),)
  284. FEATURES += mips16
  285. endif
  286. FEATURES += $(foreach v,6 7,$(if $(CONFIG_CPU_V$(v)),arm_v$(v)))
  287. # remove duplicates
  288. FEATURES:=$(sort $(FEATURES))
  289. endif
  290. endif
  291. CUR_SUBTARGET:=$(SUBTARGET)
  292. ifeq ($(SUBTARGETS),)
  293. CUR_SUBTARGET := default
  294. endif
  295. define BuildTargets/DumpCurrent
  296. .PHONY: dumpinfo
  297. dumpinfo : export DESCRIPTION=$$(Target/Description)
  298. dumpinfo:
  299. @echo 'Target: $(TARGETID)'; \
  300. echo 'Target-Board: $(BOARD)'; \
  301. echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \
  302. echo 'Target-Arch: $(ARCH)'; \
  303. echo 'Target-Arch-Packages: $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(ARCH)$(if $(CPU_TYPE),_$(CPU_TYPE))$(if $(CPU_SUBTYPE),_$(CPU_SUBTYPE)))'; \
  304. echo 'Target-Features: $(FEATURES)'; \
  305. echo 'Target-Depends: $(DEPENDS)'; \
  306. echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
  307. echo 'CPU-Type: $(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))'; \
  308. echo 'Linux-Version: $(LINUX_VERSION)'; \
  309. $(if $(LINUX_TESTING_VERSION),echo 'Linux-Testing-Version: $(LINUX_TESTING_VERSION)';) \
  310. echo 'Linux-Release: $(LINUX_RELEASE)'; \
  311. echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
  312. $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; )) \
  313. echo 'Target-Description:'; \
  314. echo "$$$$DESCRIPTION"; \
  315. echo '@@'; \
  316. echo 'Default-Packages: $(DEFAULT_PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES))'; \
  317. $(DUMPINFO)
  318. $(if $(CUR_SUBTARGET),$(SUBMAKE) -r --no-print-directory -C image -s DUMP=1 SUBTARGET=$(CUR_SUBTARGET))
  319. $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
  320. endef
  321. include $(INCLUDE_DIR)/kernel.mk
  322. ifeq ($(TARGET_BUILD),1)
  323. include $(INCLUDE_DIR)/kernel-build.mk
  324. BuildTarget?=$(BuildKernel)
  325. endif
  326. endif #__target_inc