target.mk 11 KB

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