2 # Copyright (C) 2007-2008 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 ifneq ($(__target_inc),1)
14 # Default packages - the really basic set
15 DEFAULT_PACKAGES:=base-files libc libgcc busybox dropbear mtd uci opkg netifd fstools
17 DEFAULT_PACKAGES.router:=dnsmasq iptables ip6tables ppp ppp-mod-pppoe kmod-ipt-nathelper firewall odhcpd odhcp6c
18 DEFAULT_PACKAGES.bootloader:=
24 target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
26 PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
27 SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
29 PLATFORM_DIR:=${CURDIR}
31 SUBTARGETS:=$(strip $(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)))
35 TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
36 PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
38 ifneq ($(TARGET_BUILD),1)
40 include $(PLATFORM_DIR)/Makefile
41 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
42 include $(PLATFORM_SUBDIR)/target.mk
47 -include ./$(SUBTARGET)/target.mk
51 # Add device specific packages (here below to allow device type set from subtarget)
52 DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
54 filter_packages = $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
55 extra_packages = $(if $(filter wpad-mini wpad nas,$(1)),iwinfo)
57 define Profile/Default
64 $(eval $(call Profile/Default))
65 $(eval $(call Profile/$(1)))
66 $(eval $(call shexport,Profile/$(1)/Config))
67 $(eval $(call shexport,Profile/$(1)/Description))
69 echo "Target-Profile: $(1)"; \
70 echo "Target-Profile-Name: $(NAME)"; \
71 echo "Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
72 if [ -f ./config/profile-$(1) ]; then \
73 echo "Target-Profile-Kconfig: yes"; \
75 echo "Target-Profile-Config: "; \
76 $(SH_FUNC) getvar "$(call shvar,Profile/$(1)/Config)"; \
78 echo "Target-Profile-Description:"; \
79 $(SH_FUNC) getvar "$(call shvar,Profile/$(1)/Description)"; \
82 ifeq ($(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(if $(SUBTARGET),$(SUBTARGET)_))$(1)),y)
88 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
89 define IncludeProfiles
90 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
91 -include $(sort $(wildcard $(PLATFORM_SUBDIR)/profiles/*.mk))
94 define IncludeProfiles
95 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
99 ifeq ($(TARGET_BUILD),1)
100 $(eval $(call IncludeProfiles))
103 $(eval $(call IncludeProfiles))
107 $(eval $(call shexport,Target/Description))
109 ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
110 include $(INCLUDE_DIR)/kernel-version.mk
113 GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic
114 GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/patches$(if $(wildcard $(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
115 GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
117 __config_name_list = $(1)/config-$(KERNEL_PATCHVER) $(1)/config-default
118 __config_list = $(firstword $(wildcard $(call __config_name_list,$(1))))
119 find_kernel_config=$(if $(__config_list),$(__config_list),$(lastword $(__config_name_list)))
121 GENERIC_LINUX_CONFIG = $(call find_kernel_config,$(GENERIC_PLATFORM_DIR))
122 LINUX_TARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_DIR))
123 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
124 LINUX_SUBTARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_SUBDIR))
127 # config file list used for compiling
128 LINUX_KCONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(TOPDIR)/env/kernel-config)
130 # default config list for reconfiguring
131 # defaults to subtarget if subtarget exists and target does not
132 # defaults to target otherwise
133 USE_SUBTARGET_CONFIG = $(if $(wildcard $(LINUX_TARGET_CONFIG)),,$(if $(LINUX_SUBTARGET_CONFIG),1))
135 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG)))
136 LINUX_RECONFIG_TARGET = $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG),$(LINUX_TARGET_CONFIG))
138 # select the config file to be changed by kernel_menuconfig/kernel_oldconfig
139 ifeq ($(CONFIG_TARGET),platform)
140 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG))
141 LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
143 ifeq ($(CONFIG_TARGET),subtarget)
144 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG))
145 LINUX_RECONFIG_TARGET = $(LINUX_SUBTARGET_CONFIG)
147 ifeq ($(CONFIG_TARGET),subtarget_platform)
148 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(LINUX_TARGET_CONFIG))
149 LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
151 ifeq ($(CONFIG_TARGET),env)
152 LINUX_RECONFIG_LIST = $(LINUX_KCONFIG_LIST)
153 LINUX_RECONFIG_TARGET = $(TOPDIR)/env/kernel-config
156 __linux_confcmd = $(SCRIPT_DIR)/kconfig.pl $(2) $(patsubst %,+,$(wordlist 2,9999,$(1))) $(1)
158 LINUX_CONF_CMD = $(call __linux_confcmd,$(LINUX_KCONFIG_LIST),)
159 LINUX_RECONF_CMD = $(call __linux_confcmd,$(LINUX_RECONFIG_LIST),)
160 LINUX_RECONF_DIFF = $(call __linux_confcmd,$(filter-out $(LINUX_RECONFIG_TARGET),$(LINUX_RECONFIG_LIST)),'>')
163 BuildTarget=$(BuildTargets/DumpCurrent)
166 TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
167 $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
168 $(LINUX_CONF_CMD) > $@ || rm -f $@
169 -include $(TMP_CONFIG)
170 .SILENT: $(TMP_CONFIG)
171 .PRECIOUS: $(TMP_CONFIG)
173 ifneq ($(CONFIG_OF),)
176 ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
179 ifneq ($(CONFIG_PCI),)
182 ifneq ($(CONFIG_PCIEPORTBUS),)
185 ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
186 ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
190 ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
193 ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
196 ifneq ($(CONFIG_RTC_CLASS),)
199 FEATURES += $(foreach v,v4 v5 v6 v7,$(if $(findstring -march=arm$(v),$(CFLAGS)),arm_$(v)))
202 FEATURES:=$(sort $(FEATURES))
204 CPU_CFLAGS = -Os -pipe
205 ifneq ($(findstring mips,$(ARCH)),)
206 ifneq ($(findstring mips64,$(ARCH)),)
211 CPU_CFLAGS += -mno-branch-likely
212 CPU_CFLAGS_mips32 = -mips32 -mtune=mips32
213 CPU_CFLAGS_mips32r2 = -mips32r2 -mtune=mips32r2
214 CPU_CFLAGS_mips64 = -mips64 -mtune=mips64 -mabi=64
215 CPU_CFLAGS_24kec = -mips32r2 -mtune=24kec
216 CPU_CFLAGS_34kc = -mips32r2 -mtune=34kc
217 CPU_CFLAGS_dsp = -mdsp
218 CPU_CFLAGS_dsp2 = -mdspr2
222 CPU_CFLAGS_i486 = -march=i486
223 CPU_CFLAGS_geode = -march=geode -mmmx -m3dnow
225 ifneq ($(findstring arm,$(ARCH)),)
227 CPU_CFLAGS_arm920t = -march=armv4t -mtune=arm920t
228 CPU_CFLAGS_arm926ej-s = -march=armv5te -mtune=arm926ej-s
229 CPU_CFLAGS_arm1136j-s = -march=armv6 -mtune=arm1136j-s
230 CPU_CFLAGS_arm1176jzf-s = -march=armv6 -mtune=arm1176jzf-s
231 CPU_CFLAGS_cortex-a7 = -march=armv7-a -mtune=cortex-a7
232 CPU_CFLAGS_cortex-a8 = -march=armv7-a -mtune=cortex-a8
233 CPU_CFLAGS_cortex-a9 = -march=armv7-a -mtune=cortex-a9
234 CPU_CFLAGS_cortex-a15 = -march=armv7-a -mtune=cortex-a15
235 CPU_CFLAGS_fa526 = -march=armv4 -mtune=fa526
236 CPU_CFLAGS_mpcore = -march=armv6k -mtune=mpcore
237 CPU_CFLAGS_xscale = -march=armv5te -mtune=xscale
238 ifeq ($(CONFIG_SOFT_FLOAT),)
239 CPU_CFLAGS_neon = -mfpu=neon
240 CPU_CFLAGS_vfp = -mfpu=vfp
241 CPU_CFLAGS_vfpv3 = -mfpu=vfpv3-d16
244 ifeq ($(ARCH),powerpc)
245 CPU_CFLAGS_603e:=-mcpu=603e
246 CPU_CFLAGS_8540:=-mcpu=8540
247 CPU_CFLAGS_405:=-mcpu=405
248 CPU_CFLAGS_440:=-mcpu=440
252 CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc
254 DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
257 define BuildTargets/DumpCurrent
260 @echo 'Target: $(TARGETID)'; \
261 echo 'Target-Board: $(BOARD)'; \
262 echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \
263 echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'; \
264 echo 'Target-Arch: $(ARCH)'; \
265 echo 'Target-Arch-Packages: $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD))'; \
266 echo 'Target-Features: $(FEATURES)'; \
267 echo 'Target-Depends: $(DEPENDS)'; \
268 echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
269 echo 'CPU-Type: $(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))'; \
270 echo 'Linux-Version: $(LINUX_VERSION)'; \
271 echo 'Linux-Release: $(LINUX_RELEASE)'; \
272 echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
273 $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; ))
274 echo 'Target-Description:'; \
275 $(SH_FUNC) getvar $(call shvar,Target/Description); \
277 echo 'Default-Packages: $(DEFAULT_PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES))'; \
279 $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
282 include $(INCLUDE_DIR)/kernel.mk
283 ifeq ($(TARGET_BUILD),1)
284 include $(INCLUDE_DIR)/kernel-build.mk
285 BuildTarget?=$(BuildKernel)