#
#                             IPSTB Project
#                   ---------------------------------
#
# Copyright (C) 2009 NXP B.V.,
# All Rights Reserved.
#
# Filename: linux/Makefile
#
#
# Rev Date        Author      Comments
#-------------------------------------------------------------------------------
#  60 20080305    batelaan    Use CONFIG_linux_VERSION.
#  61 20080307    amccurdy    Indirect access to aimage signing tool via "aimage_sign" symlink
#  61 20080314    laird       linux_VERSION is now set before calling this makefile.
#  62 20080317    amccurdy    Merge parallel 61s
#  63 20080318    batelaan    Use linux_DI_SRCDIR.
#  64 20080319    laird       Use CONFIG_TOOLCHAIN_OPTIMIZE_S to set optimzation level not small ram.
#                             Allow num build jobs to be set by user.
#  65 20080326    laird       Use linux_OPTIMIZE_FOR_SIZE to optimized for size.
#                             This is because we need to set it differently for dsp/control.
#  66 20080410    batelaan    Add linux.(html|man|ps|pdf|xml)docs targets.
#  67 20080415    batelaan    Keep CONFIG_NXP_RS_SERVER set to m.
#  68 20080417    amccurdy    Cleanup automated kernel config editing
#  70 20080425    batelaan    Use compact format for diffconfig target.
#                             Use prjconfig for linux config spec.
#  71 20080518    fedonczuk   Add support for NOR with 2.6.24 kernel
#  72 20080527    batelaan    Prevent unintentional overwriting of modified $KSRC/.config
#  73 20080528    batelaan    Remove auto-setting WMDRMPD options
#  74 20080603    batelaan    Remove NFS/INITRAMFS/PNP_IP_DHCP auto-setting.
#  75 20080606    laird       Remove 2.6.19 support
#  76 20080613    laird       Change config names of kernel. (PR/CR 1258)
#  77 20080623    batelaan    Move include of etc/setup_productversion.mk to etc/init.mk
#  79 20080708    batelaan    Merge with Caen version.
#  80 20080709    batelaan    Build kernel modules as external modules.
#  81 20080723    batelaan    Allow skipping of kernel build if KSRC_override is defined.
#  82 20080926    batelaan    Use _TMMAKEJOBS i.s.o. CONFIG_NUM_BUILD_JOBS variable for -j option.
#  83 20081002    batelaan    Force subtargets from linux.modules.make
#  84 20081009    batelaan    Check for warnings re incorrect symbols config stage. CONFEDIT macros changed.
#  85 20081014    neill       Add Video 4 Linux support
#84.1.1 20081015  batelaan    Forgive C compilation warnings in make oldconfig.
#  86 20081015    neill       Merge
#  87 20081022    amccurdy    Add linux_CONFEDIT_WIRELESS_EXT support
# c80 20080729    ocourson    Add multicast option
# c81 20080729    ocourson    Remove watchdog module when not required
# c82 20080730    watine      Add support of printk option
# c83 20080730    watine      Apply ethernet config
# c84 20080731    watine      USB key drivers not compiled when not selected
# c85 20080731    watine      Enable/Disable USB core
# c86 20080822    ocourson    Merge Caen with main branch
# c87 20081002    ocourson    Add power saving options
# 85.1.5 20081208 batelaan    Merge Caen changes.
#  88 20090106    batelaan    aimage_sign is optional.
#  89 20090115    batelaan    Add buildroot.toolchain as dependency of linux.kernel.make
#  90 20090126    steel       Add Moca Phy support
#  91 20090127    batelaan    Merge in GYX1D tuner
#  92 20090127    steel       Add SMSC911X support
#  93 20090310    guo         Add Samsung ISDB-T FE drivers (ie tdhl5 dvb4linux API compliant)
#  94 20090313    guo         Add Thomson ISDB-T FE drivers (NuTune, dvb4linux API compliant)
#  95 20090317    amccurdy    Run stripdir later to catch mainapp in dsp rootfs
#  96 20090323    amccurdy    Add confedit support for ext2, ext3, cramfs, jffs2, squashfs and yaffs
#                             Remove ext2 control from linux_CONFEDIT_USBMASSKEY
#  97 20090323    amccurdy    Fix 'linux_CONFEDIT_USBCORE' not defined...
#  96 20090323    cgrosse     Add NXP TDA18218 Silicon tuner
#  98 20090324    laird       Merge......
#  99 20090324    amccurdy    Replace linux_CONFEDIT_FLASH with separate controls for NOR and NAND
#  xx 20090924    myers       Add support for option forcing 100M full duplex
#  xx 20091021    amccurdy    Update untar_POSTUNTARCMDS to remove arch/mips/philips/pnx8550 after extracting linux-2.6.24.7 tar file
#  xx 20091106    amccurdy    Make linux_CONFEDIT_USBALSAKEY and linux_CONFEDIT_USBNETKEY actually do something
#  xx 20091106    amccurdy    Add confedit support for NTFS filesystem
#  xx 20091111    mpage       Add confedit support for DVB DMX Direct Access
#  xx 20091130    amccurdy    Generate listing of files within dsp rootfs
#  xx 20091130    amccurdy    Add IP3902_C confedit support. Make dsp rootfs listing conditional on linux_USE_INITRAMFS
#  xx 20100127    amccurdy    Add confedit support for DVB_TDA10024, DVB_CD1616 and DVB_TDA18252
#  xx 20100223    amccurdy    Add confedit support for kernel HW_RANDOM + PNX8335 HW RNG driver
#  xx 20100226    amccurdy    Add confedit support for kernel GPIO interrupts
#  xx 20100302    amccurdy    Add confedit support for kernel USB HID drivers and really disable USB if linux_ENABLE_USBCORE is not set
#  xx 20100428    amccurdy    Add make_fix_depmod_CMDS

# File: linux/Makefile
# Makefile to control building of linux (the kernel).
#
# The kernel is built in the location given by variable <KSRC>.

include $(PRJROOT)/etc/first.mk

$(eval $(PKG_START))

PKG=linux

# Define: linux_LOCALVERSION
# Contains the value of <CONFIG_LOCALVERSION> variable.
linux_LOCALVERSION=$(if $(filter undefined,$(origin CONFIG_LOCALVERSION)),$(CONFIG_LOCALVERSION_CMDS))$(CONFIG_LOCALVERSION)

# Define: linux_CONFIG_NAME
# linux_CONFIG_NAME is the same as CONFIG_NAME but with surrounding '"' removed.
linux_CONFIG_NAME:=$(patsubst "%",%,$(CONFIG_NAME))

# Define: CONFIG_LOCALVERSION
# CONFIG_LOCALVERSION is a string appended to the official Linux kernel version string.
# We set it to ".{<CONFIG_NAME>}", appended with ".{<PRODUCTVERSION>}".
CONFIG_LOCALVERSION_new=.$(linux_CONFIG_NAME)$(if $(PRODUCTVERSION),.$(strip $(PRODUCTVERSION)))
#CONFIG_LOCALVERSION_new=.dma2105r3w_dfb100.pr13_sjo_r2971_b1

# Define: CONFIG_LOCALVERSION_CMDS
# Make expression to define variable <CONFIG_LOCALVERSION> which is used as the value
# for <linux_LOCALVERSION>.
#CONFIG_LOCALVERSION_CMDS=$(eval $(if $(wildcard $(KSRC)/.config),\
#  $(shell grep 'CONFIG_LOCALVERSION=' $(KSRC)/.config | sed 's/"//g'),\
#  CONFIG_LOCALVERSION=$(CONFIG_LOCALVERSION_new)))

# MAC 2009/03/18 We don't want to read CONFIG_LOCALVERSION from the
# .config file because it will be out of date if
# setup_productversion.mk has changed and .config gets subsequently
# rebuilt. It should always match anyway so always use the new value
# we've calculated.
CONFIG_LOCALVERSION_CMDS=$(eval CONFIG_LOCALVERSION=$(CONFIG_LOCALVERSION_new))

# Macro: linux_AVAILABLECONFIGFILE
# Evaluates to the first file that exists, which is either:-
# - <KSRC>/.config
# - <KERNELCONFIG>
linux_AVAILABLECONFIGFILE=$(firstword $(shell ls $(KSRC)/.config $(KERNELCONFIG) 2>/dev/null))

# Macro: linux_CONFIG_MODULES
# Tells us if Linux kernel has module support enabled.
# Set to y if <linux_AVAILABLECONFIGFILE> contains 'CONFIG_MODULES=y'.
linux_CONFIG_MODULES=$(if $(filter CONFIG_MODULES=y,$(shell grep -Fe 'CONFIG_MODULES=y' $(linux_AVAILABLECONFIGFILE))),y)

# Define: KSRC_override
# If defined and not empty, then we don't create, build or clean the kernel tree.
# We do still build the kernel modules that are part of our software platform
# (see target <linux.ext.modules.make>.
#
# This variable is expected to be the path to the kernel tree (as is <KSRC>).

# Macro: KERNELCONFIG
# Path to kernel configuration file.
#
# If we are crosscompiling, then it is the file specified by <linux_CONFIG_FILE>
# and searched for in directories:
# - <linux_DI_SRCDIR>/configs
# - <linux_SRCDIR>/configs
#
# If we are not crosscompiling, then the value is ${<KSRC>}/.config

# Macro: linux_CONFIG_FILE
# Name of the linux configuration file.
# Used by <KERNELCONFIG> if we are crosscompiling.
# Must be set outside this Makefile, usually in
# <platform_control_cpu_linux.mk> or <platform_dsp_cpu.mk> .

# Macro: linux_SRCDIR
# Directory containing the Makefile, config files, etc, to control building the linux package.
#
# See: <linux_DI_SRCDIR>

# Macro: linux_DI_SRCDIR
# Optional design-in specific directory containing overriding items.
#
# See: <linux_SRCDIR> <xxx_DI_SRCDIR>

# Macro: linux_VERSION
# Version of the linux kernel tarball.
# Depends on whether we are crosscompiling how it is determined.
# - If not crosscompiling: value of "uname --kernel-release" command.
# - Otherwise: must be set outside this Makefile, usually in
# <platform_control_cpu_linux.mk> or <platform_dsp_cpu.mk> .

# Special case: we don't build the kernel if we are targeting the build host:
ifeq "$(filter $(ARCH),$(shell uname --hardware-platform --machine --processor))" "$(ARCH)"
  linux_SKIPBUILD=true
  linux_VERSION=$(shell uname --kernel-release)
  KERNELCONFIG=$(KSRC)/.config
