target.mk 10 KB

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