target.mk 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. #
  2. # Copyright (C) 2007-2008 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. ifneq ($(__target_inc),1)
  8. __target_inc=1
  9. # default device type
  10. DEVICE_TYPE?=router
  11. # Default packages - the really basic set
  12. DEFAULT_PACKAGES:=base-files libc libgcc busybox dropbear mtd uci opkg netifd fstools
  13. # For nas targets
  14. DEFAULT_PACKAGES.nas:=block-mount fdisk lsblk mdadm
  15. # For router targets
  16. DEFAULT_PACKAGES.router:=dnsmasq iptables ip6tables ppp ppp-mod-pppoe kmod-nf-nathelper firewall odhcpd odhcp6c
  17. DEFAULT_PACKAGES.bootloader:=
  18. ifneq ($(DUMP),)
  19. all: dumpinfo
  20. endif
  21. target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
  22. ifeq ($(DUMP),)
  23. PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
  24. SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
  25. else
  26. PLATFORM_DIR:=${CURDIR}
  27. ifeq ($(SUBTARGETS),)
  28. SUBTARGETS:=$(strip $(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)))
  29. endif
  30. endif
  31. TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
  32. PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
  33. ifneq ($(TARGET_BUILD),1)
  34. ifndef DUMP
  35. include $(PLATFORM_DIR)/Makefile
  36. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  37. include $(PLATFORM_SUBDIR)/target.mk
  38. endif
  39. endif
  40. else
  41. ifneq ($(SUBTARGET),)
  42. -include ./$(SUBTARGET)/target.mk
  43. endif
  44. endif
  45. # Add device specific packages (here below to allow device type set from subtarget)
  46. DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
  47. filter_packages = $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
  48. extra_packages = $(if $(filter wpad-mini wpad nas,$(1)),iwinfo)
  49. define Profile/Default
  50. NAME:=
  51. PACKAGES:=
  52. endef
  53. ifndef Profile
  54. define Profile
  55. $(eval $(call Profile/Default))
  56. $(eval $(call Profile/$(1)))
  57. dumpinfo : $(call shexport,Profile/$(1)/Config)
  58. dumpinfo : $(call shexport,Profile/$(1)/Description)
  59. DUMPINFO += \
  60. echo "Target-Profile: $(1)"; \
  61. echo "Target-Profile-Name: $(NAME)"; \
  62. echo "Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
  63. if [ -f ./config/profile-$(1) ]; then \
  64. echo "Target-Profile-Kconfig: yes"; \
  65. fi; \
  66. echo "Target-Profile-Config: "; \
  67. echo "$$$$$$$$$(call shvar,Profile/$(1)/Config)"; \
  68. echo "@@"; \
  69. echo "Target-Profile-Description:"; \
  70. echo "$$$$$$$$$(call shvar,Profile/$(1)/Description)"; \
  71. echo "@@"; \
  72. echo;
  73. ifeq ($(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(if $(SUBTARGET),$(SUBTARGET)_))$(1)),y)
  74. PROFILE=$(1)
  75. endif
  76. endef
  77. endif
  78. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  79. define IncludeProfiles
  80. -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
  81. -include $(sort $(wildcard $(PLATFORM_SUBDIR)/profiles/*.mk))
  82. endef
  83. else
  84. define IncludeProfiles
  85. -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
  86. endef
  87. endif
  88. ifeq ($(TARGET_BUILD),1)
  89. $(eval $(call IncludeProfiles))
  90. else
  91. ifeq ($(DUMP),)
  92. $(eval $(call IncludeProfiles))
  93. endif
  94. endif
  95. ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
  96. include $(INCLUDE_DIR)/kernel-version.mk
  97. endif
  98. GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic
  99. GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/patches$(if $(wildcard $(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
  100. GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
  101. __config_name_list = $(1)/config-$(KERNEL_PATCHVER) $(1)/config-default
  102. __config_list = $(firstword $(wildcard $(call __config_name_list,$(1))))
  103. find_kernel_config=$(if $(__config_list),$(__config_list),$(lastword $(__config_name_list)))
  104. GENERIC_LINUX_CONFIG = $(call find_kernel_config,$(GENERIC_PLATFORM_DIR))
  105. LINUX_TARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_DIR))
  106. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  107. LINUX_SUBTARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_SUBDIR))
  108. endif
  109. # config file list used for compiling
  110. LINUX_KCONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(TOPDIR)/env/kernel-config)
  111. # default config list for reconfiguring
  112. # defaults to subtarget if subtarget exists and target does not
  113. # defaults to target otherwise
  114. USE_SUBTARGET_CONFIG = $(if $(wildcard $(LINUX_TARGET_CONFIG)),,$(if $(LINUX_SUBTARGET_CONFIG),1))
  115. LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG)))
  116. LINUX_RECONFIG_TARGET = $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG),$(LINUX_TARGET_CONFIG))
  117. # select the config file to be changed by kernel_menuconfig/kernel_oldconfig
  118. ifeq ($(CONFIG_TARGET),platform)
  119. LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG))
  120. LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
  121. endif
  122. ifeq ($(CONFIG_TARGET),subtarget)
  123. LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG))
  124. LINUX_RECONFIG_TARGET = $(LINUX_SUBTARGET_CONFIG)
  125. endif
  126. ifeq ($(CONFIG_TARGET),subtarget_platform)
  127. LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(LINUX_TARGET_CONFIG))
  128. LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
  129. endif
  130. ifeq ($(CONFIG_TARGET),env)
  131. LINUX_RECONFIG_LIST = $(LINUX_KCONFIG_LIST)
  132. LINUX_RECONFIG_TARGET = $(TOPDIR)/env/kernel-config
  133. endif
  134. __linux_confcmd = $(SCRIPT_DIR)/kconfig.pl $(2) $(patsubst %,+,$(wordlist 2,9999,$(1))) $(1)
  135. LINUX_CONF_CMD = $(call __linux_confcmd,$(LINUX_KCONFIG_LIST),)
  136. LINUX_RECONF_CMD = $(call __linux_confcmd,$(LINUX_RECONFIG_LIST),)
  137. LINUX_RECONF_DIFF = $(call __linux_confcmd,$(filter-out $(LINUX_RECONFIG_TARGET),$(LINUX_RECONFIG_LIST)),'>')
  138. ifeq ($(DUMP),1)
  139. BuildTarget=$(BuildTargets/DumpCurrent)
  140. ifneq ($(BOARD),)
  141. TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
  142. $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
  143. $(LINUX_CONF_CMD) > $@ || rm -f $@
  144. -include $(TMP_CONFIG)
  145. .SILENT: $(TMP_CONFIG)
  146. .PRECIOUS: $(TMP_CONFIG)
  147. ifneq ($(CONFIG_OF),)
  148. FEATURES += dt
  149. endif
  150. ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
  151. FEATURES += gpio
  152. endif
  153. ifneq ($(CONFIG_PCI),)
  154. FEATURES += pci
  155. endif
  156. ifneq ($(CONFIG_PCIEPORTBUS),)
  157. FEATURES += pcie
  158. endif
  159. ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
  160. ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
  161. FEATURES += usb
  162. endif
  163. endif
  164. ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
  165. FEATURES += pcmcia
  166. endif
  167. ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
  168. FEATURES += display
  169. endif
  170. ifneq ($(CONFIG_RTC_CLASS),)
  171. FEATURES += rtc
  172. endif
  173. FEATURES += $(foreach v,v4 v5 v6 v7,$(if $(findstring -march=arm$(v),$(CFLAGS)),arm_$(v)))
  174. # remove duplicates
  175. FEATURES:=$(sort $(FEATURES))
  176. endif
  177. CPU_CFLAGS = -Os -pipe
  178. ifneq ($(findstring mips,$(ARCH)),)
  179. ifneq ($(findstring mips64,$(ARCH)),)
  180. CPU_TYPE ?= mips64
  181. else
  182. CPU_TYPE ?= mips32
  183. endif
  184. CPU_CFLAGS += -mno-branch-likely
  185. CPU_CFLAGS_mips32 = -mips32 -mtune=mips32
  186. CPU_CFLAGS_mips32r2 = -mips32r2 -mtune=mips32r2
  187. CPU_CFLAGS_mips64 = -mips64 -mtune=mips64 -mabi=64
  188. CPU_CFLAGS_24kec = -mips32r2 -mtune=24kec
  189. CPU_CFLAGS_34kc = -mips32r2 -mtune=34kc
  190. CPU_CFLAGS_74kc = -mips32r2 -mtune=74kc
  191. CPU_CFLAGS_octeon = -march=octeon -mabi=64
  192. CPU_CFLAGS_dsp = -mdsp
  193. CPU_CFLAGS_dsp2 = -mdspr2
  194. endif
  195. ifeq ($(ARCH),i386)
  196. CPU_TYPE ?= i486
  197. CPU_CFLAGS_i486 = -march=i486
  198. CPU_CFLAGS_pentium4 = -march=pentium4
  199. CPU_CFLAGS_geode = -march=geode -mmmx -m3dnow
  200. endif
  201. ifneq ($(findstring arm,$(ARCH)),)
  202. CPU_TYPE ?= xscale
  203. CPU_CFLAGS_arm920t = -march=armv4t -mtune=arm920t
  204. CPU_CFLAGS_arm926ej-s = -march=armv5te -mtune=arm926ej-s
  205. CPU_CFLAGS_arm1136j-s = -march=armv6 -mtune=arm1136j-s
  206. CPU_CFLAGS_arm1176jzf-s = -march=armv6 -mtune=arm1176jzf-s
  207. CPU_CFLAGS_cortex-a5 = -march=armv7-a -mtune=cortex-a5
  208. CPU_CFLAGS_cortex-a7 = -march=armv7-a -mtune=cortex-a7
  209. CPU_CFLAGS_cortex-a8 = -march=armv7-a -mtune=cortex-a8
  210. CPU_CFLAGS_cortex-a9 = -march=armv7-a -mtune=cortex-a9
  211. CPU_CFLAGS_cortex-a15 = -march=armv7-a -mtune=cortex-a15
  212. CPU_CFLAGS_fa526 = -march=armv4 -mtune=fa526
  213. CPU_CFLAGS_mpcore = -march=armv6k -mtune=mpcore
  214. CPU_CFLAGS_xscale = -march=armv5te -mtune=xscale
  215. ifeq ($(CONFIG_SOFT_FLOAT),)
  216. CPU_CFLAGS_neon = -mfpu=neon
  217. CPU_CFLAGS_vfp = -mfpu=vfp
  218. CPU_CFLAGS_vfpv3 = -mfpu=vfpv3-d16
  219. endif
  220. endif
  221. ifeq ($(ARCH),powerpc)
  222. CPU_CFLAGS_603e:=-mcpu=603e
  223. CPU_CFLAGS_8540:=-mcpu=8540
  224. CPU_CFLAGS_405:=-mcpu=405
  225. CPU_CFLAGS_440:=-mcpu=440
  226. endif
  227. ifeq ($(ARCH),sparc)
  228. CPU_TYPE = sparc
  229. CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc
  230. endif
  231. ifeq ($(ARCH),aarch64)
  232. CPU_TYPE ?= armv8-a
  233. CPU_CFLAGS_armv8-a = -mcpu=armv8-a
  234. endif
  235. DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
  236. endif
  237. define BuildTargets/DumpCurrent
  238. .PHONY: dumpinfo
  239. dumpinfo : export DESCRIPTION=$$(Target/Description)
  240. dumpinfo:
  241. @echo 'Target: $(TARGETID)'; \
  242. echo 'Target-Board: $(BOARD)'; \
  243. echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \
  244. echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'; \
  245. echo 'Target-Arch: $(ARCH)'; \
  246. echo 'Target-Arch-Packages: $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD))'; \
  247. echo 'Target-Features: $(FEATURES)'; \
  248. echo 'Target-Depends: $(DEPENDS)'; \
  249. echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
  250. echo 'CPU-Type: $(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))'; \
  251. echo 'Linux-Version: $(LINUX_VERSION)'; \
  252. echo 'Linux-Release: $(LINUX_RELEASE)'; \
  253. echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
  254. $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; )) \
  255. echo 'Target-Description:'; \
  256. echo "$$$$DESCRIPTION"; \
  257. echo '@@'; \
  258. echo 'Default-Packages: $(DEFAULT_PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES))'; \
  259. $(DUMPINFO)
  260. $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
  261. endef
  262. include $(INCLUDE_DIR)/kernel.mk
  263. ifeq ($(TARGET_BUILD),1)
  264. include $(INCLUDE_DIR)/kernel-build.mk
  265. BuildTarget?=$(BuildKernel)
  266. endif
  267. endif #__target_inc