target.mk 11 KB

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