else
  # Crosscompiling.

  ifeq "$(KSRC_override)" ""
    # Sanity check the KSRC variable value, it should end with linux_VERSION:
    # Get linux version from environment variable KSRC (everything after "linux-"):
    linux_VERSION_FROM_KSRC:=$(shell echo "$${KSRC\#\#*/linux-}")
    ifneq "$(linux_VERSION)" "$(linux_VERSION_FROM_KSRC)"
      $(warning KSRC = $(KSRC))
      $(warning linux_VERSION = $(linux_VERSION))
      $(error KSRC does not seem to match linux_VERSION)
    endif

  # Define: linux_LOADADDRESS
  # Required variable to define address where the linux kernel is loaded into memory.
  # Passed to kernel make command using load-y=${<linux_LOADADDRESS>}

  $(call CHECK_VAR_DEFINED,linux_LOADADDRESS,Defines Linux kernel load address)

  endif # ifeq "$(KSRC_override)" ""

  # Default config file
  KERNELCONFIG = $(firstword $(wildcard \
    $(linux_DI_SRCDIR)/configs/$(linux_CONFIG_FILE) \
    $(linux_SRCDIR)/configs/$(linux_CONFIG_FILE) \
  ))
endif

$(eval $(PKG_SETUP_VARS))

ifneq "$(linux_SKIPBUILD)" "true"

ifeq "$(KSRC_override)" ""
  $(call DOTRACE,'KSRC=$(KSRC) linux_BUILDDIR=$(linux_BUILDDIR)')
  ifneq ($(KSRC),$(linux_BUILDDIR))
    $(error Expecting to be the same: KSRC="$(KSRC)" linux_BUILDDIR="$(linux_BUILDDIR)")
  endif
else # ifeq "$(KSRC_override)" ""
  linux_BUILDDIR=$(KSRC)
endif # ifeq "$(KSRC_override)" ""

ifeq "$(wildcard $(KERNELCONFIG))" ""
  $(warning $$linux_CONFIG_FILE is "$(linux_CONFIG_FILE)")
  $(warning Check value of linux config file option(s) in prjconfig!)
  $(error $$KERNELCONFIG ($(KERNELCONFIG) file does not exist))
endif

endif # ifneq "$(linux_SKIPBUILD)" "true"

# Define: linux_DEFMAKEOPTS
# Default options of linux make invocations.
# - If distcc is being used then add the options (<STB_DISTCC_OPTIONS>) to the make command.
# - CROSS_COMPILE=$(<CROSS_COMPILE>)
# - INSTALL_MOD_PATH=$(<ROOTFS>)
# - -j<_TMMAKEJOBS>: Pass the number of build jobs to use.
# - load-y=${<linux_LOADADDRESS>} is added to specify the load address of the kernel.
# - we don't pass on V=$(V) because if we do then the if_changed
#   function in scripts/Kbuild.include starts generating command lines
#   that are too long if V=1 and we fall over in a heap.
linux_DEFMAKEOPTS=\
  $(STB_DISTCC_OPTIONS) \
  CROSS_COMPILE=$(CROSS_COMPILE) \
  INSTALL_MOD_PATH=$(ROOTFS) \
  -j$(_TMMAKEJOBS) \
  $(if $(filter-out undefined, $(origin linux_LOADADDRESS)),load-y=$(linux_LOADADDRESS))

linux_DEFINSTALLOPTS=$(linux_DEFMAKEOPTS)

# ----------------------------------------------------------------------------
# Main target definitions
# ----------------------------------------------------------------------------

$(call PKG_DEFINE_TARGETS,help)

ifneq "$(KSRC_override)" ""
# define 'empty' targets for some make targets
# we don't need when using an external KSRC tree:
$(foreach target,patch config,\
  $(eval linux.$(target)_CMDS = @echo 'Skipping linux.$(target) (using external KSRC tree)') \
  $(call PKG_DEFINE_TARGETS,$(target))\
)
$(foreach target,kernel.make int.modules.make,\
  $(eval linux.$(target)_CMDS = @echo 'Skipping linux.$(target) (using external KSRC tree)') \
  $(call PKG_TARGET,linux.$(target))\
)

define linux.clean_CMDS
	$(if $(linux_EXT_MODULE_BUILDDIR),rm -rf $(linux_EXT_MODULE_BUILDDIR))
endef
$(call PKG_DEFINE_TARGETS,clean)

define linux.untar_CMDS
	rm -f $(CPUBUILDROOT)/packages/linux
	mkdir -p $(CPUBUILDROOT)/packages
	ln -s $(KSRC) $(CPUBUILDROOT)/packages/linux
endef

$(call PKG_DEFINE_TARGETS,untar)

else # ifneq "$(KSRC_override)" ""

# Define: linux.clean_EXTRACMDSBEFORE
# Calls make clean for the kernel before deleting <KSRC>.
#
# Not used if <KSRC_override> is defined.
define linux.clean_EXTRACMDSBEFORE
	$(if $(linux_EXT_MODULE_BUILDDIR),rm -rf $(linux_EXT_MODULE_BUILDDIR))
	$(Q)-if [ -f $$KSRC/Makefile ]; then \
	  echo '  CLEAN Linux build products'; \
	  $(MAKECMD) -k --directory=$$KSRC clean; \
	  rm -f $${KSRC}/auImage $${KSRC}/auImage_enc; \
	fi
endef

# From linux 2.6.24.7 onwards, we use a pristine kernel.org tarball
# and apply _all_ NXP and local changes via overlay and patches.
#
ifeq "$(shell echo $(CONFIG_linux_VERSION))" "2.6.24.7_nxp"
  # Define: linux_TARBALL
  # Manually select the tarball we want to use rather than the default
  # behaviour (ie too automatically search for one based on $(PKG)_FULLNAME).
  linux_TARBALL := $(TARBALLS)/linux-2.6.24.7.tar.bz2

  # Define: linux.untar_POSTUNTARCMDS
  # The pristine kernel.org tarball does not create the expected directory,
  # so move it to its final expected location (ie $(PKG)_BUILDDIR).
  # Final location is known not to exist by this point in the untar process
  # so a simple 'mv' should be fine...
  define linux.untar_POSTUNTARCMDS
	mv $(dir $($(PKG)_BUILDDIR))linux-2.6.24.7 $($(PKG)_BUILDDIR)
	rm -r $($(PKG)_BUILDDIR)/arch/mips/philips/pnx8550/
  endef
endif

linux_PATCHOPTS=--multipatch

$(call PKG_DEFINE_TARGETS,clean untar patch)

# Macro: linux.post_config_CMDS
# Configuration actions to be done before every <linux.make>.
# - Links <BUILDROOT>/prjconfig.h into <KSRC>/include directory.
#
# Not used if <KSRC_override> is true.
define linux.post_config_CMDS
	$(Q)ln -sf $(BUILDROOT)/prjconfig.h $$KSRC/include
endef

# ----------------------------------------------------------------------------
# Linux configuration file edit macros.
# Define: linux_CONFEDIT_APPEND
# Appends a line containing 'argument' to working copy of kernel .config.tmp
linux_CONFEDIT_APPEND = \
  cd $$KSRC && echo '$1' >> .config.tmp

# Define: linux_CONFEDIT_DELETE
# Deletes line(s) containing 'argument' from working copy of kernel .config.tmp
linux_CONFEDIT_DELETE = \
  cd $$KSRC && \
  sed '\@.*\($1\)[ =].*@d' < .config.tmp > .config.tmp2 && \
  mv -f .config.tmp2 .config.tmp

# Define: linux_CONFEDIT_SET_RAW
# Sets 'argument' option in working copy of kernel .config equal to a given value
linux_CONFEDIT_SET_RAW = \
  if [ -n "$${REASON}" ]; \
    then printf 'CONFEDIT_SET     : %-40s(because %s)\n' '$(strip $1)$(strip $2)' "$${REASON}"; \
    else echo 'CONFEDIT_SET     : $(strip $1)$(strip $2)'; \
  fi; \
  $(call linux_CONFEDIT_DELETE,$(strip $1)); \
  $(call linux_CONFEDIT_APPEND,$(strip $1)$(strip $2))

# Define: linux_CONFEDIT_UNSET
# Unsets 'argument' option in working copy of kernel .config
linux_CONFEDIT_UNSET = \
  if [ -n "$${REASON}" ]; \
    then printf 'CONFEDIT_UNSET   : %-40s(because %s)\n' '$(strip $1)' "$${REASON}"; \
    else echo 'CONFEDIT_UNSET   : $(strip $1)'; \
  fi; \
  $(call linux_CONFEDIT_DELETE,$(strip $1)); \
  $(call linux_CONFEDIT_APPEND,\# $(strip $1) is not set)

# Define: linux_CONFEDIT_SET
# Sets 'argument' option in working copy of kernel .config equal to 'y'
linux_CONFEDIT_SET = \
  $(call linux_CONFEDIT_SET_RAW,$1,=y)

# Define: linux_CONFEDIT_SET_M
# Sets 'argument' option in working copy of kernel .config equal to 'm'
linux_CONFEDIT_SET_M = \
  $(call linux_CONFEDIT_SET_RAW,$1,=m)

# Define: linux_CONFEDIT_SET_INTEGER
# Sets 'argument' option in working copy of kernel .config equal to a given value, unquoted
linux_CONFEDIT_SET_INTEGER = \
  $(call linux_CONFEDIT_SET_RAW,$1,=$(strip $2))

# Define: linux_CONFEDIT_SET_STRING
# Sets 'argument' option in working copy of kernel .config equal to a given value, quoted
linux_CONFEDIT_SET_STRING = \
  $(call linux_CONFEDIT_SET_RAW,$1,="$2")

# Define: linux_CONFEDIT_NOOP
# Echos 'argument' option, doesn't touch working copy of kernel .config
linux_CONFEDIT_NOOP = \
  echo "CONFEDIT_NOOP    : $1"

# ----------------------------------------------------------------------------

# Define: linux_CONFEDIT_LOCALVERSION
#
linux_CONFEDIT_LOCALVERSION = \
  REASON=""; \
  $(call linux_CONFEDIT_SET_STRING,CONFIG_LOCALVERSION,$(CONFIG_LOCALVERSION_new))

# Define: linux_CONFEDIT_ENDIAN
#
linux_CONFEDIT_ENDIAN = \
  $(if $(filter el,$(_TMTGTENDIAN)), \
	REASON="_TMTGTENDIAN == el"; \
	$(call linux_CONFEDIT_SET,CONFIG_CPU_LITTLE_ENDIAN), \
	REASON="_TMTGTENDIAN != el"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_CPU_LITTLE_ENDIAN))

