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
30 ifneq ($(CONFIG_SELINUX
),)
31 DEFAULT_PACKAGES
+=busybox-selinux procd-selinux
33 DEFAULT_PACKAGES
+=busybox procd
36 # include ujail on systems with enough storage
37 ifeq ($(CONFIG_SMALL_FLASH
),)
38 DEFAULT_PACKAGES
+=procd-ujail
41 # include seccomp ld-preload hooks if kernel supports it
42 ifneq ($(CONFIG_SECCOMP
),)
43 DEFAULT_PACKAGES
+=procd-seccomp
47 DEFAULT_PACKAGES.basic
:=
49 DEFAULT_PACKAGES.nas
:=\
55 DEFAULT_PACKAGES.router
:=\
69 target_conf
=$(subst .
,_
,$(subst -,_
,$(subst /,_
,$(1))))
71 PLATFORM_DIR
:=$(TOPDIR
)/target
/linux
/$(BOARD
)
72 SUBTARGET
:=$(strip $(foreach subdir
,$(patsubst $(PLATFORM_DIR
)/%/target.mk
,%,$(wildcard $(PLATFORM_DIR
)/*/target.mk
)),$(if
$(CONFIG_TARGET_
$(call target_conf
,$(BOARD
)_
$(subdir
))),$(subdir
))))
74 PLATFORM_DIR
:=${CURDIR}
76 SUBTARGETS
:=$(strip $(patsubst $(PLATFORM_DIR
)/%/target.mk
,%,$(wildcard $(PLATFORM_DIR
)/*/target.mk
)))
80 TARGETID
:=$(BOARD
)$(if
$(SUBTARGET
),/$(SUBTARGET
))
81 PLATFORM_SUBDIR
:=$(PLATFORM_DIR
)$(if
$(SUBTARGET
),/$(SUBTARGET
))
83 ifneq ($(TARGET_BUILD
),1)
85 include $(PLATFORM_DIR
)/Makefile
86 ifneq ($(PLATFORM_DIR
),$(PLATFORM_SUBDIR
))
87 include $(PLATFORM_SUBDIR
)/target.mk
92 -include .
/$(SUBTARGET
)/target.mk
96 # Add device specific packages (here below to allow device type set from subtarget)
97 DEFAULT_PACKAGES
+= $(DEFAULT_PACKAGES.
$(DEVICE_TYPE
))
99 filter_packages
= $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
100 extra_packages
= $(if
$(filter wpad wpad-
% nas
,$(1)),iwinfo
)
102 define ProfileDefault
110 $(eval
$(call ProfileDefault
))
111 $(eval
$(call Profile
/$(1)))
112 dumpinfo
: $(call shexport
,Profile
/$(1)/Description
)
113 PACKAGES
:= $(filter-out -%,$(PACKAGES
))
115 echo
"Target-Profile: $(1)"; \
116 $(if
$(PRIORITY
), echo
"Target-Profile-Priority: $(PRIORITY)"; ) \
117 echo
"Target-Profile-Name: $(NAME)"; \
118 echo
"Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
119 echo
"Target-Profile-Description:"; \
120 echo
"$$$$$$$$$(call shvar,Profile/$(1)/Description)"; \
126 ifneq ($(PLATFORM_DIR
),$(PLATFORM_SUBDIR
))
127 define IncludeProfiles
128 -include $(sort $(wildcard $(PLATFORM_DIR
)/profiles
/*.mk
))
129 -include $(sort $(wildcard $(PLATFORM_SUBDIR
)/profiles
/*.mk
))
132 define IncludeProfiles
133 -include $(sort $(wildcard $(PLATFORM_DIR
)/profiles
/*.mk
))
137 PROFILE?
=$(call qstrip
,$(CONFIG_TARGET_PROFILE
))
139 ifeq ($(TARGET_BUILD
),1)
141 $(eval
$(call IncludeProfiles
))
145 ifneq ($(TARGET_BUILD
)$(if
$(DUMP
),,1),)
146 include $(INCLUDE_DIR
)/kernel-version.mk
149 GENERIC_PLATFORM_DIR
:= $(TOPDIR
)/target
/linux
/generic
150 GENERIC_BACKPORT_DIR
:= $(GENERIC_PLATFORM_DIR
)/backport
$(if
$(wildcard $(GENERIC_PLATFORM_DIR
)/backport-
$(KERNEL_PATCHVER
)),-$(KERNEL_PATCHVER
))
151 GENERIC_PATCH_DIR
:= $(GENERIC_PLATFORM_DIR
)/pending
$(if
$(wildcard $(GENERIC_PLATFORM_DIR
)/pending-
$(KERNEL_PATCHVER
)),-$(KERNEL_PATCHVER
))
152 GENERIC_HACK_DIR
:= $(GENERIC_PLATFORM_DIR
)/hack
$(if
$(wildcard $(GENERIC_PLATFORM_DIR
)/hack-
$(KERNEL_PATCHVER
)),-$(KERNEL_PATCHVER
))
153 GENERIC_FILES_DIR
:= $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR
)/files
$(GENERIC_PLATFORM_DIR
)/files-
$(KERNEL_PATCHVER
)),"$(dir)")
155 __config_name_list
= $(1)/config-
$(KERNEL_PATCHVER
) $(1)/config-default
156 __config_list
= $(firstword $(wildcard $(call __config_name_list
,$(1))))
157 find_kernel_config
=$(if
$(__config_list
),$(__config_list
),$(lastword
$(__config_name_list
)))
159 GENERIC_LINUX_CONFIG
= $(call find_kernel_config
,$(GENERIC_PLATFORM_DIR
))
160 LINUX_TARGET_CONFIG
= $(call find_kernel_config
,$(PLATFORM_DIR
))
161 ifneq ($(PLATFORM_DIR
),$(PLATFORM_SUBDIR
))
162 LINUX_SUBTARGET_CONFIG
= $(call find_kernel_config
,$(PLATFORM_SUBDIR
))
165 # config file list used for compiling
166 LINUX_KCONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_TARGET_CONFIG
) $(LINUX_SUBTARGET_CONFIG
) $(TOPDIR
)/env
/kernel-config
)
168 # default config list for reconfiguring
169 # defaults to subtarget if subtarget exists and target does not
170 # defaults to target otherwise
171 USE_SUBTARGET_CONFIG
= $(if
$(wildcard $(LINUX_TARGET_CONFIG
)),,$(if
$(LINUX_SUBTARGET_CONFIG
),1))
173 LINUX_RECONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_TARGET_CONFIG
) $(if
$(USE_SUBTARGET_CONFIG
),$(LINUX_SUBTARGET_CONFIG
)))
174 LINUX_RECONFIG_TARGET
= $(if
$(USE_SUBTARGET_CONFIG
),$(LINUX_SUBTARGET_CONFIG
),$(LINUX_TARGET_CONFIG
))
176 # select the config file to be changed by kernel_menuconfig/kernel_oldconfig
177 ifeq ($(CONFIG_TARGET
),platform
)
178 LINUX_RECONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_TARGET_CONFIG
))
179 LINUX_RECONFIG_TARGET
= $(LINUX_TARGET_CONFIG
)
181 ifeq ($(CONFIG_TARGET
),subtarget
)
182 LINUX_RECONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_TARGET_CONFIG
) $(LINUX_SUBTARGET_CONFIG
))
183 LINUX_RECONFIG_TARGET
= $(LINUX_SUBTARGET_CONFIG
)
185 ifeq ($(CONFIG_TARGET
),subtarget_platform
)
186 LINUX_RECONFIG_LIST
= $(wildcard $(GENERIC_LINUX_CONFIG
) $(LINUX_SUBTARGET_CONFIG
) $(LINUX_TARGET_CONFIG
))
187 LINUX_RECONFIG_TARGET
= $(LINUX_TARGET_CONFIG
)
189 ifeq ($(CONFIG_TARGET
),env
)
190 LINUX_RECONFIG_LIST
= $(LINUX_KCONFIG_LIST
)
191 LINUX_RECONFIG_TARGET
= $(TOPDIR
)/env
/kernel-config
194 __linux_confcmd
= $(2) $(patsubst %,+,$(wordlist
2,9999,$(1))) $(1)
196 LINUX_CONF_CMD
= $(SCRIPT_DIR
)/kconfig.pl
$(call __linux_confcmd
,$(LINUX_KCONFIG_LIST
))
197 LINUX_RECONF_CMD
= $(SCRIPT_DIR
)/kconfig.pl
$(call __linux_confcmd
,$(LINUX_RECONFIG_LIST
))
198 LINUX_RECONF_DIFF
= $(SCRIPT_DIR
)/kconfig.pl
- '>' $(call __linux_confcmd
,$(filter-out $(LINUX_RECONFIG_TARGET
),$(LINUX_RECONFIG_LIST
))) $(1) $(GENERIC_PLATFORM_DIR
)/config-filter
201 BuildTarget
=$(BuildTargets
/DumpCurrent
)
203 CPU_CFLAGS
= -Os
-pipe
204 ifneq ($(findstring mips
,$(ARCH
)),)
205 ifneq ($(findstring mips64
,$(ARCH
)),)
210 CPU_CFLAGS
+= -mno-branch-likely
211 CPU_CFLAGS_mips32
= -mips32
-mtune
=mips32
212 CPU_CFLAGS_mips64
= -mips64
-mtune
=mips64
-mabi
=64
213 CPU_CFLAGS_mips64r2
= -mips64r2
-mtune
=mips64r2
-mabi
=64
214 CPU_CFLAGS_4kec
= -mips32r2
-mtune
=4kec
215 CPU_CFLAGS_24kc
= -mips32r2
-mtune
=24kc
216 CPU_CFLAGS_74kc
= -mips32r2
-mtune
=74kc
217 CPU_CFLAGS_octeonplus
= -march
=octeon
+ -mabi
=64
220 CPU_TYPE ?
= pentium-mmx
221 CPU_CFLAGS_pentium-mmx
= -march
=pentium-mmx
222 CPU_CFLAGS_pentium4
= -march
=pentium4
224 ifneq ($(findstring arm
,$(ARCH
)),)
227 ifeq ($(ARCH
),powerpc
)
228 CPU_CFLAGS_603e
:=-mcpu
=603e
229 CPU_CFLAGS_8540
:=-mcpu
=8540
230 CPU_CFLAGS_405
:=-mcpu
=405
231 CPU_CFLAGS_440
:=-mcpu
=440
232 CPU_CFLAGS_464fp
:=-mcpu
=464fp
234 ifeq ($(ARCH
),powerpc64
)
235 CPU_TYPE ?
= powerpc64
236 CPU_CFLAGS_e5500
:=-mcpu
=e5500
237 CPU_CFLAGS_powerpc64
:=-mcpu
=powerpc64
241 CPU_CFLAGS_ultrasparc
= -mcpu
=ultrasparc
243 ifeq ($(ARCH
),aarch64
)
245 CPU_CFLAGS_generic
= -mcpu
=generic
246 CPU_CFLAGS_cortex-a53
= -mcpu
=cortex-a53
250 CPU_CFLAGS
+= -matomic
251 CPU_CFLAGS_arc700
= -mcpu
=arc700
252 CPU_CFLAGS_archs
= -mcpu
=archs
255 ifndef CPU_CFLAGS_
$(CPU_TYPE
)
256 $(warning CPU_TYPE
"$(CPU_TYPE)" doesn
't correspond to a known type)
259 DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
262 TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
263 $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
264 $(LINUX_CONF_CMD) > $@ || rm -f $@
265 -include $(TMP_CONFIG)
266 .SILENT: $(TMP_CONFIG)
267 .PRECIOUS: $(TMP_CONFIG)
269 ifdef KERNEL_TESTING_PATCHVER
270 ifneq ($(KERNEL_TESTING_PATCHVER),$(KERNEL_PATCHVER))
271 FEATURES += testing-kernel
274 ifneq ($(CONFIG_OF),)
277 ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
280 ifneq ($(CONFIG_PCI),)
283 ifneq ($(CONFIG_PCIEPORTBUS),)
286 ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
287 ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
291 ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
294 ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
297 ifneq ($(CONFIG_RTC_CLASS),)
300 ifneq ($(CONFIG_VIRTIO),)
303 ifneq ($(CONFIG_CPU_MIPS32_R2),)
306 FEATURES += $(foreach v,6 7,$(if $(CONFIG_CPU_V$(v)),arm_v$(v)))
309 FEATURES:=$(sort $(FEATURES))
313 CUR_SUBTARGET:=$(SUBTARGET)
314 ifeq ($(SUBTARGETS),)
315 CUR_SUBTARGET := default
318 define BuildTargets/DumpCurrent
320 dumpinfo : export DESCRIPTION=$$(Target/Description)
322 @echo 'Target
: $(TARGETID
)'; \
323 echo 'Target-Board
: $(BOARD
)'; \
324 echo 'Target-Name
: $(BOARDNAME
)$(if
$(SUBTARGETS
),$(if
$(SUBTARGET
),))'; \
325 echo 'Target-Arch
: $(ARCH
)'; \
326 echo 'Target-Arch-Packages
: $(if
$(ARCH_PACKAGES
),$(ARCH_PACKAGES
),$(ARCH
)$(if
$(CPU_TYPE
),_
$(CPU_TYPE
))$(if
$(CPU_SUBTYPE
),_
$(CPU_SUBTYPE
)))'; \
327 echo 'Target-Features
: $(FEATURES
)'; \
328 echo 'Target-Depends
: $(DEPENDS
)'; \
329 echo 'Target-Optimization
: $(if
$(CFLAGS
),$(CFLAGS
),$(DEFAULT_CFLAGS
))'; \
330 echo 'CPU-Type
: $(CPU_TYPE
)$(if
$(CPU_SUBTYPE
),+$(CPU_SUBTYPE
))'; \
331 echo 'Linux-Version
: $(LINUX_VERSION
)'; \
332 $(if $(LINUX_TESTING_VERSION),echo 'Linux-Testing-Version
: $(LINUX_TESTING_VERSION
)';) \
333 echo 'Linux-Release
: $(LINUX_RELEASE
)'; \
334 echo 'Linux-Kernel-Arch
: $(LINUX_KARCH
)'; \
335 $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget
: $(DEFAULT_SUBTARGET
)'; )) \
336 echo 'Target-Description
:'; \
337 echo "$$$$DESCRIPTION"; \
339 echo 'Default-Packages
: $(DEFAULT_PACKAGES
) $(call extra_packages
,$(DEFAULT_PACKAGES
))'; \
341 $(if $(CUR_SUBTARGET),$(SUBMAKE) -r --no-print-directory -C image -s DUMP=1 SUBTARGET=$(CUR_SUBTARGET))
342 $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
345 include $(INCLUDE_DIR)/kernel.mk
346 ifeq ($(TARGET_BUILD),1)
347 include $(INCLUDE_DIR)/kernel-build.mk
348 BuildTarget?=$(BuildKernel)