2009-08-16 13:35:34 +08:00
#
2011-01-27 20:21:10 +08:00
# Copyright (C) 2006-2011 OpenWrt.org
2007-03-24 21:42:54 +08:00
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
KERNEL_MAKEOPTS := -C $( LINUX_DIR) \
2012-07-20 20:28:50 +08:00
HOSTCFLAGS = " $( HOST_CFLAGS) -Wall -Wmissing-prototypes -Wstrict-prototypes " \
2007-03-24 21:42:54 +08:00
CROSS_COMPILE = " $( KERNEL_CROSS) " \
ARCH = " $( LINUX_KARCH) " \
2007-12-27 06:21:56 +08:00
KBUILD_HAVE_NLS = no \
2012-04-27 01:53:56 +08:00
CONFIG_SHELL = " $( BASH) " \
2012-05-05 20:48:35 +08:00
$( if $( findstring c,$( OPENWRT_VERBOSE) ) ,V= 1,V= '' )
2007-03-24 21:42:54 +08:00
2009-08-08 22:22:04 +08:00
i f d e f C O N F I G _ S T R I P _ K E R N E L _ E X P O R T S
KERNEL_MAKEOPTS += \
EXTRA_LDSFLAGS = " -I $( KERNEL_BUILD_DIR) -include symtab.h "
e n d i f
2007-10-23 14:23:29 +08:00
INITRAMFS_EXTRA_FILES ?= $( GENERIC_PLATFORM_DIR) /image/initramfs-base-files.txt
2007-10-23 14:23:23 +08:00
i f n e q ( , $( KERNEL_CC ) )
KERNEL_MAKEOPTS += CC = " $( KERNEL_CC) "
e n d i f
2014-04-13 05:21:49 +08:00
i f d e f C O N F I G _ U S E _ S P A R S E
KERNEL_MAKEOPTS += C = 1 CHECK = $( STAGING_DIR_HOST) /bin/sparse
e n d i f
2011-07-02 14:49:56 +08:00
export HOST_EXTRACFLAGS = -I$( STAGING_DIR_HOST) /include
2007-06-03 16:28:05 +08:00
# defined in quilt.mk
Kernel/Patch : =$( Kernel /Patch /Default )
2014-06-02 20:45:19 +08:00
KERNEL_GIT_OPTS :=
i f n e q ( $( strip $ ( CONFIG_KERNEL_GIT_LOCAL_REPOSITORY ) ) , "" )
KERNEL_GIT_OPTS += --reference $( CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)
e n d i f
2014-06-02 20:45:22 +08:00
i f n e q ( $( strip $ ( CONFIG_KERNEL_GIT_BRANCH ) ) , "" )
KERNEL_GIT_OPTS += --branch $( CONFIG_KERNEL_GIT_BRANCH)
e n d i f
2007-11-20 21:21:01 +08:00
i f e q ( $( strip $ ( CONFIG_EXTERNAL_KERNEL_TREE ) ) , "" )
2008-10-10 18:07:45 +08:00
ifeq ( $( strip $( CONFIG_KERNEL_GIT_CLONE_URI) ) ,"" )
define Kernel/Prepare/Default
2014-03-23 03:52:48 +08:00
xzcat $( DL_DIR) /$( LINUX_SOURCE) | $( TAR) -C $( KERNEL_BUILD_DIR) $( TAR_OPTIONS)
2007-06-03 16:28:05 +08:00
$( Kernel/Patch)
2008-08-27 22:14:00 +08:00
touch $( LINUX_DIR) /.quilt_used
2008-10-10 18:07:45 +08:00
endef
else
2014-06-02 20:45:16 +08:00
define Kernel/Prepare/Default
2014-06-02 20:45:19 +08:00
git clone $( KERNEL_GIT_OPTS) $( CONFIG_KERNEL_GIT_CLONE_URI) $( LINUX_DIR)
2014-06-02 20:45:16 +08:00
endef
2008-10-10 18:07:45 +08:00
endif
e l s e
define Kernel/Prepare/Default
2007-11-20 21:21:01 +08:00
mkdir -p $( KERNEL_BUILD_DIR)
if [ -d $( LINUX_DIR) ] ; then \
rmdir $( LINUX_DIR) ; \
fi
ln -s $( CONFIG_EXTERNAL_KERNEL_TREE) $( LINUX_DIR)
2008-10-10 18:07:45 +08:00
endef
2007-11-20 21:21:01 +08:00
e n d i f
2007-03-24 21:42:54 +08:00
2010-06-27 04:42:38 +08:00
i f e q ( $( CONFIG_TARGET_ROOTFS_INITRAMFS ) , y )
2012-04-05 22:33:04 +08:00
ifeq ( $( strip $( CONFIG_EXTERNAL_CPIO) ) ,"" )
2012-11-01 01:32:37 +08:00
define Kernel/SetInitramfs/PreConfigure
grep -v -e INITRAMFS -e CONFIG_RD_ -e CONFIG_BLK_DEV_INITRD $( LINUX_DIR) /.config.old > $( LINUX_DIR) /.config
echo 'CONFIG_BLK_DEV_INITRD=y' >> $( LINUX_DIR) /.config
echo 'CONFIG_INITRAMFS_SOURCE="$(strip $(TARGET_DIR) $(INITRAMFS_EXTRA_FILES))"' >> $( LINUX_DIR) /.config
2008-07-06 06:11:22 +08:00
endef
else
2012-11-01 01:32:37 +08:00
define Kernel/SetInitramfs/PreConfigure
grep -v INITRAMFS $( LINUX_DIR) /.config.old > $( LINUX_DIR) /.config
echo 'CONFIG_INITRAMFS_SOURCE="$(call qstrip,$(CONFIG_EXTERNAL_CPIO))"' >> $( LINUX_DIR) /.config
2012-04-05 22:33:04 +08:00
endef
endif
2012-11-01 01:32:37 +08:00
define Kernel/SetInitramfs
mv $( LINUX_DIR) /.config $( LINUX_DIR) /.config.old
$( call Kernel/SetInitramfs/PreConfigure)
echo 'CONFIG_INITRAMFS_ROOT_UID=$(shell id -u)' >> $( LINUX_DIR) /.config
echo 'CONFIG_INITRAMFS_ROOT_GID=$(shell id -g)' >> $( LINUX_DIR) /.config
echo " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE) ,CONFIG_INITRAMFS_COMPRESSION_NONE= y,# CONFIG_INITRAMFS_COMPRESSION_NONE is not set ) " >> $( LINUX_DIR) /.config
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP) ,CONFIG_INITRAMFS_COMPRESSION_GZIP= y\n CONFIG_RD_GZIP= y,# CONFIG_INITRAMFS_COMPRESSION_GZIP is not set\n # CONFIG_RD_GZIP is not set)" >> $(LINUX_DIR)/.config
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2) ,CONFIG_INITRAMFS_COMPRESSION_BZIP2= y\n CONFIG_RD_BZIP2= y,# CONFIG_INITRAMFS_COMPRESSION_BZIP2 is not set\n # CONFIG_RD_BZIP2 is not set)" >> $(LINUX_DIR)/.config
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA) ,CONFIG_INITRAMFS_COMPRESSION_LZMA= y\n CONFIG_RD_LZMA= y,# CONFIG_INITRAMFS_COMPRESSION_LZMA is not set\n # CONFIG_RD_LZMA is not set)" >> $(LINUX_DIR)/.config
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO) ,CONFIG_INITRAMFS_COMPRESSION_LZO= y\n CONFIG_RD_LZO= y,# CONFIG_INITRAMFS_COMPRESSION_LZO is not set\n # CONFIG_RD_LZO is not set)" >> $(LINUX_DIR)/.config
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ) ,CONFIG_INITRAMFS_COMPRESSION_XZ= y\n CONFIG_RD_XZ= y,# CONFIG_INITRAMFS_COMPRESSION_XZ is not set\n # CONFIG_RD_XZ is not set)" >> $(LINUX_DIR)/.config
2013-10-25 09:48:02 +08:00
echo -e " $( if $( CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4) ,CONFIG_INITRAMFS_COMPRESSION_LZ4= y\n CONFIG_RD_LZ4= y,# CONFIG_INITRAMFS_COMPRESSION_LZ4 is not set\n # CONFIG_RD_LZ4 is not set)" >> $(LINUX_DIR)/.config
2012-11-01 01:32:37 +08:00
endef
2012-04-05 22:33:04 +08:00
e l s e
2013-06-28 03:58:20 +08:00
e n d i f
d e f i n e K e r n e l / S e t N o I n i t r a m f s
2012-11-01 01:32:37 +08:00
mv $( LINUX_DIR) /.config $( LINUX_DIR) /.config.old
grep -v INITRAMFS $( LINUX_DIR) /.config.old > $( LINUX_DIR) /.config
echo 'CONFIG_INITRAMFS_SOURCE=""' >> $( LINUX_DIR) /.config
2013-06-28 03:58:20 +08:00
e n d e f
2008-07-06 06:11:22 +08:00
2007-03-24 21:42:54 +08:00
d e f i n e K e r n e l / C o n f i g u r e / D e f a u l t
2011-04-06 22:48:55 +08:00
$( LINUX_CONF_CMD) > $( LINUX_DIR) /.config.target
2010-04-13 22:07:22 +08:00
# copy CONFIG_KERNEL_* settings over to .config.target
awk '/^(#[[:space:]]+)?CONFIG_KERNEL/{sub("CONFIG_KERNEL_","CONFIG_");print}' $( TOPDIR) /.config >> $( LINUX_DIR) /.config.target
2009-01-21 05:09:04 +08:00
echo "# CONFIG_KALLSYMS_EXTRA_PASS is not set" >> $( LINUX_DIR) /.config.target
2009-02-14 22:10:44 +08:00
echo "# CONFIG_KALLSYMS_ALL is not set" >> $( LINUX_DIR) /.config.target
2013-01-16 03:55:45 +08:00
echo "# CONFIG_KALLSYMS_UNCOMPRESSED is not set" >> $( LINUX_DIR) /.config.target
2009-01-21 05:09:04 +08:00
echo "# CONFIG_KPROBES is not set" >> $( LINUX_DIR) /.config.target
2007-07-18 19:31:01 +08:00
$( SCRIPT_DIR) /metadata.pl kconfig $( TMP_DIR) /.packageinfo $( TOPDIR) /.config > $( LINUX_DIR) /.config.override
2009-11-11 09:25:06 +08:00
$( SCRIPT_DIR) /kconfig.pl 'm+' '+' $( LINUX_DIR) /.config.target /dev/null $( LINUX_DIR) /.config.override > $( LINUX_DIR) /.config
2013-06-28 03:58:20 +08:00
$( call Kernel/SetNoInitramfs)
2007-03-25 01:05:26 +08:00
rm -rf $( KERNEL_BUILD_DIR) /modules
2014-01-30 15:33:42 +08:00
$( _SINGLE) [ -d $( LINUX_DIR) /user_headers ] || $( MAKE) $( KERNEL_MAKEOPTS) INSTALL_HDR_PATH = $( LINUX_DIR) /user_headers headers_install
2012-01-08 23:23:11 +08:00
$( SH_FUNC) grep '=[ym]' $( LINUX_DIR) /.config | LC_ALL = C sort | md5s > $( LINUX_DIR) /.vermagic
2007-03-24 21:42:54 +08:00
e n d e f
2013-06-28 03:58:20 +08:00
d e f i n e K e r n e l / C o n f i g u r e / I n i t r a m f s
$( call Kernel/SetInitramfs)
e n d e f
2007-03-24 21:42:54 +08:00
d e f i n e K e r n e l / C o m p i l e M o d u l e s / D e f a u l t
2007-04-26 06:26:40 +08:00
rm -f $( LINUX_DIR) /vmlinux $( LINUX_DIR) /System.map
2008-08-17 00:59:47 +08:00
+$( MAKE) $( KERNEL_MAKEOPTS) modules
2007-03-24 21:42:54 +08:00
e n d e f
2009-04-27 23:37:58 +08:00
OBJCOPY_STRIP = -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id
2009-02-03 00:39:28 +08:00
2013-06-28 03:58:24 +08:00
# AVR32 uses a non-standard location
i f e q ( $( LINUX_KARCH ) , a v r 3 2 )
IMAGES_DIR := images
e n d i f
2014-01-07 20:23:35 +08:00
# AMD64 shares the location with x86
i f e q ( $( LINUX_KARCH ) , x 8 6 _ 6 4 )
IMAGES_DIR := ../../x86/boot
e n d i f
2013-06-28 03:58:20 +08:00
d e f i n e K e r n e l / C o p y I m a g e
$( KERNEL_CROSS) objcopy -O binary $( OBJCOPY_STRIP) -S $( LINUX_DIR) /vmlinux $( LINUX_KERNEL) $( 1)
$( KERNEL_CROSS) objcopy $( OBJCOPY_STRIP) -S $( LINUX_DIR) /vmlinux $( KERNEL_BUILD_DIR) /vmlinux$( 1) .elf
2013-06-28 03:58:24 +08:00
i f n e q ( $( subst ",,$ ( KERNELNAME ) ) , )
#")
2013-07-01 01:09:21 +08:00
$( foreach k,$( filter-out dtbs,$( subst " ,, $( KERNELNAME) )), $( CP) $( LINUX_DIR) /arch/ $( LINUX_KARCH) /boot/ $( IMAGES_DIR) / $( k) $( KERNEL_BUILD_DIR) / $( k) $( 1) ;)
2013-06-28 03:58:24 +08:00
#")
e n d i f
2013-06-28 03:58:20 +08:00
e n d e f
2007-03-24 21:42:54 +08:00
d e f i n e K e r n e l / C o m p i l e I m a g e / D e f a u l t
2013-07-23 21:11:41 +08:00
rm -f $( TARGET_DIR) /init
2012-06-18 21:20:50 +08:00
+$( MAKE) $( KERNEL_MAKEOPTS) $( subst " ,, $( KERNELNAME) )
2013-06-28 03:58:16 +08:00
#")
2013-06-28 03:58:20 +08:00
$( call Kernel/CopyImage)
e n d e f
i f n e q ( $( CONFIG_TARGET_ROOTFS_INITRAMFS ) , )
d e f i n e K e r n e l / C o m p i l e I m a g e / I n i t r a m f s
$( call Kernel/Configure/Initramfs)
2013-07-23 21:11:41 +08:00
$( CP) $( GENERIC_PLATFORM_DIR) /base-files/init $( TARGET_DIR) /init
2013-07-02 17:59:17 +08:00
rm -rf $( KERNEL_BUILD_DIR) /linux-$( LINUX_VERSION) /usr/initramfs_data.cpio*
2013-06-28 03:58:20 +08:00
+$( MAKE) $( KERNEL_MAKEOPTS) $( subst " ,, $( KERNELNAME) )
#")
#")
$( call Kernel/CopyImage,-initramfs)
2007-03-24 21:42:54 +08:00
e n d e f
2013-06-28 03:58:20 +08:00
e l s e
d e f i n e K e r n e l / C o m p i l e I m a g e / I n i t r a m f s
e n d e f
e n d i f
2007-03-24 21:42:54 +08:00
d e f i n e K e r n e l / C l e a n / D e f a u l t
rm -f $( KERNEL_BUILD_DIR) /linux-$( LINUX_VERSION) /.configured
rm -f $( LINUX_KERNEL)
2008-08-17 00:59:47 +08:00
$( _SINGLE) $( MAKE) -C $( KERNEL_BUILD_DIR) /linux-$( LINUX_VERSION) clean
2007-03-24 21:42:54 +08:00
e n d e f