# Define: linux_CONFEDIT_OPTSIZE
#
linux_CONFEDIT_OPTSIZE = \
  $(if $(linux_OPTIMIZE_FOR_SIZE), \
	REASON="linux_OPTIMIZE_FOR_SIZE set"; \
	$(call linux_CONFEDIT_SET,CONFIG_CC_OPTIMIZE_FOR_SIZE), \
	REASON="linux_OPTIMIZE_FOR_SIZE clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_CC_OPTIMIZE_FOR_SIZE))

# Define: linux_CONFEDIT_PREEMPT
#
linux_CONFEDIT_PREEMPT = \
  $(if $(linux_DISABLE_PREEMPT), \
	REASON="linux_DISABLE_PREEMPT set"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_PREEMPT); \
	$(call linux_CONFEDIT_UNSET,CONFIG_PREEMPT_NONE); \
	$(call linux_CONFEDIT_SET,CONFIG_PREEMPT_VOLUNTARY),)

# Define: linux_CONFEDIT_HI_RES_TIMERS
#
linux_CONFEDIT_HI_RES_TIMERS = \
  $(if $(linux_DISABLE_HI_RES_TIMERS), \
	REASON="linux_DISABLE_HI_RES_TIMERS set"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_HIGH_RES_TIMERS),)

# Define: linux_CONFEDIT_NO_HZ
#
linux_CONFEDIT_NO_HZ = \
  $(if $(linux_DISABLE_NO_HZ), \
	REASON="linux_DISABLE_NO_HZ set"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_NO_HZ),)

