target.mk 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. firewall \
  51. ip6tables \
  52. iptables \
  53. kmod-ipt-offload \
  54. odhcp6c \
  55. odhcpd-ipv6only \
  56. ppp \
  57. ppp-mod-pppoe
  58. ifneq ($(DUMP),)
  59. all: dumpinfo
  60. endif
  61. target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
  62. ifeq ($(DUMP),)
  63. PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
  64. SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
  65. else
  66. PLATFORM_DIR:=${CURDIR}
  67. ifeq ($(SUBTARGETS),)
  68. SUBTARGETS:=$(strip $(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)))
  69. endif
  70. endif
  71. TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
  72. PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
  73. ifneq ($(TARGET_BUILD),1)
  74. ifndef DUMP
  75. include $(PLATFORM_DIR)/Makefile
  76. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  77. include $(PLATFORM_SUBDIR)/target.mk
  78. endif
  79. endif
  80. else
  81. ifneq ($(SUBTARGET),)
  82. -include ./$(SUBTARGET)/target.mk
  83. endif
  84. endif
  85. # Add device specific packages (here below to allow device type set from subtarget)
  86. DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
  87. filter_packages = $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
  88. extra_packages = $(if $(filter wpad wpad-% nas,$(1)),iwinfo)
  89. define ProfileDefault
  90. NAME:=
  91. PRIORITY:=
  92. PACKAGES:=
  93. endef
  94. ifndef Profile
  95. define Profile
  96. $(eval $(call ProfileDefault))
  97. $(eval $(call Profile/$(1)))
  98. dumpinfo : $(call shexport,Profile/$(1)/Description)
  99. PACKAGES := $(filter-out -%,$(PACKAGES))
  100. DUMPINFO += \
  101. echo "Target-Profile: $(1)"; \
  102. $(if $(PRIORITY), echo "Target-Profile-Priority: $(PRIORITY)"; ) \
  103. echo "Target-Profile-Name: $(NAME)"; \
  104. echo "Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
  105. echo "Target-Profile-Description:"; \
  106. echo "$$$$$$$$$(call shvar,Profile/$(1)/Description)"; \
  107. echo "@@"; \
  108. echo;
  109. endef
  110. endif
  111. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  112. define IncludeProfiles
  113. -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
  114. -include $(sort $(wildcard $(PLATFORM_SUBDIR)/profiles/*.mk))
  115. endef
  116. else
  117. define IncludeProfiles
  118. -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
  119. endef
  120. endif
  121. PROFILE?=$(call qstrip,$(CONFIG_TARGET_PROFILE))
  122. ifeq ($(TARGET_BUILD),1)
  123. ifneq ($(DUMP),)
  124. $(eval $(call IncludeProfiles))
  125. endif
  126. endif
  127. ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
  128. include $(INCLUDE_DIR)/kernel-version.mk
  129. endif
  130. GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic
  131. GENERIC_BACKPORT_DIR := $(GENERIC_PLATFORM_DIR)/backport$(if $(wildcard $(GENERIC_PLATFORM_DIR)/backport-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
  132. GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/pending$(if $(wildcard $(GENERIC_PLATFORM_DIR)/pending-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
  133. GENERIC_HACK_DIR := $(GENERIC_PLATFORM_DIR)/hack$(if $(wildcard $(GENERIC_PLATFORM_DIR)/hack-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
  134. GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
  135. __config_name_list = $(1)/config-$(KERNEL_PATCHVER) $(1)/config-default
  136. __config_list = $(firstword $(wildcard $(call __config_name_list,$(1))))
  137. find_kernel_config=$(if $(__config_list),$(__config_list),$(lastword $(__config_name_list)))
  138. GENERIC_LINUX_CONFIG = $(call find_kernel_config,$(GENERIC_PLATFORM_DIR))
  139. LINUX_TARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_DIR))
  140. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  141. LINUX_SUBTARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_SUBDIR))
  142. endif
  143. # config file list used for compiling
  144. LINUX_KCONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(TOPDIR)/env/kernel-config)
  145. # default config list for reconfiguring
  146. # defaults to subtarget if subtarget exists and target does not
  147. # defaults to target otherwise
  148. USE_SUBTARGET_CONFIG = $(if $(wildcard $(LINUX_TARGET_CONFIG)),,$(if $(LINUX_SUBTARGET_CONFIG),1))
  149. LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG)))
  150. LINUX_RECONFIG_TARGET = $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG),$(LINUX_TARGET_CONFIG))
  151. # select the config file to be changed by kernel_menuconfig/kernel_oldconfig
  152. ifeq ($(CONFIG_TARGET),platform)
  153. LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG))
  154. LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
  155. endif
  156. ifeq ($(CONFIG_TARGET),subtarget)
  157. LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG))
  158. LINUX_RECONFIG_TARGET = $(LINUX_SUBTARGET_CONFIG)
  159. endif
  160. ifeq ($(CONFIG_TARGET),subtarget_platform)
  161. LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(LINUX_TARGET_CONFIG))
  162. LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
  163. endif
  164. ifeq ($(CONFIG_TARGET),env)
  165. LINUX_RECONFIG_LIST = $(LINUX_KCONFIG_LIST)
  166. LINUX_RECONFIG_TARGET = $(TOPDIR)/env/kernel-config
  167. endif
  168. __linux_confcmd = $(2) $(patsubst %,+,$(wordlist 2,9999,$(1))) $(1)
  169. LINUX_CONF_CMD = $(SCRIPT_DIR)/kconfig.pl $(call __linux_confcmd,$(LINUX_KCONFIG_LIST))
  170. LINUX_RECONF_CMD = $(SCRIPT_DIR)/kconfig.pl $(call __linux_confcmd,$(LINUX_RECONFIG_LIST))
  171. LINUX_RECONF_DIFF = $(SCRIPT_DIR)/kconfig.pl - '>' $(call __linux_confcmd,$(filter-out $(LINUX_RECONFIG_TARGET),$(LINUX_RECONFIG_LIST))) $(1) $(GENERIC_PLATFORM_DIR)/config-filter
  172. ifeq ($(DUMP),1)
  173. BuildTarget=$(BuildTargets/DumpCurrent)
  174. CPU_CFLAGS = -Os -pipe
  175. ifneq ($(findstring mips,$(ARCH)),)
  176. ifneq ($(findstring mips64,$(ARCH)),)
  177. CPU_TYPE ?= mips64
  178. else
  179. CPU_TYPE ?= mips32
  180. endif
  181. CPU_CFLAGS += -mno-branch-likely
  182. CPU_CFLAGS_mips32 = -mips32 -mtune=mips32
  183. CPU_CFLAGS_mips64 = -mips64 -mtune=mips64 -mabi=64
  184. CPU_CFLAGS_mips64r2 = -mips64r2 -mtune=mips64r2 -mabi=64
  185. CPU_CFLAGS_4kec = -mips32r2 -mtune=4kec
  186. CPU_CFLAGS_24kc = -mips32r2 -mtune=24kc
  187. CPU_CFLAGS_74kc = -mips32r2 -mtune=74kc
  188. CPU_CFLAGS_octeonplus = -march=octeon+ -mabi=64
  189. endif
  190. ifeq ($(ARCH),i386)
  191. CPU_TYPE ?= pentium-mmx
  192. CPU_CFLAGS_pentium-mmx = -march=pentium-mmx
  193. CPU_CFLAGS_pentium4 = -march=pentium4
  194. endif
  195. ifneq ($(findstring arm,$(ARCH)),)
  196. CPU_TYPE ?= xscale
  197. endif
  198. ifeq ($(ARCH),powerpc)
  199. CPU_CFLAGS_603e:=-mcpu=603e
  200. CPU_CFLAGS_8540:=-mcpu=8540
  201. CPU_CFLAGS_405:=-mcpu=405
  202. CPU_CFLAGS_440:=-mcpu=440
  203. CPU_CFLAGS_464fp:=-mcpu=464fp
  204. endif
  205. ifeq ($(ARCH),powerpc64)
  206. CPU_TYPE ?= powerpc64
  207. CPU_CFLAGS_powerpc64:=-mcpu=powerpc64
  208. endif
  209. ifeq ($(ARCH),sparc)
  210. CPU_TYPE = sparc
  211. CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc
  212. endif
  213. ifeq ($(ARCH),aarch64)
  214. CPU_TYPE ?= generic
  215. CPU_CFLAGS_generic = -mcpu=generic
  216. CPU_CFLAGS_cortex-a53 = -mcpu=cortex-a53
  217. endif
  218. ifeq ($(ARCH),arc)
  219. CPU_TYPE ?= arc700
  220. CPU_CFLAGS += -matomic
  221. CPU_CFLAGS_arc700 = -mcpu=arc700
  222. CPU_CFLAGS_archs = -mcpu=archs
  223. endif
  224. ifneq ($(CPU_TYPE),)
  225. ifndef CPU_CFLAGS_$(CPU_TYPE)
  226. $(warning CPU_TYPE "$(CPU_TYPE)" doesn't correspond to a known type)
  227. endif
  228. endif
  229. DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
  230. ifneq ($(BOARD),)
  231. TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
  232. $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
  233. $(LINUX_CONF_CMD) > $@ || rm -f $@
  234. -include $(TMP_CONFIG)
  235. .SILENT: $(TMP_CONFIG)
  236. .PRECIOUS: $(TMP_CONFIG)
  237. ifdef KERNEL_TESTING_PATCHVER
  238. ifneq ($(KERNEL_TESTING_PATCHVER),$(KERNEL_PATCHVER))
  239. FEATURES += testing-kernel
  240. endif
  241. endif
  242. ifneq ($(CONFIG_OF),)
  243. FEATURES += dt
  244. endif
  245. ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
  246. FEATURES += gpio
  247. endif
  248. ifneq ($(CONFIG_PCI),)
  249. FEATURES += pci
  250. endif
  251. ifneq ($(CONFIG_PCIEPORTBUS),)
  252. FEATURES += pcie
  253. endif
  254. ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
  255. ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
  256. FEATURES += usb
  257. endif
  258. endif
  259. ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
  260. FEATURES += pcmcia
  261. endif
  262. ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
  263. FEATURES += display
  264. endif
  265. ifneq ($(CONFIG_RTC_CLASS),)
  266. FEATURES += rtc
  267. endif
  268. ifneq ($(CONFIG_VIRTIO),)
  269. FEATURES += virtio
  270. endif
  271. ifneq ($(CONFIG_CPU_MIPS32_R2),)
  272. FEATURES += mips16
  273. endif
  274. FEATURES += $(foreach v,6 7,$(if $(CONFIG_CPU_V$(v)),arm_v$(v)))
  275. # remove duplicates
  276. FEATURES:=$(sort $(FEATURES))
  277. endif
  278. endif
  279. CUR_SUBTARGET:=$(SUBTARGET)
  280. ifeq ($(SUBTARGETS),)
  281. CUR_SUBTARGET := default
  282. endif
  283. define BuildTargets/DumpCurrent
  284. .PHONY: dumpinfo
  285. dumpinfo : export DESCRIPTION=$$(Target/Description)
  286. dumpinfo:
  287. @echo 'Target: $(TARGETID)'; \
  288. echo 'Target-Board: $(BOARD)'; \
  289. echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \
  290. echo 'Target-Arch: $(ARCH)'; \
  291. echo 'Target-Arch-Packages: $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(ARCH)$(if $(CPU_TYPE),_$(CPU_TYPE))$(if $(CPU_SUBTYPE),_$(CPU_SUBTYPE)))'; \
  292. echo 'Target-Features: $(FEATURES)'; \
  293. echo 'Target-Depends: $(DEPENDS)'; \
  294. echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
  295. echo 'CPU-Type: $(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))'; \
  296. echo 'Linux-Version: $(LINUX_VERSION)'; \
  297. $(if $(LINUX_TESTING_VERSION),echo 'Linux-Testing-Version: $(LINUX_TESTING_VERSION)';) \
  298. echo 'Linux-Release: $(LINUX_RELEASE)'; \
  299. echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
  300. $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; )) \
  301. echo 'Target-Description:'; \
  302. echo "$$$$DESCRIPTION"; \
  303. echo '@@'; \
  304. echo 'Default-Packages: $(DEFAULT_PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES))'; \
  305. $(DUMPINFO)
  306. $(if $(CUR_SUBTARGET),$(SUBMAKE) -r --no-print-directory -C image -s DUMP=1 SUBTARGET=$(CUR_SUBTARGET))
  307. $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
  308. endef
  309. include $(INCLUDE_DIR)/kernel.mk
  310. ifeq ($(TARGET_BUILD),1)
  311. include $(INCLUDE_DIR)/kernel-build.mk
  312. BuildTarget?=$(BuildKernel)
  313. endif
  314. endif #__target_inc