target.mk 13 KB

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