# Define: linux_CONFEDIT_PRINTK
#
linux_CONFEDIT_PRINTK = \
  $(if $(linux_ENABLE_PRINTK), \
	REASON="linux_ENABLE_PRINTK set"; \
	$(call linux_CONFEDIT_NOOP,"Using default config file settings for printk related options"), \
	REASON="linux_ENABLE_PRINTK clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_BUG); \
	$(call linux_CONFEDIT_UNSET,CONFIG_PRINTK); \
	$(call linux_CONFEDIT_UNSET,CONFIG_EARLY_PRINTK); \
	$(call linux_CONFEDIT_UNSET,CONFIG_SYS_HAS_EARLY_PRINTK); \
	$(call linux_CONFEDIT_UNSET,CONFIG_PRINTK_SHORT_IRQ_DISABLE); \
	$(call linux_CONFEDIT_UNSET,CONFIG_PRINTK_DEFER_IN_IRQ); \
	$(call linux_CONFEDIT_UNSET,CONFIG_SND_VERBOSE_PRINTK); \
	$(call linux_CONFEDIT_UNSET,CONFIG_ELF_CORE); \
	$(call linux_CONFEDIT_UNSET,CONFIG_SYSCTL_SYSCALL); \
	$(call linux_CONFEDIT_UNSET,CONFIG_KALLSYMS))

# Define: linux_CONFEDIT_DEBUG
#
linux_CONFEDIT_DEBUG = \
  $(if $(linux_ENABLE_KERNEL_DEBUG), \
	REASON="linux_ENABLE_KERNEL_DEBUG set"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DEBUG_DRIVER); \
	$(call linux_CONFEDIT_UNSET,CONFIG_DEBUG_DEVRES); \
	$(call linux_CONFEDIT_SET,CONFIG_DEBUG_KERNEL); \
	$(call linux_CONFEDIT_UNSET,CONFIG_DEBUG_SHIRQ); \
	$(call linux_CONFEDIT_SET,CONFIG_DETECT_SOFTLOCKUP); \
	$(call linux_CONFEDIT_UNSET,CONFIG_SCHED_DEBUG); \
	$(call linux_CONFEDIT_UNSET,CONFIG_SCHEDSTATS); \
	$(call linux_CONFEDIT_UNSET,CONFIG_TIMER_STATS); \
	$(call linux_CONFEDIT_SET,CONFIG_DEBUG_SLAB); \
	$(call linux_CONFEDIT_UNSET,CONFIG_DEBUG_SLAB_LEAK); \
	$(call linux_CONFEDIT_SET,CONFIG_DEBUG_PREEMPT); \
	$(call linux_CONFEDIT_SET,CONFIG_DEBUG_RT_MUTEXES); \
	$(call linux_CONFEDIT_SET,CONFIG_DEBUG_PI_LIST); \
	$(call linux_CONFEDIT_UNSET,CONFIG_RT_MUTEX_TESTER); \
	$(call linux_CONFEDIT_SET,CONFIG_DEBUG_SPINLOCK); \
	$(call linux_CONFEDIT_SET,CONFIG_DEBUG_MUTEXES); \
	$(call linux_CONFEDIT_SET,CONFIG_DEBUG_LOCK_ALLOC); \
	$(call linux_CONFEDIT_SET,CONFIG_PROVE_LOCKING); \
	$(call linux_CONFEDIT_SET,CONFIG_LOCKDEP); \
	$(call linux_CONFEDIT_UNSET,CONFIG_LOCK_STAT); \
	$(call linux_CONFEDIT_UNSET,CONFIG_DEBUG_LOCKDEP); \
	$(call linux_CONFEDIT_SET,CONFIG_TRACE_IRQFLAGS); \
	$(call linux_CONFEDIT_SET,CONFIG_DEBUG_SPINLOCK_SLEEP); \
	$(call linux_CONFEDIT_SET,CONFIG_DEBUG_LOCKING_API_SELFTESTS); \
	$(call linux_CONFEDIT_SET,CONFIG_STACKTRACE); \
	$(call linux_CONFEDIT_UNSET,CONFIG_DEBUG_KOBJECT); \
	$(call linux_CONFEDIT_UNSET,CONFIG_DEBUG_INFO); \
	$(call linux_CONFEDIT_UNSET,CONFIG_DEBUG_VM); \
	$(call linux_CONFEDIT_SET,CONFIG_DEBUG_LIST); \
	$(call linux_CONFEDIT_SET,CONFIG_DEBUG_SG); \
	$(call linux_CONFEDIT_SET,CONFIG_FORCED_INLINING); \
	$(call linux_CONFEDIT_UNSET,CONFIG_BOOT_PRINTK_DELAY); \
	$(call linux_CONFEDIT_UNSET,CONFIG_RCU_TORTURE_TEST); \
	$(call linux_CONFEDIT_UNSET,CONFIG_FAULT_INJECTION); \
	$(call linux_CONFEDIT_UNSET,CONFIG_DEBUG_STACK_USAGE); \
	$(call linux_CONFEDIT_UNSET,CONFIG_KGDB); \
	$(call linux_CONFEDIT_UNSET,CONFIG_RUNTIME_DEBUG); \
	$(call linux_CONFEDIT_UNSET,CONFIG_MIPS_UNCACHED), \
	REASON="linux_ENABLE_KERNEL_DEBUG clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DEBUG_KERNEL))

# Define: linux_CONFEDIT_ATA
#
linux_CONFEDIT_ATA = \
  $(if $(linux_ENABLE_SATA), \
	REASON="linux_ENABLE_SATA set"; \
	$(call linux_CONFEDIT_SET,CONFIG_ATA), \
	REASON="linux_ENABLE_SATA clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_ATA))

# Define: linux_CONFEDIT_BLK_DEV_LOOP
#
linux_CONFEDIT_BLK_DEV_LOOP = \
  $(if $(linux_ENABLE_BLK_DEV_LOOP), \
	REASON="linux_ENABLE_BLK_DEV_LOOP set"; \
	$(call linux_CONFEDIT_SET,CONFIG_BLK_DEV_LOOP); \
	$(call linux_CONFEDIT_UNSET,CONFIG_BLK_DEV_CRYPTOLOOP), \
	REASON="linux_ENABLE_BLK_DEV_LOOP clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_BLK_DEV_LOOP))

# Define: linux_CONFEDIT_EXT2_FS
#
linux_CONFEDIT_EXT2_FS = \
  $(if $(linux_ENABLE_EXT2_FS), \
	REASON="linux_ENABLE_EXT2_FS set"; \
	$(call linux_CONFEDIT_NOOP,"Using default config file settings for CONFIG_EXT2_FS"), \
	REASON="linux_ENABLE_EXT2_FS clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_EXT2_FS))

# Define: linux_CONFEDIT_EXT3_FS
#
linux_CONFEDIT_EXT3_FS = \
  $(if $(linux_ENABLE_EXT3_FS), \
	REASON="linux_ENABLE_EXT3_FS set"; \
	$(call linux_CONFEDIT_NOOP,"Using default config file settings for CONFIG_EXT3_FS"), \
	REASON="linux_ENABLE_EXT3_FS clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_EXT3_FS))

# Define: linux_CONFEDIT_NTFS_FS
#
linux_CONFEDIT_NTFS_FS = \
  $(if $(linux_ENABLE_NTFS_FS), \
	REASON="linux_ENABLE_NTFS_FS set"; \
	$(call linux_CONFEDIT_NOOP,"Using default config file settings for CONFIG_NTFS_FS"), \
	REASON="linux_ENABLE_NTFS_FS clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_NTFS_FS))

# Define: linux_CONFEDIT_CRAMFS_FS
#
linux_CONFEDIT_CRAMFS_FS = \
  $(if $(linux_ENABLE_CRAMFS_FS), \
	REASON="linux_ENABLE_CRAMFS_FS set"; \
	$(call linux_CONFEDIT_NOOP,"Using default config file settings for CONFIG_CRAMFS"), \
	REASON="linux_ENABLE_CRAMFS_FS clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_CRAMFS))

# Define: linux_CONFEDIT_JFFS2_FS
#
linux_CONFEDIT_JFFS2_FS = \
  $(if $(linux_ENABLE_JFFS2_FS), \
	REASON="linux_ENABLE_JFFS2_FS set"; \
	$(call linux_CONFEDIT_NOOP,"Using default config file settings for CONFIG_JFFS2_FS"), \
	REASON="linux_ENABLE_JFFS2_FS clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_JFFS2_FS))

# Define: linux_CONFEDIT_SQUASHFS_FS
#
linux_CONFEDIT_SQUASHFS_FS = \
  $(if $(linux_ENABLE_SQUASHFS_FS), \
	REASON="linux_ENABLE_SQUASHFS_FS set"; \
	$(call linux_CONFEDIT_NOOP,"Using default config file settings for CONFIG_SQUASHFS"), \
	REASON="linux_ENABLE_SQUASHFS_FS clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_SQUASHFS))

# Define: linux_CONFEDIT_YAFFS_FS
#
linux_CONFEDIT_YAFFS_FS = \
  $(if $(linux_ENABLE_YAFFS_FS), \
	REASON="linux_ENABLE_YAFFS_FS set"; \
	$(call linux_CONFEDIT_NOOP,"Using default config file settings for CONFIG_YAFFS_FS"), \
	REASON="linux_ENABLE_YAFFS_FS clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_YAFFS_FS))

# Define: linux_CONFEDIT_NAND_FLASH
#
linux_CONFEDIT_NAND_FLASH = \
  $(if $(CONFIG_NAND_FLASH), \
	REASON="CONFIG_NAND_FLASH set"; \
	$(call linux_CONFEDIT_SET,CONFIG_MTD_NAND); \
	$(call linux_CONFEDIT_SET,CONFIG_MTD_NAND_IDS); \
	$(call linux_CONFEDIT_SET,CONFIG_MTD_NAND_$(if $(filter 2.6.19.1,$(patsubst "%",%,$(CONFIG_linux_VERSION))),STB225,PLATFORM)); \
	$(call linux_CONFEDIT_SET,CONFIG_MTD_BLOCK_ROBBS); \
	$(call linux_CONFEDIT_UNSET,CONFIG_MTD_NAND_VERIFY_WRITE); \
	$(call linux_CONFEDIT_UNSET,CONFIG_MTD_NAND_ECC_SMC); \
	$(call linux_CONFEDIT_UNSET,CONFIG_MTD_NAND_MUSEUM_IDS); \
	$(call linux_CONFEDIT_UNSET,CONFIG_MTD_NAND_DISKONCHIP); \
	$(call linux_CONFEDIT_UNSET,CONFIG_MTD_NAND_NANDSIM); \
	$(call linux_CONFEDIT_UNSET,CONFIG_MTD_ALAUDA), \
	REASON="CONFIG_NAND_FLASH clear"; \
	$(call linux_CONFEDIT_NOOP,"NAND is disabled in reference config... no edit required"))

# Define: linux_CONFEDIT_NOR_FLASH
#
linux_CONFEDIT_NOR_FLASH = \
  $(if $(CONFIG_NOR_FLASH), \
	REASON="CONFIG_NOR_FLASH set"; \
	$(call linux_CONFEDIT_NOOP,"NOR is enabled in reference config... no edit required"), \
	REASON="CONFIG_NOR_FLASH clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_MTD_PHYSMAP))

# Define: linux_CONFEDIT_ETHERNET
#
linux_CONFEDIT_ETHERNET = \
  $(if $(linux_ENABLE_ETHERNET), \
	REASON="linux_ENABLE_ETHERNET set"; \
	$(call linux_CONFEDIT_NOOP,"Using default config file settings for ethernet"), \
	REASON="linux_ENABLE_ETHERNET clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_SUNRPC); \
	$(call linux_CONFEDIT_UNSET,CONFIG_NFS_COMMON); \
	$(call linux_CONFEDIT_UNSET,CONFIG_LOCKD_V4); \
	$(call linux_CONFEDIT_UNSET,CONFIG_LOCKD); \
	$(call linux_CONFEDIT_UNSET,CONFIG_ROOT_NFS); \
	$(call linux_CONFEDIT_UNSET,CONFIG_NFS_V3); \
	$(call linux_CONFEDIT_UNSET,CONFIG_NFS_FS); \
	$(call linux_CONFEDIT_UNSET,CONFIG_NETWORK_FILESYSTEMS))

# Define: linux_CONFEDIT_IP3902
#
linux_CONFEDIT_IP3902 = \
  $(if $(linux_ENABLE_IP3902), \
	REASON="linux_ENABLE_IP3902 set"; \
	$(call linux_CONFEDIT_NOOP,"Using default config file settings for IP3902"), \
	REASON="linux_ENABLE_IP3902 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_IP3902))

# Define: linux_CONFEDIT_IP3902_CA
#
linux_CONFEDIT_IP3902_CA = \
  $(if $(linux_ENABLE_IP3902_CA), \
	REASON="linux_ENABLE_IP3902_CA set"; \
	$(call linux_CONFEDIT_SET,CONFIG_IP3902_CA), \
	REASON="linux_ENABLE_IP3902_CA clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_IP3902_CA))

# Define: linux_CONFEDIT_SMSC911X
#
linux_CONFEDIT_SMSC911X = \
  $(if $(linux_ENABLE_SMSC911X), \
	REASON="linux_ENABLE_SMSC911X set"; \
	$(call linux_CONFEDIT_NOOP,"Using default config file settings for SMSC911X"), \
	REASON="linux_ENABLE_SMSC911X clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_SMSC911X))

# Define: linux_CONFEDIT_NETPHY_PIO29
#
linux_CONFEDIT_NETPHY_PIO29 = \
  $(if $(linux_ENABLE_NETPHY_PIO29), \
	REASON="linux_ENABLE_NETPHY_PIO29 set"; \
	$(call linux_CONFEDIT_SET,CONFIG_NETPHY_RESET_PIO_29), \
	REASON="linux_ENABLE_NETPHY_PIO29 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_NETPHY_RESET_PIO_29))

# Define: linux_CONFEDIT_MOCA_PHY
#
linux_CONFEDIT_MOCA_PHY = \
  $(if $(linux_ENABLE_MOCA_PHY), \
	REASON="linux_ENABLE_MOCA_PHY set"; \
	$(call linux_CONFEDIT_SET,CONFIG_MOCA_PHY), \
	REASON="linux_ENABLE_MOCA_PHY clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_MOCA_PHY))

# Define: linux_CONFEDIT_ETHERNET_FORCE_100M_FULL_DUPLEX
#
linux_CONFEDIT_ETHERNET_FORCE_100M_FULL_DUPLEX = \
  $(if $(linux_ENABLE_ETHERNET_FORCE_100M_FULL_DUPLEX), \
	REASON="linux_ENABLE_ETHERNET_FORCE_100M_FULL_DUPLEX set"; \
	$(call linux_CONFEDIT_SET,CONFIG_ETHERNET_FORCE_100M_FULL_DUPLEX), \
	REASON="linux_ENABLE_ETHERNET_FORCE_100M_FULL_DUPLEX clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_ETHERNET_FORCE_100M_FULL_DUPLEX))

# Define: linux_CONFEDIT_DVB_DMX_DIRECT_ACCESS
#
linux_CONFEDIT_DVB_DMX_DIRECT_ACCESS = \
  $(if $(linux_ENABLE_DVB_DMX_DIRECT_ACCESS), \
	REASON="linux_ENABLE_DVB_DMX_DIRECT_ACCESS set"; \
	$(call linux_CONFEDIT_SET,CONFIG_DVB_DMX_DIRECT_ACCESS), \
	REASON="linux_ENABLE_DVB_DMX_DIRECT_ACCESS clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_DMX_DIRECT_ACCESS))

# Define: linux_CONFEDIT_IP_MULTICAST
#
linux_CONFEDIT_IP_MULTICAST = \
  $(if $(linux_ENABLE_IP_MULTICAST), \
	REASON="linux_ENABLE_IP_MULTICAST set"; \
	$(call linux_CONFEDIT_SET,CONFIG_IP_MULTICAST), \
	REASON="linux_ENABLE_IP_MULTICAST clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_IP_MULTICAST))

# Define: linux_CONFEDIT_HWRNG
#
linux_CONFEDIT_HWRNG = \
  $(if $(linux_ENABLE_HWRNG), \
	REASON="linux_ENABLE_HWRNG set"; \
	$(call linux_CONFEDIT_SET,CONFIG_HW_RANDOM); \
	$(call linux_CONFEDIT_SET,CONFIG_HW_RANDOM_PNX833X), \
	REASON="linux_ENABLE_HWRNG clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_HW_RANDOM))

# Define: linux_CONFEDIT_WATCHDOG
#
linux_CONFEDIT_WATCHDOG = \
  $(if $(linux_ENABLE_WATCHDOG), \
	REASON="linux_ENABLE_WATCHDOG set"; \
	$(call linux_CONFEDIT_SET,CONFIG_WATCHDOG); \
	$(call linux_CONFEDIT_SET,CONFIG_PNX833X_WDT), \
	REASON="linux_ENABLE_WATCHDOG clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_WATCHDOG))

# Define: linux_CONFEDIT_WIRELESS_EXT
#
#linux_CONFEDIT_WIRELESS_EXT = \
#  $(if $(linux_ENABLE_WIRELESS_EXT), \
#	REASON="linux_ENABLE_WIRELESS_EXT set"; \
#	$(call linux_CONFEDIT_SET,CONFIG_WIRELESS_EXT), \
#	REASON="linux_ENABLE_WIRELESS_EXT clear"; \
#	$(call linux_CONFEDIT_UNSET,CONFIG_WIRELESS_EXT))

# Define: linux_CONFEDIT_V4L
#
linux_CONFEDIT_V4L = \
  $(if $(linux_ENABLE_V4L), \
	REASON="linux_ENABLE_V4L set"; \
	$(call linux_CONFEDIT_SET,CONFIG_VIDEO_DEV); \
	$(call linux_CONFEDIT_SET,CONFIG_VIDEO_V4L1); \
	$(call linux_CONFEDIT_SET,CONFIG_VIDEO_V4L1_COMPAT); \
	$(call linux_CONFEDIT_SET,CONFIG_VIDEO_V4L2); \
	$(call linux_CONFEDIT_SET,CONFIG_VIDEO_CAPTURE_DRIVERS); \
	$(call linux_CONFEDIT_UNSET,CONFIG_VIDEO_ADV_DEBUG); \
	$(call linux_CONFEDIT_SET,CONFIG_VIDEO_HELPER_CHIPS_AUTO); \
	$(call linux_CONFEDIT_UNSET,CONFIG_VIDEO_VIVI); \
	$(call linux_CONFEDIT_UNSET,CONFIG_VIDEO_CPIA); \
	$(call linux_CONFEDIT_UNSET,CONFIG_VIDEO_CPIA2); \
	$(call linux_CONFEDIT_UNSET,CONFIG_VIDEO_SAA5246A); \
	$(call linux_CONFEDIT_UNSET,CONFIG_VIDEO_SAA5249); \
	$(call linux_CONFEDIT_UNSET,CONFIG_TUNER_3036); \
	$(call linux_CONFEDIT_SET,CONFIG_V4L_USB_DRIVERS); \
	$(call linux_CONFEDIT_UNSET,CONFIG_VIDEO_PVRUSB2); \
	$(call linux_CONFEDIT_UNSET,CONFIG_VIDEO_EM28XX); \
	$(call linux_CONFEDIT_UNSET,CONFIG_VIDEO_USBVISION); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_VICAM); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_IBMCAM); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_KONICAWC); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_QUICKCAM_MESSENGER); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_ET61X251); \
	$(call linux_CONFEDIT_UNSET,CONFIG_VIDEO_OVCAMCHIP); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_W9968CF); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_OV511); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_SE401); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_SN9C102); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_STV680); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_ZC0301); \
	$(call linux_CONFEDIT_SET,CONFIG_USB_PWC); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_PWC_DEBUG); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_ZR364XX); \
	$(call linux_CONFEDIT_SET,CONFIG_RADIO_ADAPTERS); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_DSBR))

# Define: linux_CONFEDIT_SERIAL_PNX8XXX_UART0
#
linux_CONFEDIT_SERIAL_PNX8XXX_UART0 = \
  $(if $(linux_ENABLE_SERIAL_PNX8XXX_UART0), \
	REASON="linux_ENABLE_SERIAL_PNX8XXX_UART0 set"; \
	$(call linux_CONFEDIT_SET,CONFIG_SERIAL_PNX8XXX_UART0), \
	REASON="linux_ENABLE_SERIAL_PNX8XXX_UART0 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_SERIAL_PNX8XXX_UART0))

# Define: linux_CONFEDIT_SERIAL_PNX8XXX_TTYS0
#
linux_CONFEDIT_SERIAL_PNX8XXX_TTYS0 = \
  $(if $(linux_ENABLE_SERIAL_PNX8XXX_TTYS0), \
	REASON="linux_ENABLE_SERIAL_PNX8XXX_TTYS0 set"; \
	$(call linux_CONFEDIT_SET,CONFIG_SERIAL_PNX8XXX_TTYS0), \
	REASON="linux_ENABLE_SERIAL_PNX8XXX_TTYS0 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_SERIAL_PNX8XXX_TTYS0))

# Define: linux_CONFEDIT_SERIAL_PNX8XXX_UART1
#
linux_CONFEDIT_SERIAL_PNX8XXX_UART1 = \
  $(if $(linux_ENABLE_SERIAL_PNX8XXX_UART1), \
	REASON="linux_ENABLE_SERIAL_PNX8XXX_UART1 set"; \
	$(call linux_CONFEDIT_SET,CONFIG_SERIAL_PNX8XXX_UART1), \
	REASON="linux_ENABLE_SERIAL_PNX8XXX_UART1 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_SERIAL_PNX8XXX_UART1))

# Define: linux_CONFEDIT_SERIAL_PNX8XXX_TTYS1
#
linux_CONFEDIT_SERIAL_PNX8XXX_TTYS1 = \
  $(if $(linux_ENABLE_SERIAL_PNX8XXX_TTYS1), \
	REASON="linux_ENABLE_SERIAL_PNX8XXX_TTYS1 set"; \
	$(call linux_CONFEDIT_SET,CONFIG_SERIAL_PNX8XXX_TTYS1), \
	REASON="linux_ENABLE_SERIAL_PNX8XXX_TTYS1 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_SERIAL_PNX8XXX_TTYS1))

# Define: linux_CONFEDIT_SERIAL_PNX8XXX_CONSOLE
#
linux_CONFEDIT_SERIAL_PNX8XXX_CONSOLE = \
  $(if $(linux_ENABLE_SERIAL_PNX8XXX_CONSOLE), \
	REASON="linux_ENABLE_SERIAL_PNX8XXX_CONSOLE set"; \
	$(call linux_CONFEDIT_SET,CONFIG_SERIAL_PNX8XXX_CONSOLE), \
	REASON="linux_ENABLE_SERIAL_PNX8XXX_CONSOLE clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_SERIAL_PNX8XXX_CONSOLE))


linux_CONFEDIT_NXP_COMMON_INTERFACE =
linux_CONFEDIT_NXP_AK470X =
linux_CONFEDIT_NXP_UDA3000 =
linux_CONFEDIT_NXP_TDA9983 =
linux_CONFEDIT_NXP_LCD =
linux_CONFEDIT_NXP_SAA1064 =
linux_CONFEDIT_NXP_BOARD =
linux_CONFEDIT_NXP_RC_PROTOCOL =
linux_CONFEDIT_NXP_INFRA_RED =

# Define: linux_CONFEDIT_USBCORE
#
linux_CONFEDIT_USBCORE = \
  $(if $(linux_ENABLE_USBCORE), \
	REASON="linux_ENABLE_USBCORE set"; \
	$(call linux_CONFEDIT_SET,CONFIG_USB), \
	REASON="linux_ENABLE_USBCORE clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB))

# Define: linux_CONFEDIT_USBALSAKEY
#
#linux_CONFEDIT_USBALSAKEY = \
#  $(if $(linux_ENABLE_USBALSAKEY), \
#	REASON="linux_ENABLE_USBALSAKEY set"; \
#	$(call linux_CONFEDIT_SET_M,CONFIG_SND_USB_AUDIO), \
#	REASON="linux_ENABLE_USBALSAKEY clear"; \
#	$(call linux_CONFEDIT_UNSET,CONFIG_SND_USB_AUDIO))

# Define: linux_CONFEDIT_USBHID
#
linux_CONFEDIT_USBHID = \
  $(if $(linux_ENABLE_USBHID), \
	REASON="linux_ENABLE_USBHID set"; \
	$(call linux_CONFEDIT_SET,CONFIG_HID_SUPPORT); \
	$(call linux_CONFEDIT_SET_M,CONFIG_HID); \
	$(call linux_CONFEDIT_SET_M,CONFIG_USB_HID), \
	REASON="linux_ENABLE_USBHID clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_HID_SUPPORT); \
	$(call linux_CONFEDIT_UNSET,CONFIG_HID); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_HID))

# Define: linux_CONFEDIT_USBMASSKEY
#
linux_CONFEDIT_USBMASSKEY =

# Define: linux_CONFEDIT_USBNETKEY
#
linux_CONFEDIT_USBNETKEY = \
  $(if $(linux_ENABLE_USBNETKEY), \
	REASON="linux_ENABLE_USBNETKEY set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_USB_USBNET); \
	$(call linux_CONFEDIT_SET_M,CONFIG_USB_PEGASUS); \
	$(call linux_CONFEDIT_SET_M,CONFIG_USB_NET_AX8817X), \
	REASON="linux_ENABLE_USBNETKEY clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_USBNET); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_PEGASUS); \
	$(call linux_CONFEDIT_UNSET,CONFIG_USB_NET_AX8817X))

# Define: linux_CONFEDIT_DVB_TDA10021
#
linux_CONFEDIT_DVB_TDA10021 = \
  $(if $(linux_ENABLE_DVB_TDA10021), \
	REASON="linux_ENABLE_DVB_TDA10021 set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_TDA10021), \
	REASON="linux_ENABLE_DVB_TDA10021 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_TDA10021))

# Define: linux_CONFEDIT_DVB_TDA10023
#
linux_CONFEDIT_DVB_TDA10023 = \
  $(if $(linux_ENABLE_DVB_TDA10023), \
	REASON="linux_ENABLE_DVB_TDA10023 set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_TDA10023), \
	REASON="linux_ENABLE_DVB_TDA10023 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_TDA10023))

# Define: linux_CONFEDIT_DVB_TDA10024
#
linux_CONFEDIT_DVB_TDA10024 = \
  $(if $(linux_ENABLE_DVB_TDA10024), \
	REASON="linux_ENABLE_DVB_TDA10024 set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_TDA10024), \
	REASON="linux_ENABLE_DVB_TDA10024 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_TDA10024))

# Define: linux_CONFEDIT_DVB_TDA10046
#
# Warning: CONFIG_DVB_TDA1004X (ie ends in 'X') is controlled by linux_ENABLE_DVB_TDA10046 (ie ends in '6')
#          Got to love those crazy Caen guys... ;-)
#
linux_CONFEDIT_DVB_TDA10046 = \
  $(if $(linux_ENABLE_DVB_TDA10046), \
	REASON="linux_ENABLE_DVB_TDA10046 set... note X -vs- 6"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_TDA1004X), \
	REASON="linux_ENABLE_DVB_TDA10046 clear... note X -vs- 6"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_TDA1004X))

# Define: linux_CONFEDIT_DVB_TDA10048
#
linux_CONFEDIT_DVB_TDA10048 = \
  $(if $(linux_ENABLE_DVB_TDA10048), \
	REASON="linux_ENABLE_DVB_TDA10048 set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_TDA10048), \
	REASON="linux_ENABLE_DVB_TDA10048 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_TDA10048))

# Define: linux_CONFEDIT_ISDB_TC90507XBG
#
linux_CONFEDIT_ISDB_TC90507XBG = \
  $(if $(linux_ENABLE_ISDB_TC90507XBG), \
	REASON="linux_ENABLE_ISDB_TC90507XBG set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_ISDB_TC90507XBG), \
	REASON="linux_ENABLE_ISDB_TC90507XBG clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_ISDB_TC90507XBG))

# Define: linux_CONFEDIT_ISDB_MB86A20S
#
linux_CONFEDIT_ISDB_MB86A20S = \
  $(if $(linux_ENABLE_ISDB_MB86A20S), \
	REASON="linux_ENABLE_ISDB_MB86A20S set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_ISDB_MB86A20S), \
	REASON="linux_ENABLE_ISDB_MB86A20S clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_ISDB_MB86A20S))

# Define: linux_CONFEDIT_DVB_TDA10086
#
linux_CONFEDIT_DVB_TDA10086 = \
  $(if $(linux_ENABLE_DVB_TDA10086), \
	REASON="linux_ENABLE_DVB_TDA10086 set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_TDA10086), \
	REASON="linux_ENABLE_DVB_TDA10086 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_TDA10086))

# Define: linux_CONFEDIT_DVB_TDA826X
#
linux_CONFEDIT_DVB_TDA826X = \
  $(if $(linux_ENABLE_DVB_TDA826X), \
	REASON="linux_ENABLE_DVB_TDA826X set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_TDA826X), \
	REASON="linux_ENABLE_DVB_TDA826X clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_TDA826X))

# Define: linux_CONFEDIT_DVB_TDA827X
#
linux_CONFEDIT_DVB_TDA827X = \
  $(if $(linux_ENABLE_DVB_TDA827X), \
	REASON="linux_ENABLE_DVB_TDA827X set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_TDA827X), \
	REASON="linux_ENABLE_DVB_TDA827X clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_TDA827X))

# Define: linux_CONFEDIT_DVB_TDA18211
#
linux_CONFEDIT_DVB_TDA18211 = \
  $(if $(linux_ENABLE_DVB_TDA18211), \
	REASON="linux_ENABLE_DVB_TDA18211 set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_TDA18211), \
	REASON="linux_ENABLE_DVB_TDA18211 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_TDA18211))


# Define: linux_CONFEDIT_DVB_TDA18218
#
linux_CONFEDIT_DVB_TDA18218 = \
  $(if $(linux_ENABLE_DVB_TDA18218), \
	REASON="linux_ENABLE_DVB_TDA18218 set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_TDA18218), \
	REASON="linux_ENABLE_DVB_TDA18218 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_TDA18218))

