1
0

target.mk 11 KB

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