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