# Define: linux_CONFEDIT_DVB_TD1316
#
linux_CONFEDIT_DVB_TD1316 = \
  $(if $(linux_ENABLE_DVB_TD1316), \
	REASON="linux_ENABLE_DVB_TD1316 set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_TD1316), \
	REASON="linux_ENABLE_DVB_TD1316 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_TD1316))

# Define: linux_CONFEDIT_DVB_CD1616
#
linux_CONFEDIT_DVB_CD1616 = \
  $(if $(linux_ENABLE_DVB_CD1616), \
	REASON="linux_ENABLE_DVB_CD1616 set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_CD1616), \
	REASON="linux_ENABLE_DVB_CD1616 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_CD1616))

# Define: linux_CONFEDIT_DVB_TDA18252
#
linux_CONFEDIT_DVB_TDA18252 = \
  $(if $(linux_ENABLE_DVB_TDA18252), \
	REASON="linux_ENABLE_DVB_TDA18252 set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_TDA18252), \
	REASON="linux_ENABLE_DVB_TDA18252 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_TDA18252))

# Define: linux_CONFEDIT_DVB_MAX3541
#
linux_CONFEDIT_DVB_MAX3541 = \
  $(if $(linux_ENABLE_DVB_MAX3541), \
	REASON="linux_ENABLE_DVB_MAX3541 set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_MAX3541), \
	REASON="linux_ENABLE_DVB_MAX3541 clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_MAX3541))

