2 # Copyright (C) 2007-2008 OpenWrt.org
3 # Copyright (C) 2016 LEDE Project
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
9 ifneq ($(__target_inc
),1)
15 # Default packages - the really basic set
34 DEFAULT_PACKAGES.basic
:=
36 DEFAULT_PACKAGES.nas
:=\
42 DEFAULT_PACKAGES.router
:=\
57 target_conf
=$(subst .
,_
,$(subst -,_
,$(subst /,_
,$(1))))
59 PLATFORM_DIR
:=$(TOPDIR
)/target
/linux
/$(BOARD
)
60 SUBTARGET
:=$(strip $(foreach subdir
,$(patsubst $(PLATFORM_DIR
)/%/target.mk
,%,$(wildcard $(PLATFORM_DIR
)/*/target.mk
)),$(if
$(CONFIG_TARGET_
$(call target_conf
,$(BOARD
)_
$(subdir
))),$(subdir
))))
62 PLATFORM_DIR
:=${CURDIR}
64 SUBTARGETS
:=$(strip $(patsubst $(PLATFORM_DIR
)/%/target.mk
,%,$(wildcard $(PLATFORM_DIR
)/*/target.mk
)))
68 TARGETID
:=$(BOARD
)$(if
$(SUBTARGET
),/$(SUBTARGET
))
69 PLATFORM_SUBDIR
:=$(PLATFORM_DIR
)$(if
$(SUBTARGET
),/$(SUBTARGET
))
71 ifneq ($(TARGET_BUILD
),1)
73 include $(PLATFORM_DIR
)/Makefile
74 ifneq ($(PLATFORM_DIR
),$(PLATFORM_SUBDIR
))
75 include $(PLATFORM_SUBDIR
)/target.mk
80 -include .
/$(SUBTARGET
)/target.mk
84 # Add device specific packages (here below to allow device type set from subtarget)
85 DEFAULT_PACKAGES
+= $(DEFAULT_PACKAGES.
$(DEVICE_TYPE
))
87 filter_packages
= $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
88 extra_packages
= $(if
$(filter wpad wpad-
% nas
,$(1)),iwinfo
)
98 $(eval
$(call ProfileDefault
))
99 $(eval
$(call Profile
/$(1)))
100 dumpinfo
: $(call shexport
,Profile
/$(1)/Description
)
101 PACKAGES
:= $(filter-out -%,$(PACKAGES
))
103 echo
"Target-Profile: $(1)"; \
104 $(if
$(PRIORITY
), echo
"Target-Profile-Priority: $(PRIORITY)"; ) \
105 echo
"Target-Profile-Name: $(NAME)"; \
106 echo
"Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
107 echo
"Target-Profile-Description:"; \
108 echo
"$$$$$$$$$(call shvar,Profile/$(1)/Description)"; \
114 ifneq ($(PLATFORM_DIR
),$(PLATFORM_SUBDIR
))
115 define IncludeProfiles
116 -include $(sort $(wildcard $(PLATFORM_DIR
)/profiles
/*.mk
))
117 -include $(sort $(wildcard $(PLATFORM_SUBDIR
)/profiles
/*.mk
))
120 define IncludeProfiles
121 -include $(sort $(wildcard $(PLATFORM_DIR
)/profiles
/*.mk
))
125 PROFILE?
=$(call qstrip
,$(CONFIG_TARGET_PROFILE
))
127 ifeq ($(TARGET_BUILD
),1)
129 $(eval
$(call IncludeProfiles
))
133 ifneq ($(TARGET_BUILD
)$(if
$(DUMP
),,1),)
134 include $(INCLUDE_DIR
)/kernel-version.mk
137 GENERIC_PLATFORM_DIR
:= $(TOPDIR
)/target
/linux
/generic
138 GENERIC_BACKPORT_DIR
:= $(GENERIC_PLATFORM_DIR
)/backport
$(if
$(wildcard $(GENERIC_PLATFORM_DIR
)/backport-
$(KERNEL_PATCHVER
)),-$(KERNEL_PATCHVER
))
139 GENERIC_PATCH_DIR
:= $(GENERIC_PLATFORM_DIR
)/pending
$(if
$(wildcard $(GENERIC_PLATFORM_DIR
)/pending-
$(KERNEL_PATCHVER
)),-$(KERNEL_PATCHVER
))
140 GENERIC_HACK_DIR
:= $(GENERIC_PLATFORM_DIR
)/hack
$(if
$(wildcard $(GENERIC_PLATFORM_DIR
)/hack-
$(KERNEL_PATCHVER
)),-$(KERNEL_PATCHVER
))
141 GENERIC_FILES_DIR
:= $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR
)/files
$(GENERIC_PLATFORM_DIR
)/files-
$(KERNEL_PATCHVER
)),"$(dir)")
143 __config_name_list
= $(1)/config-
$(KERNEL_PATCHVER
) $(1)/config-default
144 __config_list
= $(firstword $(wildcard $(call __config_name_list
,$(1))))
145 find_kernel_config
=$(if
$(__config_list
),$(__config_list
),$(lastword
$(__config_name_list
)))
147 GENERIC_LINUX_CONFIG
= $(call find_kernel_config
,$(GENERIC_PLATFORM_DIR
))
148 LINUX_TARGET_CONFIG
= $(call find_kernel_config
,$(PLATFORM_DIR
))
149 ifneq ($(PLATFORM_DIR
),$(PLATFORM_SUBDIR
))
150 LINUX_SUBTARGET_CONFIG
= $(call find_kernel_config
,$(PLATFORM_SUBDIR
))
153 # config file list used for compiling
154 LINUX_KCONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_TARGET_CONFIG
) $(LINUX_SUBTARGET_CONFIG
) $(TOPDIR
)/env
/kernel-config
)
156 # default config list for reconfiguring
157 # defaults to subtarget if subtarget exists and target does not
158 # defaults to target otherwise
159 USE_SUBTARGET_CONFIG
= $(if
$(wildcard $(LINUX_TARGET_CONFIG
)),,$(if
$(LINUX_SUBTARGET_CONFIG
),1))
161 LINUX_RECONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_TARGET_CONFIG
) $(if
$(USE_SUBTARGET_CONFIG
),$(LINUX_SUBTARGET_CONFIG
)))
162 LINUX_RECONFIG_TARGET
= $(if
$(USE_SUBTARGET_CONFIG
),$(LINUX_SUBTARGET_CONFIG
),$(LINUX_TARGET_CONFIG
))
164 # select the config file to be changed by kernel_menuconfig/kernel_oldconfig
165 ifeq ($(CONFIG_TARGET
),platform
)
166 LINUX_RECONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_TARGET_CONFIG
))
167 LINUX_RECONFIG_TARGET
= $(LINUX_TARGET_CONFIG
)
169 ifeq ($(CONFIG_TARGET
),subtarget
)
170 LINUX_RECONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_TARGET_CONFIG
) $(LINUX_SUBTARGET_CONFIG
))
171 LINUX_RECONFIG_TARGET
= $(LINUX_SUBTARGET_CONFIG
)
173 ifeq ($(CONFIG_TARGET
),subtarget_platform
)
174 LINUX_RECONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_SUBTARGET_CONFIG
) $(LINUX_TARGET_CONFIG
))
175 LINUX_RECONFIG_TARGET
= $(LINUX_TARGET_CONFIG
)
177 ifeq ($(CONFIG_TARGET
),env
)
178 LINUX_RECONFIG_LIST
= $(LINUX_KCONFIG_LIST
)
179 LINUX_RECONFIG_TARGET
= $(TOPDIR
)/env
/kernel-config
182 __linux_confcmd
= $(SCRIPT_DIR
)/kconfig.pl
$(2) $(patsubst %,+,$(wordlist
2,9999,$(1))) $(1)
184 LINUX_CONF_CMD
= $(call __linux_confcmd
,$(LINUX_KCONFIG_LIST
),)
185 LINUX_RECONF_CMD
= $(call __linux_confcmd
,$(LINUX_RECONFIG_LIST
),)
186 LINUX_RECONF_DIFF
= $(call __linux_confcmd
,$(filter-out $(LINUX_RECONFIG_TARGET
),$(LINUX_RECONFIG_LIST
)),'>')
189 BuildTarget
=$(BuildTargets
/DumpCurrent
)
191 CPU_CFLAGS
= -Os
-pipe
192 ifneq ($(findstring mips
,$(ARCH
)),)
193 ifneq ($(findstring mips64
,$(ARCH
)),)
198 CPU_CFLAGS
+= -mno-branch-likely
199 CPU_CFLAGS_mips32
= -mips32
-mtune
=mips32
200 CPU_CFLAGS_mips64
= -mips64
-mtune
=mips64
-mabi
=64
201 CPU_CFLAGS_mips64r2
= -mips64r2
-mtune
=mips64r2
-mabi
=64
202 CPU_CFLAGS_24kc
= -mips32r2
-mtune
=24kc
203 CPU_CFLAGS_74kc
= -mips32r2
-mtune
=74kc
204 CPU_CFLAGS_octeonplus
= -march
=octeon
+ -mabi
=64
207 CPU_TYPE ?
= pentium-mmx
208 CPU_CFLAGS_pentium-mmx
= -march
=pentium-mmx
209 CPU_CFLAGS_pentium4
= -march
=pentium4
211 ifneq ($(findstring arm
,$(ARCH
)),)
214 ifeq ($(ARCH
),powerpc
)
215 CPU_CFLAGS_603e
:=-mcpu
=603e
216 CPU_CFLAGS_8540
:=-mcpu
=8540
217 CPU_CFLAGS_405
:=-mcpu
=405
218 CPU_CFLAGS_440
:=-mcpu
=440
219 CPU_CFLAGS_464fp
:=-mcpu
=464fp
221 ifeq ($(ARCH
),powerpc64
)
222 CPU_TYPE ?
= powerpc64
223 CPU_CFLAGS_powerpc64
:=-mcpu
=powerpc64
227 CPU_CFLAGS_ultrasparc
= -mcpu
=ultrasparc
229 ifeq ($(ARCH
),aarch64
)
231 CPU_CFLAGS_generic
= -mcpu
=generic
232 CPU_CFLAGS_cortex-a53
= -mcpu
=cortex-a53
236 CPU_CFLAGS
+= -matomic
237 CPU_CFLAGS_arc700
= -mcpu
=arc700
238 CPU_CFLAGS_archs
= -mcpu
=archs
241 ifndef CPU_CFLAGS_
$(CPU_TYPE
)
242 $(warning CPU_TYPE
"$(CPU_TYPE)" doesn
't correspond to a known type)
245 DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
248 TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
249 $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
250 $(LINUX_CONF_CMD) > $@ || rm -f $@
251 -include $(TMP_CONFIG)
252 .SILENT: $(TMP_CONFIG)
253 .PRECIOUS: $(TMP_CONFIG)
255 ifdef KERNEL_TESTING_PATCHVER
256 ifneq ($(KERNEL_TESTING_PATCHVER),$(KERNEL_PATCHVER))
257 FEATURES += testing-kernel
260 ifneq ($(CONFIG_OF),)
263 ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
266 ifneq ($(CONFIG_PCI),)
269 ifneq ($(CONFIG_PCIEPORTBUS),)
272 ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
273 ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
277 ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
280 ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
283 ifneq ($(CONFIG_RTC_CLASS),)
286 ifneq ($(CONFIG_VIRTIO),)
289 ifneq ($(CONFIG_CPU_MIPS32_R2),)
292 FEATURES += $(foreach v,6 7,$(if $(CONFIG_CPU_V$(v)),arm_v$(v)))
295 FEATURES:=$(sort $(FEATURES))
299 CUR_SUBTARGET:=$(SUBTARGET)
300 ifeq ($(SUBTARGETS),)
301 CUR_SUBTARGET := default
304 define BuildTargets/DumpCurrent
306 dumpinfo : export DESCRIPTION=$$(Target/Description)
308 @echo 'Target
: $(TARGETID
)'; \
309 echo 'Target-Board
: $(BOARD
)'; \
310 echo 'Target-Name
: $(BOARDNAME
)$(if
$(SUBTARGETS
),$(if
$(SUBTARGET
),))'; \
311 echo 'Target-Arch
: $(ARCH
)'; \
312 echo 'Target-Arch-Packages
: $(if
$(ARCH_PACKAGES
),$(ARCH_PACKAGES
),$(ARCH
)$(if
$(CPU_TYPE
),_
$(CPU_TYPE
))$(if
$(CPU_SUBTYPE
),_
$(CPU_SUBTYPE
)))'; \
313 echo 'Target-Features
: $(FEATURES
)'; \
314 echo 'Target-Depends
: $(DEPENDS
)'; \
315 echo 'Target-Optimization
: $(if
$(CFLAGS
),$(CFLAGS
),$(DEFAULT_CFLAGS
))'; \
316 echo 'CPU-Type
: $(CPU_TYPE
)$(if
$(CPU_SUBTYPE
),+$(CPU_SUBTYPE
))'; \
317 echo 'Linux-Version
: $(LINUX_VERSION
)'; \
318 $(if $(LINUX_TESTING_VERSION),echo 'Linux-Testing-Version
: $(LINUX_TESTING_VERSION
)';) \
319 echo 'Linux-Release
: $(LINUX_RELEASE
)'; \
320 echo 'Linux-Kernel-Arch
: $(LINUX_KARCH
)'; \
321 $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget
: $(DEFAULT_SUBTARGET
)'; )) \
322 echo 'Target-Description
:'; \
323 echo "$$$$DESCRIPTION"; \
325 echo 'Default-Packages
: $(DEFAULT_PACKAGES
) $(call extra_packages
,$(DEFAULT_PACKAGES
))'; \
327 $(if $(CUR_SUBTARGET),$(SUBMAKE) -r --no-print-directory -C image -s DUMP=1 SUBTARGET=$(CUR_SUBTARGET))
328 $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
331 include $(INCLUDE_DIR)/kernel.mk
332 ifeq ($(TARGET_BUILD),1)
333 include $(INCLUDE_DIR)/kernel-build.mk
334 BuildTarget?=$(BuildKernel)