kernel: bump 5.4 to 5.4.67
[openwrt/openwrt.git] / include / target.mk
1 #
2 # Copyright (C) 2007-2008 OpenWrt.org
3 # Copyright (C) 2016 LEDE Project
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8
9 ifneq ($(__target_inc),1)
10 __target_inc=1
11
12 # default device type
13 DEVICE_TYPE?=router
14
15 # Default packages - the really basic set
16 DEFAULT_PACKAGES:=\
17 base-files \
18 busybox \
19 ca-bundle \
20 dropbear \
21 fstools \
22 libc \
23 libgcc \
24 libustream-wolfssl \
25 logd \
26 mtd \
27 netifd \
28 opkg \
29 uci \
30 uclient-fetch \
31 urandom-seed \
32 urngd
33 # For the basic set
34 DEFAULT_PACKAGES.basic:=
35 # For nas targets
36 DEFAULT_PACKAGES.nas:=\
37 block-mount \
38 fdisk \
39 lsblk \
40 mdadm
41 # For router targets
42 DEFAULT_PACKAGES.router:=\
43 dnsmasq \
44 firewall \
45 ip6tables \
46 iptables \
47 kmod-ipt-offload \
48 odhcp6c \
49 odhcpd-ipv6only \
50 ppp \
51 ppp-mod-pppoe
52
53 ifneq ($(DUMP),)
54 all: dumpinfo
55 endif
56
57 target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
58 ifeq ($(DUMP),)
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))))
61 else
62 PLATFORM_DIR:=${CURDIR}
63 ifeq ($(SUBTARGETS),)
64 SUBTARGETS:=$(strip $(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)))
65 endif
66 endif
67
68 TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
69 PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
70
71 ifneq ($(TARGET_BUILD),1)
72 ifndef DUMP
73 include $(PLATFORM_DIR)/Makefile
74 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
75 include $(PLATFORM_SUBDIR)/target.mk
76 endif
77 endif
78 else
79 ifneq ($(SUBTARGET),)
80 -include ./$(SUBTARGET)/target.mk
81 endif
82 endif
83
84 # Add device specific packages (here below to allow device type set from subtarget)
85 DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
86
87 filter_packages = $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
88 extra_packages = $(if $(filter wpad-mini wpad-basic wpad-basic-wolfssl wpad nas,$(1)),iwinfo)
89
90 define ProfileDefault
91 NAME:=
92 PRIORITY:=
93 PACKAGES:=
94 endef
95
96 ifndef Profile
97 define Profile
98 $(eval $(call ProfileDefault))
99 $(eval $(call Profile/$(1)))
100 dumpinfo : $(call shexport,Profile/$(1)/Description)
101 PACKAGES := $(filter-out -%,$(PACKAGES))
102 DUMPINFO += \
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)"; \
109 echo "@@"; \
110 echo;
111 endef
112 endif
113
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))
118 endef
119 else
120 define IncludeProfiles
121 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
122 endef
123 endif
124
125 PROFILE?=$(call qstrip,$(CONFIG_TARGET_PROFILE))
126
127 ifeq ($(TARGET_BUILD),1)
128 ifneq ($(DUMP),)
129 $(eval $(call IncludeProfiles))
130 endif
131 endif
132
133 ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
134 include $(INCLUDE_DIR)/kernel-version.mk
135 endif
136
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)")
142
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)))
146
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))
151 endif
152
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)
155
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))
160
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))
163
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)
168 endif
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)
172 endif
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)
176 endif
177 ifeq ($(CONFIG_TARGET),env)
178 LINUX_RECONFIG_LIST = $(LINUX_KCONFIG_LIST)
179 LINUX_RECONFIG_TARGET = $(TOPDIR)/env/kernel-config
180 endif
181
182 __linux_confcmd = $(SCRIPT_DIR)/kconfig.pl $(2) $(patsubst %,+,$(wordlist 2,9999,$(1))) $(1)
183
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)),'>')
187
188 ifeq ($(DUMP),1)
189 BuildTarget=$(BuildTargets/DumpCurrent)
190
191 CPU_CFLAGS = -Os -pipe
192 ifneq ($(findstring mips,$(ARCH)),)
193 ifneq ($(findstring mips64,$(ARCH)),)
194 CPU_TYPE ?= mips64
195 else
196 CPU_TYPE ?= mips32
197 endif
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_24kc = -mips32r2 -mtune=24kc
202 CPU_CFLAGS_74kc = -mips32r2 -mtune=74kc
203 CPU_CFLAGS_octeonplus = -march=octeon+ -mabi=64
204 endif
205 ifeq ($(ARCH),i386)
206 CPU_TYPE ?= pentium-mmx
207 CPU_CFLAGS_pentium-mmx = -march=pentium-mmx
208 CPU_CFLAGS_pentium4 = -march=pentium4
209 endif
210 ifneq ($(findstring arm,$(ARCH)),)
211 CPU_TYPE ?= xscale
212 endif
213 ifeq ($(ARCH),powerpc)
214 CPU_CFLAGS_603e:=-mcpu=603e
215 CPU_CFLAGS_8540:=-mcpu=8540
216 CPU_CFLAGS_405:=-mcpu=405
217 CPU_CFLAGS_440:=-mcpu=440
218 CPU_CFLAGS_464fp:=-mcpu=464fp
219 endif
220 ifeq ($(ARCH),powerpc64)
221 CPU_TYPE ?= powerpc64
222 CPU_CFLAGS_powerpc64:=-mcpu=powerpc64
223 endif
224 ifeq ($(ARCH),sparc)
225 CPU_TYPE = sparc
226 CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc
227 endif
228 ifeq ($(ARCH),aarch64)
229 CPU_TYPE ?= generic
230 CPU_CFLAGS_generic = -mcpu=generic
231 CPU_CFLAGS_cortex-a53 = -mcpu=cortex-a53
232 endif
233 ifeq ($(ARCH),arc)
234 CPU_TYPE ?= arc700
235 CPU_CFLAGS += -matomic
236 CPU_CFLAGS_arc700 = -mcpu=arc700
237 CPU_CFLAGS_archs = -mcpu=archs
238 endif
239 ifneq ($(CPU_TYPE),)
240 ifndef CPU_CFLAGS_$(CPU_TYPE)
241 $(warning CPU_TYPE "$(CPU_TYPE)" doesn't correspond to a known type)
242 endif
243 endif
244 DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
245
246 ifneq ($(BOARD),)
247 TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
248 $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
249 $(LINUX_CONF_CMD) > $@ || rm -f $@
250 -include $(TMP_CONFIG)
251 .SILENT: $(TMP_CONFIG)
252 .PRECIOUS: $(TMP_CONFIG)
253
254 ifdef KERNEL_TESTING_PATCHVER
255 ifneq ($(KERNEL_TESTING_PATCHVER),$(KERNEL_PATCHVER))
256 FEATURES += testing-kernel
257 endif
258 endif
259 ifneq ($(CONFIG_OF),)
260 FEATURES += dt
261 endif
262 ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
263 FEATURES += gpio
264 endif
265 ifneq ($(CONFIG_PCI),)
266 FEATURES += pci
267 endif
268 ifneq ($(CONFIG_PCIEPORTBUS),)
269 FEATURES += pcie
270 endif
271 ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
272 ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
273 FEATURES += usb
274 endif
275 endif
276 ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
277 FEATURES += pcmcia
278 endif
279 ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
280 FEATURES += display
281 endif
282 ifneq ($(CONFIG_RTC_CLASS),)
283 FEATURES += rtc
284 endif
285 ifneq ($(CONFIG_VIRTIO),)
286 FEATURES += virtio
287 endif
288 ifneq ($(CONFIG_CPU_MIPS32_R2),)
289 FEATURES += mips16
290 endif
291 FEATURES += $(foreach v,6 7,$(if $(CONFIG_CPU_V$(v)),arm_v$(v)))
292
293 # remove duplicates
294 FEATURES:=$(sort $(FEATURES))
295 endif
296 endif
297
298 CUR_SUBTARGET:=$(SUBTARGET)
299 ifeq ($(SUBTARGETS),)
300 CUR_SUBTARGET := default
301 endif
302
303 define BuildTargets/DumpCurrent
304 .PHONY: dumpinfo
305 dumpinfo : export DESCRIPTION=$$(Target/Description)
306 dumpinfo:
307 @echo 'Target: $(TARGETID)'; \
308 echo 'Target-Board: $(BOARD)'; \
309 echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \
310 echo 'Target-Arch: $(ARCH)'; \
311 echo 'Target-Arch-Packages: $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(ARCH)$(if $(CPU_TYPE),_$(CPU_TYPE))$(if $(CPU_SUBTYPE),_$(CPU_SUBTYPE)))'; \
312 echo 'Target-Features: $(FEATURES)'; \
313 echo 'Target-Depends: $(DEPENDS)'; \
314 echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
315 echo 'CPU-Type: $(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))'; \
316 echo 'Linux-Version: $(LINUX_VERSION)'; \
317 $(if $(LINUX_TESTING_VERSION),echo 'Linux-Testing-Version: $(LINUX_TESTING_VERSION)';) \
318 echo 'Linux-Release: $(LINUX_RELEASE)'; \
319 echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
320 $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; )) \
321 echo 'Target-Description:'; \
322 echo "$$$$DESCRIPTION"; \
323 echo '@@'; \
324 echo 'Default-Packages: $(DEFAULT_PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES))'; \
325 $(DUMPINFO)
326 $(if $(CUR_SUBTARGET),$(SUBMAKE) -r --no-print-directory -C image -s DUMP=1 SUBTARGET=$(CUR_SUBTARGET))
327 $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
328 endef
329
330 include $(INCLUDE_DIR)/kernel.mk
331 ifeq ($(TARGET_BUILD),1)
332 include $(INCLUDE_DIR)/kernel-build.mk
333 BuildTarget?=$(BuildKernel)
334 endif
335
336 endif #__target_inc