target.mk 9.6 KB

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