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