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