1################################################################################
2#
3# linux-backports
4#
5################################################################################
6
7ifeq ($(BR2_PACKAGE_LINUX_BACKPORTS_5_10_X),y)
8LINUX_BACKPORTS_VERSION_MAJOR = 5.10.110
9LINUX_BACKPORTS_MINIMAL_KVER_MAJOR = 3
10LINUX_BACKPORTS_MINIMAL_KVER_MINOR = 10
11else
12# use default the latest version as default
13LINUX_BACKPORTS_VERSION_MAJOR = 5.15.58
14LINUX_BACKPORTS_MINIMAL_KVER_MAJOR = 4
15LINUX_BACKPORTS_MINIMAL_KVER_MINOR = 4
16endif
17
18LINUX_BACKPORTS_VERSION = $(LINUX_BACKPORTS_VERSION_MAJOR)-1
19LINUX_BACKPORTS_SOURCE = backports-$(LINUX_BACKPORTS_VERSION).tar.xz
20LINUX_BACKPORTS_SITE = $(BR2_KERNEL_MIRROR)/linux/kernel/projects/backports/stable/v$(LINUX_BACKPORTS_VERSION_MAJOR)
21LINUX_BACKPORTS_LICENSE = GPL-2.0
22LINUX_BACKPORTS_LICENSE_FILES = \
23	COPYING \
24	LICENSES/exceptions/Linux-syscall-note \
25	LICENSES/preferred/GPL-2.0
26
27# flex and bison are needed to generate kconfig parser. We use the
28# same logic as the linux kernel (we add host dependencies only if
29# host does not have them). See linux/linux.mk and
30# support/dependencies/check-host-bison-flex.mk.
31LINUX_BACKPORTS_DEPENDENCIES = \
32	$(BR2_BISON_HOST_DEPENDENCY) \
33	$(BR2_FLEX_HOST_DEPENDENCY)
34
35ifeq ($(BR2_PACKAGE_LINUX_BACKPORTS_USE_DEFCONFIG),y)
36LINUX_BACKPORTS_KCONFIG_FILE = $(LINUX_BACKPORTS_DIR)/defconfigs/$(call qstrip,$(BR2_PACKAGE_LINUX_BACKPORTS_DEFCONFIG))
37else ifeq ($(BR2_PACKAGE_LINUX_BACKPORTS_USE_CUSTOM_CONFIG),y)
38LINUX_BACKPORTS_KCONFIG_FILE = $(call qstrip,$(BR2_PACKAGE_LINUX_BACKPORTS_CUSTOM_CONFIG_FILE))
39endif
40
41LINUX_BACKPORTS_KCONFIG_FRAGMENT_FILES = $(call qstrip,$(BR2_PACKAGE_LINUX_BACKPORTS_CONFIG_FRAGMENT_FILES))
42LINUX_BACKPORTS_KCONFIG_OPTS = $(LINUX_BACKPORTS_MAKE_OPTS)
43
44# linux-backports' build system expects the config options to be present
45# in the environment, and it is so when using their custom buildsystem,
46# because they are set in the main Makefile, which then calls a second
47# Makefile.
48#
49# In our case, we do not use that first Makefile. So, we parse the
50# .config file, filter-out comment lines and put the rest as command
51# line variables.
52#
53# LINUX_BACKPORTS_MAKE_OPTS is used by the kconfig-package infra, while
54# LINUX_BACKPORTS_MODULE_MAKE_OPTS is used by the kernel-module infra.
55#
56LINUX_BACKPORTS_MAKE_OPTS = \
57	LEX=flex \
58	YACC=bison \
59	BACKPORT_DIR=$(@D) \
60	KLIB_BUILD=$(LINUX_DIR) \
61	KLIB=$(TARGET_DIR)/lib/modules/$(LINUX_VERSION_PROBED) \
62	INSTALL_MOD_DIR=backports \
63	`sed -r -e '/^\#/d;' $(@D)/.config`
64
65LINUX_BACKPORTS_MODULE_MAKE_OPTS = $(LINUX_BACKPORTS_MAKE_OPTS)
66
67# This file is not automatically generated by 'oldconfig' that we use in
68# the kconfig-package infrastructure. In the linux buildsystem, it is
69# generated by running silentoldconfig, but that's not the case for
70# linux-backports: it uses a hand-crafted rule to generate that file.
71define LINUX_BACKPORTS_KCONFIG_FIXUP_CMDS
72	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) $(LINUX_BACKPORTS_MAKE_OPTS) backport-include/backport/autoconf.h
73endef
74
75# Checks to give errors that the user can understand
76ifeq ($(BR_BUILDING),y)
77
78ifeq ($(BR2_PACKAGE_LINUX_BACKPORTS_USE_DEFCONFIG),y)
79ifeq ($(call qstrip,$(BR2_PACKAGE_LINUX_BACKPORTS_DEFCONFIG)),)
80$(error No linux-backports defconfig name specified, check your BR2_PACKAGE_LINUX_BACKPORTS_DEFCONFIG setting)
81endif
82endif
83
84ifeq ($(BR2_PACKAGE_LINUX_BACKPORTS_USE_CUSTOM_CONFIG),y)
85ifeq ($(call qstrip,$(BR2_PACKAGE_LINUX_BACKPORTS_CUSTOM_CONFIG_FILE)),)
86$(error No linux-backports configuration file specified, check your BR2_PACKAGE_LINUX_BACKPORTS_CUSTOM_CONFIG_FILE setting)
87endif
88endif
89
90endif # BR_BUILDING
91
92$(eval $(kernel-module))
93$(eval $(kconfig-package))
94
95# linux-backports' own .config file needs options from the kernel's own
96# .config file. The dependencies handling in the infrastructure does not
97# allow to express this kind of dependencies. Besides, linux.mk might
98# not have been parsed yet, so the Linux build dir LINUX_DIR is not yet
99# known. Thus, we use a "secondary expansion" so the rule is re-evaluated
100# after all Makefiles are parsed, and thus at that time we will have the
101# LINUX_DIR variable set to the proper value. Moreover, since linux-4.19,
102# the kernel's build system internally touches its .config file, so we
103# can't use it as a stamp file. We use the LINUX_KCONFIG_STAMP_DOTCONFIG
104# instead.
105#
106# Furthermore, we want to check the kernel version is compatible with
107# linux-backports. To avoid overriding linux-backports'
108# KCONFIG_STAMP_DOTCONFIG rule defined in the kconfig-package infra, we
109# use an intermediate stamp-file.
110#
111# Finally, it must also come after the call to kconfig-package, so we get
112# LINUX_BACKPORTS_DIR properly defined (because the target part of the
113# rule is not re-evaluated).
114#
115$(LINUX_BACKPORTS_DIR)/$(LINUX_BACKPORTS_KCONFIG_STAMP_DOTCONFIG): $(LINUX_BACKPORTS_DIR)/.stamp_check_kernel_version
116
117.SECONDEXPANSION:
118$(LINUX_BACKPORTS_DIR)/.stamp_check_kernel_version: $$(LINUX_DIR)/$$(LINUX_KCONFIG_STAMP_DOTCONFIG)
119	$(Q)KVER=$(LINUX_VERSION_PROBED); \
120	MIN_KVER_MAJOR=$(LINUX_BACKPORTS_MINIMAL_KVER_MAJOR); \
121	MIN_KVER_MINOR=$(LINUX_BACKPORTS_MINIMAL_KVER_MINOR); \
122	KVER_MAJOR=`echo $${KVER} | sed 's/^\([0-9]*\)\..*/\1/'`; \
123	KVER_MINOR=`echo $${KVER} | sed 's/^[0-9]*\.\([0-9]*\).*/\1/'`; \
124	if [ $${KVER_MAJOR} -lt $(LINUX_BACKPORTS_MINIMAL_KVER_MAJOR) \
125		-o \( $${KVER_MAJOR} -eq $(LINUX_BACKPORTS_MINIMAL_KVER_MAJOR) \
126			-a $${KVER_MINOR} -lt $(LINUX_BACKPORTS_MINIMAL_KVER_MINOR) \
127		\) ]; then \
128		printf "Linux version '%s' is too old for linux-backports (needs %s.%s or later)\n" \
129			"$${KVER}" \
130			"$(LINUX_BACKPORTS_MINIMAL_KVER_MAJOR)" \
131			"$(LINUX_BACKPORTS_MINIMAL_KVER_MINOR)"; \
132		exit 1; \
133	fi
134	$(Q)touch $(@)
135