1 # SPDX-License-Identifier: GPL-2.0-only
3 # Copyright (C) 2007-2008 OpenWrt.org
4 # Copyright (C) 2016 LEDE Project
6 ifneq ($(__target_inc
),1)
12 # Default packages - the really basic set
32 DEFAULT_PACKAGES
+=opkg
35 ifneq ($(CONFIG_SELINUX
),)
36 DEFAULT_PACKAGES
+=busybox-selinux procd-selinux
38 DEFAULT_PACKAGES
+=busybox procd
41 # include ujail on systems with enough storage
42 ifeq ($(CONFIG_SMALL_FLASH
),)
43 DEFAULT_PACKAGES
+=procd-ujail
46 # include seccomp ld-preload hooks if kernel supports it
47 ifneq ($(CONFIG_SECCOMP
),)
48 DEFAULT_PACKAGES
+=procd-seccomp
52 DEFAULT_PACKAGES.basic
:=
54 DEFAULT_PACKAGES.nas
:=\
60 DEFAULT_PACKAGES.router
:=\
74 target_conf
=$(subst .
,_
,$(subst -,_
,$(subst /,_
,$(1))))
76 PLATFORM_DIR
:=$(firstword $(wildcard $(TOPDIR
)/target
/linux
/feeds
/$(BOARD
) $(TOPDIR
)/target
/linux
/$(BOARD
)))
77 SUBTARGET
:=$(strip $(foreach subdir
,$(patsubst $(PLATFORM_DIR
)/%/target.mk
,%,$(wildcard $(PLATFORM_DIR
)/*/target.mk
)),$(if
$(CONFIG_TARGET_
$(call target_conf
,$(BOARD
)_
$(subdir
))),$(subdir
))))
79 PLATFORM_DIR
:=${CURDIR}
81 SUBTARGETS
:=$(strip $(patsubst $(PLATFORM_DIR
)/%/target.mk
,%,$(wildcard $(PLATFORM_DIR
)/*/target.mk
)))
85 TARGETID
:=$(BOARD
)$(if
$(SUBTARGET
),/$(SUBTARGET
))
86 PLATFORM_SUBDIR
:=$(PLATFORM_DIR
)$(if
$(SUBTARGET
),/$(SUBTARGET
))
88 ifneq ($(TARGET_BUILD
),1)
90 include $(PLATFORM_DIR
)/Makefile
91 ifneq ($(PLATFORM_DIR
),$(PLATFORM_SUBDIR
))
92 include $(PLATFORM_SUBDIR
)/target.mk
97 -include .
/$(SUBTARGET
)/target.mk
101 # Add device specific packages (here below to allow device type set from subtarget)
102 DEFAULT_PACKAGES
+= $(DEFAULT_PACKAGES.
$(DEVICE_TYPE
))
104 filter_packages
= $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
105 extra_packages
= $(if
$(filter wpad wpad-
% nas
,$(1)),iwinfo
)
107 define ProfileDefault
115 $(eval
$(call ProfileDefault
))
116 $(eval
$(call Profile
/$(1)))
117 dumpinfo
: $(call shexport
,Profile
/$(1)/Description
)
118 PACKAGES
:= $(filter-out -%,$(PACKAGES
))
120 echo
"Target-Profile: $(1)"; \
121 $(if
$(PRIORITY
), echo
"Target-Profile-Priority: $(PRIORITY)"; ) \
122 echo
"Target-Profile-Name: $(NAME)"; \
123 echo
"Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
124 echo
"Target-Profile-Description:"; \
125 echo
"$$$$$$$$$(call shvar,Profile/$(1)/Description)"; \
131 ifneq ($(PLATFORM_DIR
),$(PLATFORM_SUBDIR
))
132 define IncludeProfiles
133 -include $(sort $(wildcard $(PLATFORM_DIR
)/profiles
/*.mk
))
134 -include $(sort $(wildcard $(PLATFORM_SUBDIR
)/profiles
/*.mk
))
137 define IncludeProfiles
138 -include $(sort $(wildcard $(PLATFORM_DIR
)/profiles
/*.mk
))
142 PROFILE?
=$(call qstrip
,$(CONFIG_TARGET_PROFILE
))
144 ifeq ($(TARGET_BUILD
),1)
146 $(eval
$(call IncludeProfiles
))
150 ifneq ($(TARGET_BUILD
)$(if
$(DUMP
),,1),)
151 include $(INCLUDE_DIR
)/kernel-version.mk
154 GENERIC_PLATFORM_DIR
:= $(TOPDIR
)/target
/linux
/generic
155 GENERIC_BACKPORT_DIR
:= $(GENERIC_PLATFORM_DIR
)/backport
$(if
$(wildcard $(GENERIC_PLATFORM_DIR
)/backport-
$(KERNEL_PATCHVER
)),-$(KERNEL_PATCHVER
))
156 GENERIC_PATCH_DIR
:= $(GENERIC_PLATFORM_DIR
)/pending
$(if
$(wildcard $(GENERIC_PLATFORM_DIR
)/pending-
$(KERNEL_PATCHVER
)),-$(KERNEL_PATCHVER
))
157 GENERIC_HACK_DIR
:= $(GENERIC_PLATFORM_DIR
)/hack
$(if
$(wildcard $(GENERIC_PLATFORM_DIR
)/hack-
$(KERNEL_PATCHVER
)),-$(KERNEL_PATCHVER
))
158 GENERIC_FILES_DIR
:= $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR
)/files
$(GENERIC_PLATFORM_DIR
)/files-
$(KERNEL_PATCHVER
)),"$(dir)")
160 __config_name_list
= $(1)/config-
$(KERNEL_PATCHVER
) $(1)/config-default
161 __config_list
= $(firstword $(wildcard $(call __config_name_list
,$(1))))
162 find_kernel_config
=$(if
$(__config_list
),$(__config_list
),$(lastword
$(__config_name_list
)))
164 GENERIC_LINUX_CONFIG
= $(call find_kernel_config
,$(GENERIC_PLATFORM_DIR
))
165 LINUX_TARGET_CONFIG
= $(call find_kernel_config
,$(PLATFORM_DIR
))
166 ifneq ($(PLATFORM_DIR
),$(PLATFORM_SUBDIR
))
167 LINUX_SUBTARGET_CONFIG
= $(call find_kernel_config
,$(PLATFORM_SUBDIR
))
170 # config file list used for compiling
171 LINUX_KCONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_TARGET_CONFIG
) $(LINUX_SUBTARGET_CONFIG
) $(TOPDIR
)/env
/kernel-config
)
173 # default config list for reconfiguring
174 # defaults to subtarget if subtarget exists and target does not
175 # defaults to target otherwise
176 USE_SUBTARGET_CONFIG
= $(if
$(wildcard $(LINUX_TARGET_CONFIG
)),,$(if
$(LINUX_SUBTARGET_CONFIG
),1))
178 LINUX_RECONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_TARGET_CONFIG
) $(if
$(USE_SUBTARGET_CONFIG
),$(LINUX_SUBTARGET_CONFIG
)))
179 LINUX_RECONFIG_TARGET
= $(if
$(USE_SUBTARGET_CONFIG
),$(LINUX_SUBTARGET_CONFIG
),$(LINUX_TARGET_CONFIG
))
181 CFG_TARGET
= $(CONFIG_TARGET
)
182 ifeq ($(CFG_TARGET
),platform
)
184 $(warning Deprecation warning
: use CONFIG_TARGET
=target instead.
)
185 else ifeq ($(CFG_TARGET
),subtarget_platform
)
186 CFG_TARGET
= subtarget_target
187 $(warning Deprecation warning
: use CONFIG_TARGET
=subtarget_target instead.
)
190 # select the config file to be changed by kernel_menuconfig/kernel_oldconfig
191 ifeq ($(CFG_TARGET
),target
)
192 LINUX_RECONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_TARGET_CONFIG
))
193 LINUX_RECONFIG_TARGET
= $(LINUX_TARGET_CONFIG
)
194 else ifeq ($(CFG_TARGET
),subtarget
)
195 LINUX_RECONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_TARGET_CONFIG
) $(LINUX_SUBTARGET_CONFIG
))
196 LINUX_RECONFIG_TARGET
= $(LINUX_SUBTARGET_CONFIG
)
197 else ifeq ($(CFG_TARGET
),subtarget_target
)
198 LINUX_RECONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_SUBTARGET_CONFIG
) $(LINUX_TARGET_CONFIG
))
199 LINUX_RECONFIG_TARGET
= $(LINUX_TARGET_CONFIG
)
200 else ifeq ($(CFG_TARGET
),env
)
201 LINUX_RECONFIG_LIST
= $(LINUX_KCONFIG_LIST
)
202 LINUX_RECONFIG_TARGET
= $(TOPDIR
)/env
/kernel-config
203 else ifneq ($(strip $(CFG_TARGET
)),)
204 $(error CONFIG_TARGET
=$(CFG_TARGET
) is invalid. Valid
: target|subtarget|subtarget_target|env
)
207 __linux_confcmd
= $(2) $(patsubst %,+,$(wordlist
2,9999,$(1))) $(1)
209 LINUX_CONF_CMD
= $(SCRIPT_DIR
)/kconfig.pl
$(call __linux_confcmd
,$(LINUX_KCONFIG_LIST
))
210 LINUX_RECONF_CMD
= $(SCRIPT_DIR
)/kconfig.pl
$(call __linux_confcmd
,$(LINUX_RECONFIG_LIST
))
211 LINUX_RECONF_DIFF
= $(SCRIPT_DIR
)/kconfig.pl
- '>' $(call __linux_confcmd
,$(filter-out $(LINUX_RECONFIG_TARGET
),$(LINUX_RECONFIG_LIST
))) $(1) $(GENERIC_PLATFORM_DIR
)/config-filter
214 BuildTarget
=$(BuildTargets
/DumpCurrent
)
216 CPU_CFLAGS
= -Os
-pipe
217 ifneq ($(findstring mips
,$(ARCH
)),)
218 ifneq ($(findstring mips64
,$(ARCH
)),)
223 CPU_CFLAGS
+= -mno-branch-likely
224 CPU_CFLAGS_mips32
= -mips32
-mtune
=mips32
225 CPU_CFLAGS_mips64
= -mips64
-mtune
=mips64
-mabi
=64
226 CPU_CFLAGS_mips64r2
= -mips64r2
-mtune
=mips64r2
-mabi
=64
227 CPU_CFLAGS_4kec
= -mips32r2
-mtune
=4kec
228 CPU_CFLAGS_24kc
= -mips32r2
-mtune
=24kc
229 CPU_CFLAGS_74kc
= -mips32r2
-mtune
=74kc
230 CPU_CFLAGS_octeonplus
= -march
=octeon
+ -mabi
=64
233 CPU_TYPE ?
= pentium-mmx
234 CPU_CFLAGS_pentium-mmx
= -march
=pentium-mmx
235 CPU_CFLAGS_pentium4
= -march
=pentium4
237 ifneq ($(findstring arm
,$(ARCH
)),)
240 ifeq ($(ARCH
),powerpc
)
241 CPU_CFLAGS_603e
:=-mcpu
=603e
242 CPU_CFLAGS_8540
:=-mcpu
=8540
243 CPU_CFLAGS_8548
:=-mcpu
=8548
244 CPU_CFLAGS_405
:=-mcpu
=405
245 CPU_CFLAGS_440
:=-mcpu
=440
246 CPU_CFLAGS_464fp
:=-mcpu
=464fp
248 ifeq ($(ARCH
),powerpc64
)
249 CPU_TYPE ?
= powerpc64
250 CPU_CFLAGS_e5500
:=-mcpu
=e5500
251 CPU_CFLAGS_powerpc64
:=-mcpu
=powerpc64
255 CPU_CFLAGS_ultrasparc
= -mcpu
=ultrasparc
257 ifeq ($(ARCH
),aarch64
)
259 CPU_CFLAGS_generic
= -mcpu
=generic
260 CPU_CFLAGS_cortex-a53
= -mcpu
=cortex-a53
264 CPU_CFLAGS
+= -matomic
265 CPU_CFLAGS_arc700
= -mcpu
=arc700
266 CPU_CFLAGS_archs
= -mcpu
=archs
268 ifeq ($(ARCH
),riscv64
)
270 CPU_CFLAGS_riscv64
:=-mabi
=lp64d
-march
=rv64imafdc
272 ifeq ($(ARCH
),loongarch64
)
274 CPU_CFLAGS
:= -O2
-pipe
275 CPU_CFLAGS_generic
:=-march
=loongarch64
278 ifndef CPU_CFLAGS_
$(CPU_TYPE
)
279 $(warning CPU_TYPE
"$(CPU_TYPE)" doesn
't correspond to a known type)
282 DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
285 TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
286 $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
287 $(LINUX_CONF_CMD) > $@ || rm -f $@
288 -include $(TMP_CONFIG)
289 .SILENT: $(TMP_CONFIG)
290 .PRECIOUS: $(TMP_CONFIG)
292 ifdef KERNEL_TESTING_PATCHVER
293 ifneq ($(KERNEL_TESTING_PATCHVER),$(KERNEL_PATCHVER))
294 FEATURES += testing-kernel
297 ifneq ($(CONFIG_OF),)
300 ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
303 ifneq ($(CONFIG_PCI),)
306 ifneq ($(CONFIG_PCIEPORTBUS),)
309 ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
310 ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
314 ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
317 ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
320 ifneq ($(CONFIG_RTC_CLASS),)
323 ifneq ($(CONFIG_VIRTIO),)
326 ifneq ($(CONFIG_CPU_MIPS32_R2),)
329 FEATURES += $(foreach v,6 7,$(if $(CONFIG_CPU_V$(v)),arm_v$(v)))
332 FEATURES:=$(sort $(FEATURES))
336 CUR_SUBTARGET:=$(SUBTARGET)
337 ifeq ($(SUBTARGETS),)
338 CUR_SUBTARGET := default
341 define BuildTargets/DumpCurrent
343 dumpinfo : export DESCRIPTION=$$(Target/Description)
345 @echo 'Target
: $(TARGETID
)'; \
346 echo 'Target-Board
: $(BOARD
)'; \
347 echo 'Target-Name
: $(BOARDNAME
)$(if
$(SUBTARGETS
),$(if
$(SUBTARGET
),))'; \
348 echo 'Target-Arch
: $(ARCH
)'; \
349 echo 'Target-Arch-Packages
: $(if
$(ARCH_PACKAGES
),$(ARCH_PACKAGES
),$(ARCH
)$(if
$(CPU_TYPE
),_
$(CPU_TYPE
))$(if
$(CPU_SUBTYPE
),_
$(CPU_SUBTYPE
)))'; \
350 echo 'Target-Features
: $(FEATURES
)'; \
351 echo 'Target-Depends
: $(DEPENDS
)'; \
352 echo 'Target-Optimization
: $(if
$(CFLAGS
),$(CFLAGS
),$(DEFAULT_CFLAGS
))'; \
353 echo 'CPU-Type
: $(CPU_TYPE
)$(if
$(CPU_SUBTYPE
),+$(CPU_SUBTYPE
))'; \
354 echo 'Linux-Version
: $(LINUX_VERSION
)'; \
355 $(if $(LINUX_TESTING_VERSION),echo 'Linux-Testing-Version
: $(LINUX_TESTING_VERSION
)';) \
356 echo 'Linux-Release
: $(LINUX_RELEASE
)'; \
357 echo 'Linux-Kernel-Arch
: $(LINUX_KARCH
)'; \
358 $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget
: $(DEFAULT_SUBTARGET
)'; )) \
359 echo 'Target-Description
:'; \
360 echo "$$$$DESCRIPTION"; \
362 echo 'Default-Packages
: $(DEFAULT_PACKAGES
) $(call extra_packages
,$(DEFAULT_PACKAGES
))'; \
364 $(if $(CUR_SUBTARGET),$(SUBMAKE) -r --no-print-directory -C image -s DUMP=1 SUBTARGET=$(CUR_SUBTARGET))
365 $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
368 include $(INCLUDE_DIR)/kernel.mk
369 ifeq ($(TARGET_BUILD),1)
370 include $(INCLUDE_DIR)/kernel-build.mk
371 BuildTarget?=$(BuildKernel)