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
16 DEFAULT_PACKAGES:=base-files libc libgcc busybox dropbear mtd uci opkg netifd fstools uclient-fetch logd
18 DEFAULT_PACKAGES.nas:=block-mount fdisk lsblk mdadm
20 DEFAULT_PACKAGES.router:=dnsmasq iptables ip6tables ppp ppp-mod-pppoe firewall odhcpd odhcp6c
21 DEFAULT_PACKAGES.bootloader:=
27 target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
29 PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
30 SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
32 PLATFORM_DIR:=${CURDIR}
34 SUBTARGETS:=$(strip $(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)))
38 TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
39 PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
41 ifneq ($(TARGET_BUILD),1)
43 include $(PLATFORM_DIR)/Makefile
44 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
45 include $(PLATFORM_SUBDIR)/target.mk
50 -include ./$(SUBTARGET)/target.mk
54 # Add device specific packages (here below to allow device type set from subtarget)
55 DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
57 filter_packages = $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
58 extra_packages = $(if $(filter wpad-mini wpad nas,$(1)),iwinfo)
68 $(eval $(call ProfileDefault))
69 $(eval $(call Profile/$(1)))
70 dumpinfo : $(call shexport,Profile/$(1)/Description)
72 echo "Target-Profile: $(1)"; \
73 $(if $(PRIORITY), echo "Target-Profile-Priority: $(PRIORITY)"; ) \
74 echo "Target-Profile-Name: $(NAME)"; \
75 echo "Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
76 echo "Target-Profile-Description:"; \
77 echo "$$$$$$$$$(call shvar,Profile/$(1)/Description)"; \
83 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
84 define IncludeProfiles
85 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
86 -include $(sort $(wildcard $(PLATFORM_SUBDIR)/profiles/*.mk))
89 define IncludeProfiles
90 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
94 PROFILE:=$(call qstrip,$(CONFIG_TARGET_PROFILE))
96 ifeq ($(TARGET_BUILD),1)
98 $(eval $(call IncludeProfiles))
102 ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
103 include $(INCLUDE_DIR)/kernel-version.mk
106 GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic
107 GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/patches$(if $(wildcard $(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
108 GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
110 __config_name_list = $(1)/config-$(KERNEL_PATCHVER) $(1)/config-default
111 __config_list = $(firstword $(wildcard $(call __config_name_list,$(1))))
112 find_kernel_config=$(if $(__config_list),$(__config_list),$(lastword $(__config_name_list)))
114 GENERIC_LINUX_CONFIG = $(call find_kernel_config,$(GENERIC_PLATFORM_DIR))
115 LINUX_TARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_DIR))
116 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
117 LINUX_SUBTARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_SUBDIR))
120 # config file list used for compiling
121 LINUX_KCONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(TOPDIR)/env/kernel-config)
123 # default config list for reconfiguring
124 # defaults to subtarget if subtarget exists and target does not
125 # defaults to target otherwise
126 USE_SUBTARGET_CONFIG = $(if $(wildcard $(LINUX_TARGET_CONFIG)),,$(if $(LINUX_SUBTARGET_CONFIG),1))
128 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG)))
129 LINUX_RECONFIG_TARGET = $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG),$(LINUX_TARGET_CONFIG))
131 # select the config file to be changed by kernel_menuconfig/kernel_oldconfig
132 ifeq ($(CONFIG_TARGET),platform)
133 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG))
134 LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
136 ifeq ($(CONFIG_TARGET),subtarget)
137 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG))
138 LINUX_RECONFIG_TARGET = $(LINUX_SUBTARGET_CONFIG)
140 ifeq ($(CONFIG_TARGET),subtarget_platform)
141 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(LINUX_TARGET_CONFIG))
142 LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
144 ifeq ($(CONFIG_TARGET),env)
145 LINUX_RECONFIG_LIST = $(LINUX_KCONFIG_LIST)
146 LINUX_RECONFIG_TARGET = $(TOPDIR)/env/kernel-config
149 __linux_confcmd = $(SCRIPT_DIR)/kconfig.pl $(2) $(patsubst %,+,$(wordlist 2,9999,$(1))) $(1)
151 LINUX_CONF_CMD = $(call __linux_confcmd,$(LINUX_KCONFIG_LIST),)
152 LINUX_RECONF_CMD = $(call __linux_confcmd,$(LINUX_RECONFIG_LIST),)
153 LINUX_RECONF_DIFF = $(call __linux_confcmd,$(filter-out $(LINUX_RECONFIG_TARGET),$(LINUX_RECONFIG_LIST)),'>')
156 BuildTarget=$(BuildTargets/DumpCurrent)
159 TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
160 $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
161 $(LINUX_CONF_CMD) > $@ || rm -f $@
162 -include $(TMP_CONFIG)
163 .SILENT: $(TMP_CONFIG)
164 .PRECIOUS: $(TMP_CONFIG)
166 ifneq ($(CONFIG_OF),)
169 ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
172 ifneq ($(CONFIG_PCI),)
175 ifneq ($(CONFIG_PCIEPORTBUS),)
178 ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
179 ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
183 ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
186 ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
189 ifneq ($(CONFIG_RTC_CLASS),)
192 FEATURES += $(foreach v,v4 v5 v6 v7,$(if $(findstring -march=arm$(v),$(CFLAGS)),arm_$(v)))
195 FEATURES:=$(sort $(FEATURES))
197 CPU_CFLAGS = -Os -pipe
198 ifneq ($(findstring mips,$(ARCH)),)
199 ifneq ($(findstring mips64,$(ARCH)),)
204 CPU_CFLAGS += -mno-branch-likely
205 CPU_CFLAGS_mips32 = -mips32 -mtune=mips32
206 CPU_CFLAGS_mips32r2 = -mips32r2 -mtune=mips32r2
207 CPU_CFLAGS_mips64 = -mips64 -mtune=mips64 -mabi=64
208 CPU_CFLAGS_24kc = -mips32r2 -mtune=24kc
209 CPU_CFLAGS_24kec = -mips32r2 -mtune=24kec
210 CPU_CFLAGS_34kc = -mips32r2 -mtune=34kc
211 CPU_CFLAGS_74kc = -mips32r2 -mtune=74kc
212 CPU_CFLAGS_1004kc = -mips32r2 -mtune=1004kc
213 CPU_CFLAGS_octeon = -march=octeon -mabi=64
214 CPU_CFLAGS_dsp = -mdsp
215 CPU_CFLAGS_dsp2 = -mdspr2
219 CPU_CFLAGS_i486 = -march=i486
220 CPU_CFLAGS_pentium4 = -march=pentium4
221 CPU_CFLAGS_geode = -march=geode -mmmx -m3dnow
223 ifneq ($(findstring arm,$(ARCH)),)
225 CPU_CFLAGS_arm920t = -march=armv4t -mtune=arm920t
226 CPU_CFLAGS_arm926ej-s = -march=armv5te -mtune=arm926ej-s
227 CPU_CFLAGS_arm1136j-s = -march=armv6 -mtune=arm1136j-s
228 CPU_CFLAGS_arm1176jzf-s = -march=armv6 -mtune=arm1176jzf-s
229 CPU_CFLAGS_cortex-a5 = -march=armv7-a -mtune=cortex-a5
230 CPU_CFLAGS_cortex-a7 = -march=armv7-a -mtune=cortex-a7
231 CPU_CFLAGS_cortex-a8 = -march=armv7-a -mtune=cortex-a8
232 CPU_CFLAGS_cortex-a9 = -march=armv7-a -mtune=cortex-a9
233 CPU_CFLAGS_cortex-a15 = -march=armv7-a -mtune=cortex-a15
234 CPU_CFLAGS_cortex-a53 = -march=armv8-a -mtune=cortex-a53
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
242 CPU_CFLAGS_neon-vfpv4 = -mfpu=neon-vfpv4
245 ifeq ($(ARCH),powerpc)
246 CPU_CFLAGS_603e:=-mcpu=603e
247 CPU_CFLAGS_8540:=-mcpu=8540
248 CPU_CFLAGS_405:=-mcpu=405
249 CPU_CFLAGS_440:=-mcpu=440
253 CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc
255 ifeq ($(ARCH),aarch64)
257 CPU_CFLAGS_armv8-a = -mcpu=armv8-a
261 CPU_CFLAGS += -matomic
262 CPU_CFLAGS_arc700 = -marc700
263 CPU_CFLAGS_archs = -marchs
265 DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
268 CUR_SUBTARGET:=$(SUBTARGET)
269 ifeq ($(SUBTARGETS),)
270 CUR_SUBTARGET := default
273 define BuildTargets/DumpCurrent
275 dumpinfo : export DESCRIPTION=$$(Target/Description)
277 @echo 'Target: $(TARGETID)'; \
278 echo 'Target-Board: $(BOARD)'; \
279 echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \
280 echo 'Target-Arch: $(ARCH)'; \
281 echo 'Target-Arch-Packages: $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(ARCH)$(if $(CPU_TYPE),_$(CPU_TYPE))$(if $(CPU_SUBTYPE),_$(CPU_SUBTYPE)))'; \
282 echo 'Target-Features: $(FEATURES)'; \
283 echo 'Target-Depends: $(DEPENDS)'; \
284 echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
285 echo 'CPU-Type: $(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))'; \
286 echo 'Linux-Version: $(LINUX_VERSION)'; \
287 echo 'Linux-Release: $(LINUX_RELEASE)'; \
288 echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
289 $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; )) \
290 echo 'Target-Description:'; \
291 echo "$$$$DESCRIPTION"; \
293 echo 'Default-Packages: $(DEFAULT_PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES))'; \
295 $(if $(CUR_SUBTARGET),$(SUBMAKE) -r --no-print-directory -C image -s DUMP=1 SUBTARGET=$(CUR_SUBTARGET))
296 $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
299 include $(INCLUDE_DIR)/kernel.mk
300 ifeq ($(TARGET_BUILD),1)
301 include $(INCLUDE_DIR)/kernel-build.mk
302 BuildTarget?=$(BuildKernel)