2 # Copyright (C) 2006-2007 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
7 include $(INCLUDE_DIR)/prereq.mk
8 include $(INCLUDE_DIR)/depends.mk
14 KERNEL_FILE_DEPENDS=$(GENERIC_BACKPORT_DIR) $(GENERIC_PATCH_DIR) $(GENERIC_HACK_DIR) $(PATCH_DIR) $(GENERIC_FILES_DIR) $(FILES_DIR)
15 STAMP_PREPARED=$(LINUX_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,$(KERNEL_FILE_DEPENDS),)))
16 STAMP_CONFIGURED:=$(LINUX_DIR)/.configured
17 include $(INCLUDE_DIR)/download.mk
18 include $(INCLUDE_DIR)/quilt.mk
19 include $(INCLUDE_DIR)/kernel-defaults.mk
22 $(call Kernel/Prepare/Default)
25 define Kernel/Configure
26 $(call Kernel/Configure/Default)
29 define Kernel/CompileModules
30 $(call Kernel/CompileModules/Default)
33 define Kernel/CompileImage
34 $(call Kernel/CompileImage/Default)
35 $(call Kernel/CompileImage/Initramfs)
39 $(call Kernel/Clean/Default)
42 define Download/kernel
45 HASH:=$(LINUX_KERNEL_HASH)
49 ifneq ($(strip $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)),"")
50 KERNEL_GIT_OPTS+=--reference $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)
53 define Download/git-kernel
54 URL:=$(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI))
56 VERSION:=$(CONFIG_KERNEL_GIT_REF)
58 SUBDIR:=linux-$(LINUX_VERSION)
59 OPTS:=$(KERNEL_GIT_OPTS)
62 ifdef CONFIG_COLLECT_KERNEL_DEBUG
63 define Kernel/CollectDebug
64 rm -rf $(KERNEL_BUILD_DIR)/debug
65 mkdir -p $(KERNEL_BUILD_DIR)/debug/modules
66 $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/debug/
68 $(STAGING_DIR_ROOT)/lib/modules/$(LINUX_VERSION)/* \
69 $(KERNEL_BUILD_DIR)/debug/modules/
70 $(FIND) $(KERNEL_BUILD_DIR)/debug -type f | $(XARGS) $(KERNEL_CROSS)strip --only-keep-debug
71 $(TAR) c -C $(KERNEL_BUILD_DIR) debug \
72 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
73 | bzip2 -c -9 > $(BIN_DIR)/kernel-debug.tar.bz2
77 ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
78 ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
79 define Kernel/Autoclean
80 $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
81 $(call rdep,$(KERNEL_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
87 $(if $(QUILT),$(Build/Quilt))
88 $(if $(LINUX_SITE),$(call Download,kernel))
89 $(if $(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI)),$(call Download,git-kernel))
94 $(STAMP_PREPARED): $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
95 -rm -rf $(KERNEL_BUILD_DIR)
96 -mkdir -p $(KERNEL_BUILD_DIR)
100 $(KERNEL_BUILD_DIR)/symtab.h: FORCE
101 rm -f $(KERNEL_BUILD_DIR)/symtab.h
102 touch $(KERNEL_BUILD_DIR)/symtab.h
103 +$(KERNEL_MAKE) vmlinux
104 find $(LINUX_DIR) $(STAGING_DIR_ROOT)/lib/modules -name \*.ko | \
105 xargs $(TARGET_CROSS)nm | \
106 awk '$$$$1 == "U" { print $$$$2 } ' | \
107 sort -u > $(KERNEL_BUILD_DIR)/mod_symtab.txt
108 $(TARGET_CROSS)nm -n $(LINUX_DIR)/vmlinux.o | grep ' [rR] __ksymtab' | sed -e 's,........ [rR] __ksymtab_,,' > $(KERNEL_BUILD_DIR)/kernel_symtab.txt
109 grep -Ff $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_include.txt
110 grep -Fvf $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_exclude.txt
112 echo '#define SYMTAB_KEEP \'; \
113 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
114 awk '{print "KEEP(*(___ksymtab+" $$$$1 ")) \\" }'; \
116 echo '#define SYMTAB_KEEP_GPL \'; \
117 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
118 awk '{print "KEEP(*(___ksymtab_gpl+" $$$$1 ")) \\" }'; \
120 echo '#define SYMTAB_DISCARD \'; \
121 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
122 awk '{print "*(___ksymtab+" $$$$1 ") \\" }'; \
124 echo '#define SYMTAB_DISCARD_GPL \'; \
125 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
126 awk '{print "*(___ksymtab_gpl+" $$$$1 ") \\" }'; \
130 $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_KCONFIG_LIST) $(TOPDIR)/.config FORCE
134 $(LINUX_DIR)/.modules: export STAGING_PREFIX=$$(STAGING_DIR_HOST)
135 $(LINUX_DIR)/.modules: export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig
136 $(LINUX_DIR)/.modules: export PKG_CONFIG_LIBDIR=$$(STAGING_DIR_HOST)/lib/pkgconfig
137 $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
138 $(Kernel/CompileModules)
141 $(LINUX_DIR)/.image: export STAGING_PREFIX=$$(STAGING_DIR_HOST)
142 $(LINUX_DIR)/.image: export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig
143 $(LINUX_DIR)/.image: export PKG_CONFIG_LIBDIR=$$(STAGING_DIR_HOST)/lib/pkgconfig
144 $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) $(if $(CONFIG_STRIP_KERNEL_EXPORTS),$(KERNEL_BUILD_DIR)/symtab.h) FORCE
145 $(Kernel/CompileImage)
146 $(Kernel/CollectDebug)
155 download: $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
156 prepare: $(STAMP_PREPARED)
157 compile: $(LINUX_DIR)/.modules
158 $(MAKE) -C image compile TARGET_BUILD=
160 oldconfig menuconfig nconfig: $(STAMP_PREPARED) $(STAMP_CHECKED) FORCE
161 rm -f $(LINUX_DIR)/.config.prev
162 rm -f $(STAMP_CONFIGURED)
163 $(LINUX_RECONF_CMD) > $(LINUX_DIR)/.config
164 $(_SINGLE)$(KERNEL_MAKE) \
165 $(if $(findstring Darwin,$(HOST_OS)),HOST_LOADLIBES="-L$(STAGING_DIR_HOST)/lib -lncurses") \
166 YACC=$(STAGING_DIR_HOST)/bin/bison \
168 $(LINUX_RECONF_DIFF) $(LINUX_DIR)/.config | \
169 grep -vE '(CONFIG_CC_(HAS_ASM_GOTO|IS_GCC|IS_CLANG)|GCC_VERSION)=' \
170 > $(LINUX_RECONFIG_TARGET)
172 install: $(LINUX_DIR)/.image
173 +$(MAKE) -C image compile install TARGET_BUILD=
176 rm -rf $(KERNEL_BUILD_DIR)
179 @+$(NO_TRACE_MAKE) -s -C image prereq TARGET_BUILD=