target.mk 13 KB

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