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