# Define: linux_CONFEDIT_DVB_GYX1D
#
linux_CONFEDIT_DVB_GYX1D = \
  $(if $(linux_ENABLE_DVB_GYX1D), \
	REASON="linux_ENABLE_DVB_GYX1D set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_DVB_GYX1D), \
	REASON="linux_ENABLE_DVB_GYX1D clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_DVB_GYX1D))

# Define: linux_CONFEDIT_ISDB_TDA665XTT
#
linux_CONFEDIT_ISDB_TDA665XTT = \
  $(if $(linux_ENABLE_ISDB_TDA665XTT), \
	REASON="linux_ENABLE_ISDB_TDA665XTT set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_ISDB_TDA665XTT), \
	REASON="linux_ENABLE_ISDB_TDA665XTT clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_ISDB_TDA665XTT))

# Define: linux_CONFEDIT_ISDB_TUA6039F
#
linux_CONFEDIT_ISDB_TUA6039F = \
  $(if $(linux_ENABLE_ISDB_TUA6039F), \
	REASON="linux_ENABLE_ISDB_TUA6039F set"; \
	$(call linux_CONFEDIT_SET_M,CONFIG_ISDB_TUA6039F), \
	REASON="linux_ENABLE_ISDB_TUA6039F clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_ISDB_TUA6039F))

# Define: linux_CONFEDIT_PM
#
linux_CONFEDIT_PM = \
  $(if $(linux_ENABLE_PM), \
	REASON="linux_ENABLE_PM set"; \
	$(call linux_CONFEDIT_SET,CONFIG_PM), \
	REASON="linux_ENABLE_PM clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_PM))

# Define: linux_CONFEDIT_GPIO_INTERRUPTS
#
linux_CONFEDIT_GPIO_INTERRUPTS = \
  $(if $(linux_ENABLE_GPIO_INTERRUPTS), \
	REASON="linux_ENABLE_GPIO_INTERRUPTS set"; \
	$(call linux_CONFEDIT_SET,CONFIG_PNX833X_GPIO); \
	$(call linux_CONFEDIT_SET,CONFIG_PNX833X_GPIO_INTERRUPTS), \
	REASON="linux_ENABLE_GPIO_INTERRUPTS clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_PNX833X_GPIO_INTERRUPTS))


linux_CONFEDIT_TIME_DOCTOR = \
  $(if $(linux_ENABLE_TIME_DOCTOR), \
	REASON="linux_ENABLE_TIME_DOCTOR set"; \
	$(call linux_CONFEDIT_SET,CONFIG_TIME_DOCTOR); \
	$(call linux_CONFEDIT_SET,CONFIG_TIME_DOCTOR_PRESERVE_OVER_REBOOT); \
	$(call linux_CONFEDIT_SET,CONFIG_TIME_DOCTOR_AUTO_START); \
	$(call linux_CONFEDIT_SET_INTEGER,CONFIG_TIME_DOCTOR_SAMPLES,$(linux_TIME_DOCTOR_BUFFER_SIZE)), \
	REASON="linux_ENABLE_TIME_DOCTOR clear"; \
	$(call linux_CONFEDIT_UNSET,CONFIG_TIME_DOCTOR))

# ----------------------------------------------------------------------------

linux_CHECK_FILE_IS_NOT_CHANGED = $(call CHECK_FILE_IS_NOT_CHANGED,$$KSRC/.config,$$KSRC/.config.refcopy, \
  if [ -f $$KSRC/.config -a -f $$KSRC/.config.refcopy ]; then echo; diff -u $$KSRC/.config.refcopy $$KSRC/.config; echo; fi; \
  echo 'The linux.config target would overwrite this file which you may not want!'; \
  echo 'Please verify that this is ok or save the modified file'; \
  echo '(for example, using  prjmake linux.meldconfig).'; \
  echo 'Then run: "rm $(KSRC)/.config.refcopy"'; \
  echo 'and repeat the original command.')

# Macro: linux.config_CMDS
# Configures Linux kernel.
# - Saves existing <KSRC>/.config to <KSRC>/.config_YYMMDD_HHMMSS.
# - Installs .config file from <KERNELCONFIG>
# - Updated .config file based on prjconfig + platform config options
# - Runs Linux kernel oldconfig target to synchronize the .config files with the Kconfig files in the Linux tree.
# linux.config is dependent on .prjconfig
#
# This target does nothing if <KSRC_override> is defined.
define linux.config_CMDS
	$(Q)$(linux_CHECK_FILE_IS_NOT_CHANGED)
	@echo -e "\nConfig file in   : $(KERNELCONFIG)\nConfig file out  : $$KSRC/.config\n"
	@cp -f $(KERNELCONFIG) $$KSRC/.config.tmp
	$(Q)$(linux_CONFEDIT_LOCALVERSION)
	$(Q)$(linux_CONFEDIT_ENDIAN)
	$(Q)$(linux_CONFEDIT_OPTSIZE)
	$(Q)$(linux_CONFEDIT_PREEMPT)
	$(Q)$(linux_CONFEDIT_HI_RES_TIMERS)
	$(Q)$(linux_CONFEDIT_NO_HZ)
	$(Q)$(linux_CONFEDIT_DEBUG)
	$(Q)$(linux_CONFEDIT_ATA)
	$(Q)$(linux_CONFEDIT_BLK_DEV_LOOP)
	$(Q)$(linux_CONFEDIT_EXT2_FS)
	$(Q)$(linux_CONFEDIT_EXT3_FS)
	$(Q)$(linux_CONFEDIT_NTFS_FS)
	$(Q)$(linux_CONFEDIT_CRAMFS_FS)
	$(Q)$(linux_CONFEDIT_JFFS2_FS)
	$(Q)$(linux_CONFEDIT_SQUASHFS_FS)
	$(Q)$(linux_CONFEDIT_YAFFS_FS)
	$(Q)$(linux_CONFEDIT_NAND_FLASH)
	$(Q)$(linux_CONFEDIT_NOR_FLASH)
	$(Q)$(linux_CONFEDIT_WIRELESS_EXT)
	$(Q)$(linux_CONFEDIT_V4L)
	$(Q)$(linux_CONFEDIT_SERIAL_PNX8XXX_UART0)
	$(Q)$(linux_CONFEDIT_SERIAL_PNX8XXX_TTYS0)
	$(Q)$(linux_CONFEDIT_SERIAL_PNX8XXX_UART1)
	$(Q)$(linux_CONFEDIT_SERIAL_PNX8XXX_TTYS1)
	$(Q)$(linux_CONFEDIT_SERIAL_PNX8XXX_CONSOLE)
	$(Q)$(linux_CONFEDIT_NXP_COMMON_INTERFACE)
	$(Q)$(linux_CONFEDIT_NXP_AK470X)
	$(Q)$(linux_CONFEDIT_NXP_UDA3000)
	$(Q)$(linux_CONFEDIT_NXP_TDA9983)
	$(Q)$(linux_CONFEDIT_NXP_LCD)
	$(Q)$(linux_CONFEDIT_NXP_SAA1064)
	$(Q)$(linux_CONFEDIT_NXP_BOARD)
	$(Q)$(linux_CONFEDIT_NXP_RC_PROTOCOL)
	$(Q)$(linux_CONFEDIT_NXP_INFRA_RED)
	$(Q)$(linux_CONFEDIT_DVB_TDA10021)
	$(Q)$(linux_CONFEDIT_DVB_TDA10023)
	$(Q)$(linux_CONFEDIT_DVB_TDA10024)
	$(Q)$(linux_CONFEDIT_DVB_TDA10046)
	$(Q)$(linux_CONFEDIT_DVB_TDA10048)
	$(Q)$(linux_CONFEDIT_ISDB_TC90507XBG)
	$(Q)$(linux_CONFEDIT_ISDB_TDA665XTT)
	$(Q)$(linux_CONFEDIT_ISDB_MB86A20S)
	$(Q)$(linux_CONFEDIT_ISDB_TUA6039F)
	$(Q)$(linux_CONFEDIT_DVB_TDA10086)
	$(Q)$(linux_CONFEDIT_DVB_TDA826X)
	$(Q)$(linux_CONFEDIT_DVB_TDA827X)
	$(Q)$(linux_CONFEDIT_DVB_TDA18211)
	$(Q)$(linux_CONFEDIT_DVB_TDA18218)
	$(Q)$(linux_CONFEDIT_DVB_TD1316)
	$(Q)$(linux_CONFEDIT_DVB_CD1616)
	$(Q)$(linux_CONFEDIT_DVB_TDA18252)
	$(Q)$(linux_CONFEDIT_DVB_MAX3541)
	$(Q)$(linux_CONFEDIT_DVB_GYX1D)
	$(Q)$(linux_CONFEDIT_IP_MULTICAST)
	$(Q)$(linux_CONFEDIT_HWRNG)
	$(Q)$(linux_CONFEDIT_WATCHDOG)
	$(Q)$(linux_CONFEDIT_PRINTK)
	$(Q)$(linux_CONFEDIT_ETHERNET)
	$(Q)$(linux_CONFEDIT_IP3902)
	$(Q)$(linux_CONFEDIT_IP3902_CA)
	$(Q)$(linux_CONFEDIT_SMSC911X)
	$(Q)$(linux_CONFEDIT_USBCORE)
	$(Q)$(linux_CONFEDIT_USBALSAKEY)
	$(Q)$(linux_CONFEDIT_USBHID_no_thank_you)
	$(Q)$(linux_CONFEDIT_USBMASSKEY_no_thank_you)
	$(Q)$(linux_CONFEDIT_USBNETKEY)
	$(Q)$(linux_CONFEDIT_NETPHY_PIO29)
	$(Q)$(linux_CONFEDIT_MOCA_PHY)
	$(Q)$(linux_CONFEDIT_ETHERNET_FORCE_100M_FULL_DUPLEX)
	$(Q)$(linux_CONFEDIT_PM)
	$(Q)$(linux_CONFEDIT_DVB_DMX_DIRECT_ACCESS)
	$(Q)$(linux_CONFEDIT_GPIO_INTERRUPTS)
	$(Q)$(linux_CONFEDIT_TIME_DOCTOR)
	@echo
	$(Q)cd $$KSRC && \
		if ! cmp -s .config.tmp .config; then \
			if [ -f .config ]; then mv -f .config .config_`date '+%Y%m%d_%H%M%S'`; fi; \
			mv -f .config.tmp .config; \
		fi
	$(MAKECMD) --directory=$$KSRC $(linux_MAKEOPTS) oldconfig >/dev/null </dev/null
	$(linux.post_config_CMDS)
	$(Q)cd $$KSRC && cp -fa .config .config.refcopy
endef

MAYBE_GENERATED_VERSION_FILE:=$(wildcard $(BUILDROOT)/generated_setup_productversion.mk)

$(call PKG_TARGET, linux.config, linux.$(config_PREDECESSOR))
$(call OBJ_TARGET_OTHER_DEPS,linux.config,$(KERNELCONFIG) $(BUILDROOT)/.prjconfig $(PRJROOT)/etc/setup_productversion.mk $(MAYBE_GENERATED_VERSION_FILE))

endif # ifneq "$(KSRC_override)" ""

linux.menuconfig: linux.config
	cd $$KSRC && \
	  $(MAKECMD) $(linux_MAKEOPTS) menuconfig
	$(linux.post_config_CMDS)

linux.oldconfig: linux.config
	cd $$KSRC && \
	  $(MAKECMD) $(linux_MAKEOPTS) oldconfig
	$(linux.post_config_CMDS)

linux.meldconfig:
	-meld $(KERNELCONFIG) $$KSRC/.config

linux.diffconfig:
	-diff $(DIFFCONFIG_OPTS) $(KERNELCONFIG) $$KSRC/.config || true

linux.udiffconfig:
	-diff -u $(KERNELCONFIG) $$KSRC/.config || true

linux.updconfig:
	cp -f $$KSRC/.config $(KERNELCONFIG)

# Macro: linux.make_POSTCMDS
# Optional set of commands to be performed after making the Linux kernel image.
# For example, it could copy the kernel image to the <TFTPBOOT> directory.
#
# Not used if <KSRC_override> is defined.

# Target: linux.make
# Builds the linux kernel and modules.
# - It has no actions of its own, unless <linux.make_POSTCMDS> is defined.
# - It has a dependency on the <linux.kernel.make> target.
# - If <linux_CONFIG_MODULES> is defined it also has a dependency on the
#
# If <KSRC_override> is defined then this target only calls
# <linux.ext.modules.make>.
define linux.make_CMDS
	$(if $(filter-out undefined, $(origin linux.make_POSTCMDS)),$(linux.make_POSTCMDS))
endef
$(call PKG_TARGET, linux.make, \
  $(if $(KSRC_override),,linux.kernel.make) \
  $(if $(linux_CONFIG_MODULES),linux.modules.make))

$(call OBJ_AUTO_FORCE,linux.make,\
  $(if $(KSRC_override),,linux.kernel.make) \
  $(if $(linux_CONFIG_MODULES), \
    $(if $(KSRC_override),,linux.int.modules.make) \
    linux.ext.modules.make \
  )\
)

# Target: linux.modules.make
# Builds the linux kernel modules.
# It has no actions of its own, but only a dependency on the
# <linux.int.modules.make> and
# <linux.ext.modules.make> target.
#
# This target does not call <linux.int.modules.make>
# if <KSRC_override> is defined.
linux.modules.make_CMDS=
$(call PKG_TARGET, linux.modules.make, \
  $(if $(KSRC_override),,linux.int.modules.make) \
  linux.ext.modules.make \
)

$(if $(linux_CONFIG_MODULES), \
  $(call OBJ_AUTO_FORCE,linux.modules.make,\
    $(if $(KSRC_override),,linux.int.modules.make) \
    linux.ext.modules.make \
  )\
)

#
# modules.dep files created by newer versions of depmod (Ubuntu 9.10, Fedora 12, etc)
# don't include full path to module files, which breaks older versions of modprobe,
# including the version in busybox 1.11.x
#
# sed -i apparently causes problems for nfs build dirs... use temp file + mv instead
#
# But, for BrightSign we've fixed this inside busybox's modprobe
# because it got too painful to fix up modules.dep when we're
# installing third party modules from outside the NXP build system so
# we don't need this.
define linux.kernel.make_fix_depmod_CMDS
#	KERNELRELEASE=$$($(MAKECMD) --no-print-directory -C $$KSRC $(linux_MAKEOPTS) kernelrelease) && \
#	MODULES_DEP="$(ROOTFS)/lib/modules/$${KERNELRELEASE}/modules.dep" && \
#	FILESIZE_BEFORE=$$(wc -c < $${MODULES_DEP}) && \
#	sed "s@\(^\|[ \t]\+\)\(extra\|kernel\)/@\1/lib/modules/$${KERNELRELEASE}/\2/@g" < $${MODULES_DEP} > $${MODULES_DEP}_tmp && \
#	mv $${MODULES_DEP}_tmp $${MODULES_DEP} && \
#	FILESIZE_AFTER=$$(wc -c < $${MODULES_DEP}) && \
#	if [ "$${FILESIZE_BEFORE}" -eq "$${FILESIZE_AFTER}" ]; then \
#		echo; echo "  DEPMOD absolute path fix not required"; else \
#		echo; echo "  DEPMOD absolute path fix WAS required ($${FILESIZE_BEFORE} -> $${FILESIZE_AFTER}) !"; \
#	fi
endef

# If we're building an initrd then we need to make sure the device
# nodes are correct but we can only do that under
# fakeroot. Unfortunately that means we must have to run the entire
# kernel build under fakeroot. Newer versions of fakeroot object to
# recursing into another fakeroot so we ensure that the new fakeroot
# doesn't know about the old one.
ifeq "$(linux_USE_INITRAMFS)" "true"
  define linux.kernel.compile_CMDS
	@echo Making kernel under fakeroot
	$(Q)STRIP="$(CROSS_COMPILE)strip" SSTRIP="$(PRJROOT)/bin/sstrip" $(PRJROOT)/bin/stripdir $(ROOTFS)
	$(Q)find $(ROOTFS)/dev -mindepth 1 -maxdepth 1 \( \! -name MAKEDEV \) -type f -exec rm -f "{}" \;
	$(Q)FAKEROOTKEY= fakeroot /bin/sh -c '(cd $(ROOTFS)/dev && ./MAKEDEV) && $(MAKECMD) -C $$KSRC $(linux_MAKEOPTS) uImage'
  endef
else
  define linux.kernel.compile_CMDS
	@echo Making kernel normally
	$(Q)$(MAKECMD) -C $$KSRC $(linux_MAKEOPTS) uImage
	$(Q)$(MAKECMD) -C $$KSRC $(linux_MAKEOPTS) headers_install unwanted= INSTALL_HDR_PATH=$(STAGINGDIR)/usr
# This blatant hack is necessary because otherwise these headers are
# found in preference to the ones included in alsa-lib during alsa-lib
# compilation. :(
	$(Q)rm -rf $(STAGINGDIR)/usr/include/sound
  endef
endif

# Target: <linux.kernel.make>
# Builds the kernel, but not its modules.
# Generates:
# - uImage
# - auImage (signed version of uImage).
# - auImage_enc (AES encoded, signed version of uImage).
# Calls Linux headers_install target with INSTALL_HDR_PATH set to ${<STAGINGDIR>}/usr.
# It sets 'unwanted' to empty so that it does not remove any header files
# that may have been installed since an earlier kernel build.
#
# Target <buildroot.toolchain> will be called first to ensure that the toolchain
# installs header files first, which then get updated with the correct versions
# of header files from this kernel version.
#
# See: <linux.modules.make> <linux_DEFMAKEOPTS> <linux_CONFIG_MODULES>
#
# This target does nothing if <KSRC_override> is defined.

ifeq "$(KSRC_override)" ""
  define linux.kernel.make_auImage_CMDS
	if ! [ $${KSRC}/auImage -nt $${KSRC}/uImage ]; then \
		$(PRJROOT)/bin/aimage_sign --type uImage --linkaddress $(linux_LOADADDRESS) \
			$(if $(CONFIG_NAND_FLASH),--padmodulo $(shell let EBS=$(CONFIG_NAND_FLASH_ERASE_BLOCK_SIZE); echo $$EBS)) \
			$${KSRC}/uImage $${KSRC}/auImage && chmod a+r $${KSRC}/auImage; fi
	if ! [ $${KSRC}/auImage_enc -nt $${KSRC}/uImage ]; then \
		$(PRJROOT)/bin/aimage_sign --type uImage --linkaddress $(linux_LOADADDRESS) \
			$(if $(CONFIG_NAND_FLASH),--padmodulo $(shell let EBS=$(CONFIG_NAND_FLASH_ERASE_BLOCK_SIZE); echo $$EBS)) \
			--encmode cbc_onepass --aeskey 000102030405060708090A0B0C0D0E0F \
			$${KSRC}/uImage $${KSRC}/auImage_enc && chmod a+r $${KSRC}/auImage_enc; fi
  endef
  define linux.kernel.make_CMDS
	@echo '  KERNEL Linux'
	$(Q)rm -f $$KSRC/drivers/nxp/.*Pass
	$(linux.kernel.compile_CMDS)
	$(Q)$(if $(filter true,$(linux_USE_INITRAMFS)),echo 'All files:'; $(PRJROOT)/bin/dir_list_hashes $(ROOTFS); echo)
	$(if $(wildcard $(PRJROOT)/bin/aimage_sign),$(linux.kernel.make_auImage_CMDS))
  endef
  $(call PKG_TARGET, linux.kernel.make, linux.$(make_PREDECESSOR) buildroot.toolchain)
endif # ifeq "$(KSRC_override)" ""


# Clean up modules directories for different versions so we don't run
# out of space in the rootfs when the version number is changing lots.
#
# When this used to be done in linux.install it wasn't clear when it
# was actually run (and it wasn't when it should have been) so let's
# always run it immediately after the symlinks are created.
#
# Also blow away a directory in staging that can be used to hold stamp
# files to indicate whether other third party modules need installing.
define linux.kernel.clean_modules_junk_CMDS
	$(Q)echo "Our modules directory is believed to be $(linux_VERSION)$(linux_LOCALVERSION)"
	$(Q)for d in $(ROOTFS)/lib/modules/*; do \
		if [ ! $$d -ef $(ROOTFS)/lib/modules/$(linux_VERSION)$(linux_LOCALVERSION) ]; then \
			echo "Cleaning up mismatched modules directory `basename "$$d"`"; \
			rm -rf "$$d" && \
			rm -rf "$(STAGINGDIR)/.modules.`basename "$$d"`"; \
		fi; \
	done
	$(Q)rm -f $(ROOTFS)/lib/modules/*/{build,source}
endef

# Target: <linux.int.modules.make>
# Build the Linux internal (in-tree) kernel modules.
# It fails if <linux_CONFIG_MODULES> is not defined.
#
# See: <linux_DEFMAKEOPTS> <linux_CONFIG_MODULES>
#
# This target does nothing if <KSRC_override> is defined.
ifeq "$(KSRC_override)" ""
  define linux.int.modules.make_CMDS
	$(linux.post_config_CMDS)
	$(if $(linux_CONFIG_MODULES),@echo '  IN-TREE MODULES Linux',@echo '  MODULES Linux: disabled!'; exit 1)
	$(if $(linux_CONFIG_MODULES),$(Q)rm -f $$KSRC/drivers/nxp/.*Pass)
	$(if $(linux_CONFIG_MODULES),$(Q)$(MAKECMD) -C $$KSRC $(linux_MAKEOPTS) KMODULE_SELECT=none modules)
	$(if $(linux_CONFIG_MODULES),$(Q)$(MAKECMD) -C $$KSRC $(linux_MAKEOPTS) KMODULE_SELECT=none modules_install)
	$(if $(linux_CONFIG_MODULES),$(Q)$(linux.kernel.make_fix_depmod_CMDS))
	$(linux.kernel.clean_modules_junk_CMDS)
	mkdir -p $(STAGINGDIR)/.modules.$(linux_VERSION)$(linux_LOCALVERSION)
  endef
  $(call PKG_TARGET, linux.int.modules.make, linux.kernel.make)
endif # ifeq "$(KSRC_override)" ""

# Define: linux_EXT_MODULE_BUILDDIR
# Build directory for the external kernel modules.
# Default value is "${<CPUBUILDROOT>}/kmodules".
linux_EXT_MODULE_BUILDDIR=$(CPUBUILDROOT)/kmodules

# Target: <linux.ext.modules.make>
# Build the external kernel modules.
# It fails if <linux_CONFIG_MODULES> is not defined.
#
# See: <linux_DEFMAKEOPTS> <linux_CONFIG_MODULES>
# <linux_EXT_MODULE_BUILDDIR>
define linux.ext.modules.make_CMDS
	$(linux.post_config_CMDS)
	$(if $(linux_CONFIG_MODULES),@echo '  EXTERNAL MODULES Linux',@echo '  MODULES Linux: disabled!'; exit 1)
	$(Q)mkdir -p $(linux_EXT_MODULE_BUILDDIR)
	$(Q)rm -f $(linux_EXT_MODULE_BUILDDIR)/.*Pass
	$(Q)cp -af $(linux_SRCDIR)/external_modules.mk $(linux_EXT_MODULE_BUILDDIR)/Makefile
	$(Q)$(MAKECMD) -C $$KSRC $(linux_MAKEOPTS) KMODULE_SELECT=m modules M=$(linux_EXT_MODULE_BUILDDIR)
	$(Q)$(MAKECMD) -C $$KSRC $(linux_MAKEOPTS) KMODULE_SELECT=m modules_install M=$(linux_EXT_MODULE_BUILDDIR)
	$(Q)$(linux.kernel.make_fix_depmod_CMDS)
	$(linux.kernel.clean_modules_junk_CMDS)
	mkdir -p $(STAGINGDIR)/.modules.$(linux_VERSION)$(linux_LOCALVERSION)
endef
$(call PKG_TARGET, linux.ext.modules.make, $(if $(KSRC_override),linux.$(make_PREDECESSOR),linux.kernel.make))
$(call OBJ_TARGET_OTHER_DEPS, linux.ext.modules.make, $(linux_SRCDIR)/external_modules.mk)

# Target: <linux.install>
# This target only removes unwanted build and source symlinks
# from $(ROOTFS)/lib/modules/* .
# Use <linux.make> instead to install any modules.
define linux.install_CMDS
	@echo "Linux header files have already been installed via linux.kernel.make (or linux.make)."
	@echo "Linux kernel modules have already been installed via linux.modules.make (or linux.make)."
	$(Q)rm -f $(ROOTFS)/lib/modules/*/{build,source}
endef

$(call PKG_TARGET, linux.install, linux.$(install_PREDECESSOR))
$(call OBJ_AUTO_FORCE,linux.install, linux.make)

define linux_MAKE_DOCS
linux.$(1)docs: linux.patch
	cd $$$$KSRC && \
	    $$(MAKECMD) $$(linux_MAKEOPTS) $(1)docs
endef
$(foreach type,html man ps pdf xml, $(eval $(call linux_MAKE_DOCS,$(type))))

$(eval $(PKG_END))

include $(linux_SRCDIR)/initramfs.mk

linux.help:
	@printf '%-32s - %s\n' 'make linux.modules.make' 'Makes all loadable kmodules'
	@printf '%-32s - %s\n' 'make linux.int.modules.make' 'Makes loadable kmodules that are internal to $$KSRC'
	@printf '%-32s - %s\n' 'make linux.ext.modules.make' 'Makes loadable kmodules that are external to $$KSRC'
	@printf '%-32s - %s\n' 'make linux.htmldocs' 'Runs make htmldocs in $$KSRC'
	@printf '%-32s - %s\n' '# To view linux.htmldocs, run:' 'htmlview $$KSRC/Documentation/DocBook/index.html'
	@printf '%-32s - %s\n' 'make linux.mandocs' 'Runs make mandocs in $$KSRC'
	@printf '%-32s - %s\n' 'make linux.pdfdocs' 'Runs make pdfdocs in $$KSRC'
	@printf '%-32s - %s\n' 'make linux.psdocs' 'Runs make psdocs in $$KSRC'
	@printf '%-32s - %s\n' 'make linux.xmldocs' 'Runs make xmldocs in $$KSRC'
	@printf '%-32s - %s\n' 'make linux.menuconfig' 'Runs make menuconfig to update $$KSRC/.config'
	@printf '%-32s - %s\n' 'make linux.oldconfig' 'Runs make oldconfig to update $$KSRC/.config'
	@printf '%-32s - %s\n' 'make linux.meldconfig' 'Runs: meld on $(patsubst $(PRJROOT)/%,%,$(KERNELCONFIG)) and $$KSRC/.config'
	@printf '%-32s - %s\n' 'make linux.diffconfig' 'Runs: "diff $${DIFFCONFIG_OPTS}" on $(patsubst $(PRJROOT)/%,%,$(KERNELCONFIG)) and $$KSRC/.config'
	@printf '%-32s - %s\n' 'make linux.udiffconfig' 'Runs: "diff -u" on $(patsubst $(PRJROOT)/%,%,$(KERNELCONFIG)) and $$KSRC/.config'
	@printf '%-32s - %s\n' 'make linux.updconfig' 'Updates $(patsubst $(PRJROOT)/%,%,$(KERNELCONFIG)) from $$KSRC/.config'
	@printf '%-32s - %s\n' 'linux source .config file' '$(patsubst $(PRJROOT)/%,%,$(KERNELCONFIG))'
	@printf '%-32s - %s\n' 'linux build  .config file' '$(patsubst $(PRJROOT)/%,%,$(KSRC)/.config)'
	@printf '%-32s - %s\n' 'make linux.externaltree.help' 'Show help on using external KSRC tree'

linux.externaltree.help:
	@printf 'If make or environment variable KSRC_override is true, then targets\n'
	@printf 'linux.patch, linux.config, linux.kernel.make, and linux.int.modules.make\n'
	@printf 'only print a message saying they are skipped (using external KSRC tree).\n'

include $(PRJROOT)/etc/last.mk
