#
# backport Kconfig
#
# Some options are user-selectable ("BPAUTO_USERSEL_*")
#
# Most options, however, follow a few different schemes:
#
# A) An option that is selected by drivers ("select FOO") will be
#    changed to "select BPAUTO_FOO" (if the option BPAUTO_FOO
#    exists). The option BPAUTO_FOO then controls setting of the
#    BPAUTO_BUILD_FOO option, which is a module, like this:
#
# config BPAUTO_BUILD_FOO
#	tristate
#	# or bool
#
#	# not possible on kernel < X.Y, build will fail if any
#	# drivers are allowed to build on kernels < X.Y
#	depends on KERNEL_X_Y
#
#	# don't build the backport code if FOO is in the kernel
#	# already, but only if the kernel version is also >= X.Z;
#	# this is an example of backporting where the version of
#	# the FOO subsystem that we need is only available from
#	# kernel version X.Z
#	depends on !FOO || KERNEL_X_Z
#
#	# build if driver needs it (it selects BPAUTO_FOO)
#	default m if BPAUTO_FOO
#
#	# or for build-testing (BPAUTO_USERSEL_BUILD_ALL is enabled)
#	default m if BPAUTO_USERSEL_BUILD_ALL
#
# config BPAUTO_FOO
#	bool
#
# This only works as-is if the kernel code is usable on any version,
# otherwise the "&& !FOO" part needs to be different.
#
#
# B) An option for code always present on some kernels (e.g. KFIFO).
#    This simply depends on/sets the default based on the version:
#
# config BPAUTO_BUILD_KFIFO
#	def_bool y
#	depends on KERNEL_2_6_36
#
#
# C) similarly, a kconfig symbol for an option, e.g.
#    BPAUTO_OPTION_SOME_FIX (no examples provided) check git log
#
#
# Variations are obviously possible.
#

comma		:= ,
left_paren	:= (

# $(if-success,<command>,<then>,<else>)
# Return <then> if <command> exits with 0, <else> otherwise.
if-success = $(shell,{ $(1); } >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")

# $(success,<command>)
# Return y if <command> exits with 0, n otherwise
success = $(if-success,$(1),y,n)

config BP_MODULES
	modules
	bool
	default MODULES

	help
	This symbol is necessary for the newer kconf tool, it looks
	for the "modules" directive to control the 'm' state.

config KERNEL_HAS_SPINLOCK_BH_GUARD
	def_bool $(success,grep -q DEFINE_LOCK_GUARD_1\$(left_paren)spinlock_bh$(comma) $(KLIB_BUILD)/include/linux/spinlock.h)

config KERNEL_HAS_GENLMSG_MULTICAST_ALLNS_GFP
	def_bool $(success,grep -A5 'int genlmsg_multicast_allns' $(KLIB_BUILD)/include/net/genetlink.h | grep -q gfp_t)

config KERNEL_HAS_TIMER_SHUTDOWN_SYNC
	def_bool $(success,grep -q '^extern int timer_shutdown$(left_paren)' $(KLIB_BUILD)/include/linux/timer.h && grep -q '^extern int timer_shutdown_sync$(left_paren)' $(KLIB_BUILD)/include/linux/timer.h)

config KERNEL_HAS_TIMER_DELETE
	def_bool $(success,grep -q '^extern int timer_delete$(left_paren)' $(KLIB_BUILD)/include/linux/timer.h)

config KERNEL_HAS_TIMER_DELETE_SYNC
	def_bool $(success,grep -q '^extern int timer_delete_sync$(left_paren)' $(KLIB_BUILD)/include/linux/timer.h)

config KERNEL_HAS_TASKLET_SETUP
	def_bool $(success,grep -q '^extern void tasklet_setup$(left_paren)' $(KLIB_BUILD)/include/linux/interrupt.h)

config KERNEL_HAS_ETH_HW_ADDR_SET
	def_bool $(success,grep -q '^void eth_hw_addr_set$(left_paren)' $(KLIB_BUILD)/include/linux/etherdevice.h)

config BPAUTO_BUILD_NLATTR
	def_bool y
	depends on KERNEL_5_2
	#c-file lib/nlattr.c

config BPAUTO_USERSEL_BUILD_ALL
	bool "Build all compat code"
	help
	  This option selects all the compat code options
	  that would otherwise only be selected by drivers.

	  It's only really useful for compat testing, so
	  you probably shouldn't enable it.

config BPAUTO_WANT_DEV_COREDUMP
	bool

config BPAUTO_CRYPTO_LIB_ARC4
	bool

config BPAUTO_BUILD_CRYPTO_LIB_ARC4
	bool
	default y if BPAUTO_CRYPTO_LIB_ARC4
	depends on !(CRYPTO_LIB_ARC4=y || CRYPTO_LIB_ARC4=m)
	#h-file crypto/arc4.h
	#c-file lib/crypto/arc4.c

config BPAUTO_CRYPTO_LIB_AES_CBC_MACS
	bool

# Only in kernel >= 5.14; the dependency is always met, so just set it to y
config PTP_1588_CLOCK_OPTIONAL
	def_bool y
