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