libpcap: add optional netfilter support
[openwrt/staging/yousong.git] / include / kernel-build.mk
1 #
2 # Copyright (C) 2006-2007 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 include $(INCLUDE_DIR)/host.mk
8 include $(INCLUDE_DIR)/prereq.mk
9 include $(INCLUDE_DIR)/depends.mk
10
11 ifneq ($(DUMP),1)
12 all: compile
13 endif
14
15 KERNEL_FILE_DEPENDS=$(GENERIC_PATCH_DIR) $(PATCH_DIR) $(GENERIC_FILES_DIR) $(FILES_DIR)
16 STAMP_PREPARED=$(LINUX_DIR)/.prepared$(if $(QUILT)$(DUMP),,_$(shell $(call find_md5,$(KERNEL_FILE_DEPENDS),)))
17 STAMP_CONFIGURED:=$(LINUX_DIR)/.configured
18 include $(INCLUDE_DIR)/download.mk
19 include $(INCLUDE_DIR)/quilt.mk
20 include $(INCLUDE_DIR)/kernel-defaults.mk
21
22 define Kernel/Prepare
23 $(call Kernel/Prepare/Default)
24 endef
25
26 define Kernel/Configure
27 $(call Kernel/Configure/Default)
28 endef
29
30 define Kernel/CompileModules
31 $(call Kernel/CompileModules/Default)
32 endef
33
34 define Kernel/CompileImage
35 $(call Kernel/CompileImage/Default)
36 $(call Kernel/CompileImage/Initramfs)
37 endef
38
39 define Kernel/Clean
40 $(call Kernel/Clean/Default)
41 endef
42
43 define Download/kernel
44 URL:=$(LINUX_SITE)
45 FILE:=$(LINUX_SOURCE)
46 HASH:=$(LINUX_KERNEL_HASH)
47 endef
48
49 KERNEL_GIT_OPTS:=
50 ifneq ($(strip $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)),"")
51 KERNEL_GIT_OPTS+=--reference $(CONFIG_KERNEL_GIT_LOCAL_REPOSITORY)
52 endif
53
54 ifneq ($(strip $(CONFIG_KERNEL_GIT_BRANCH)),"")
55 KERNEL_GIT_OPTS+=--branch $(CONFIG_KERNEL_GIT_BRANCH)
56 endif
57
58 define Download/git-kernel
59 URL:=$(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI))
60 PROTO:=git
61 VERSION:=$(CONFIG_KERNEL_GIT_BRANCH)
62 FILE:=$(LINUX_SOURCE)
63 SUBDIR:=linux-$(LINUX_VERSION)
64 OPTS:=$(KERNEL_GIT_OPTS)
65 endef
66
67 ifdef CONFIG_COLLECT_KERNEL_DEBUG
68 define Kernel/CollectDebug
69 rm -rf $(KERNEL_BUILD_DIR)/debug
70 mkdir -p $(KERNEL_BUILD_DIR)/debug/modules
71 $(CP) $(LINUX_DIR)/vmlinux $(KERNEL_BUILD_DIR)/debug/
72 -$(CP) \
73 $(STAGING_DIR_ROOT)/lib/modules/$(LINUX_VERSION)/* \
74 $(KERNEL_BUILD_DIR)/debug/modules/
75 $(FIND) $(KERNEL_BUILD_DIR)/debug -type f | $(XARGS) $(KERNEL_CROSS)strip --only-keep-debug
76 $(TAR) c -C $(KERNEL_BUILD_DIR) debug \
77 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)") \
78 | bzip2 -c -9 > $(BIN_DIR)/kernel-debug.tar.bz2
79 endef
80 endif
81
82 ifeq ($(DUMP)$(filter prereq clean refresh update,$(MAKECMDGOALS)),)
83 ifneq ($(if $(QUILT),,$(CONFIG_AUTOREBUILD)),)
84 define Kernel/Autoclean
85 $(PKG_BUILD_DIR)/.dep_files: $(STAMP_PREPARED)
86 $(call rdep,$(KERNEL_FILE_DEPENDS),$(STAMP_PREPARED),$(PKG_BUILD_DIR)/.dep_files,-x "*/.dep_*")
87 endef
88 endif
89 endif
90
91 define BuildKernel
92 $(if $(QUILT),$(Build/Quilt))
93 $(if $(LINUX_SITE),$(call Download,kernel))
94 $(if $(call qstrip,$(CONFIG_KERNEL_GIT_CLONE_URI)),$(call Download,git-kernel))
95
96 .NOTPARALLEL:
97
98 $(Kernel/Autoclean)
99 $(STAMP_PREPARED): $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
100 -rm -rf $(KERNEL_BUILD_DIR)
101 -mkdir -p $(KERNEL_BUILD_DIR)
102 $(Kernel/Prepare)
103 touch $$@
104
105 $(KERNEL_BUILD_DIR)/symtab.h: FORCE
106 rm -f $(KERNEL_BUILD_DIR)/symtab.h
107 touch $(KERNEL_BUILD_DIR)/symtab.h
108 +$(MAKE) $(KERNEL_MAKEOPTS) vmlinux
109 find $(LINUX_DIR) $(STAGING_DIR_ROOT)/lib/modules -name \*.ko | \
110 xargs $(TARGET_CROSS)nm | \
111 awk '$$$$1 == "U" { print $$$$2 } ' | \
112 sort -u > $(KERNEL_BUILD_DIR)/mod_symtab.txt
113 $(TARGET_CROSS)nm -n $(LINUX_DIR)/vmlinux.o | grep ' [rR] __ksymtab' | sed -e 's,........ [rR] __ksymtab_,,' > $(KERNEL_BUILD_DIR)/kernel_symtab.txt
114 grep -Ff $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_include.txt
115 grep -Fvf $(KERNEL_BUILD_DIR)/mod_symtab.txt $(KERNEL_BUILD_DIR)/kernel_symtab.txt > $(KERNEL_BUILD_DIR)/sym_exclude.txt
116 ( \
117 echo '#define SYMTAB_KEEP \'; \
118 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
119 awk '{print "KEEP(*(___ksymtab+" $$$$1 ")) \\" }'; \
120 echo; \
121 echo '#define SYMTAB_KEEP_GPL \'; \
122 cat $(KERNEL_BUILD_DIR)/sym_include.txt | \
123 awk '{print "KEEP(*(___ksymtab_gpl+" $$$$1 ")) \\" }'; \
124 echo; \
125 echo '#define SYMTAB_DISCARD \'; \
126 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
127 awk '{print "*(___ksymtab+" $$$$1 ") \\" }'; \
128 echo; \
129 echo '#define SYMTAB_DISCARD_GPL \'; \
130 cat $(KERNEL_BUILD_DIR)/sym_exclude.txt | \
131 awk '{print "*(___ksymtab_gpl+" $$$$1 ") \\" }'; \
132 echo; \
133 ) > $$@
134
135 $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_KCONFIG_LIST) $(TOPDIR)/.config FORCE
136 $(Kernel/Configure)
137 touch $$@
138
139 $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
140 $(Kernel/CompileModules)
141 touch $$@
142
143 $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) $(if $(CONFIG_STRIP_KERNEL_EXPORTS),$(KERNEL_BUILD_DIR)/symtab.h) FORCE
144 $(Kernel/CompileImage)
145 $(Kernel/CollectDebug)
146 touch $$@
147
148 mostlyclean: FORCE
149 $(Kernel/Clean)
150
151 define BuildKernel
152 endef
153
154 download: $(if $(LINUX_SITE),$(DL_DIR)/$(LINUX_SOURCE))
155 prepare: $(STAMP_PREPARED)
156 compile: $(LINUX_DIR)/.modules
157 $(MAKE) -C image compile TARGET_BUILD=
158
159 oldconfig menuconfig nconfig: $(STAMP_PREPARED) $(STAMP_CHECKED) FORCE
160 rm -f $(LINUX_DIR)/.config.prev
161 rm -f $(STAMP_CONFIGURED)
162 $(LINUX_RECONF_CMD) > $(LINUX_DIR)/.config
163 $(_SINGLE)$(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) HOST_LOADLIBES="-L$(STAGING_DIR_HOST)/lib -lncurses" $$@
164 $(LINUX_RECONF_DIFF) $(LINUX_DIR)/.config > $(LINUX_RECONFIG_TARGET)
165
166 install: $(LINUX_DIR)/.image
167 +$(MAKE) -C image compile install TARGET_BUILD=
168
169 clean: FORCE
170 rm -rf $(KERNEL_BUILD_DIR)
171
172 image-prereq:
173 @+$(NO_TRACE_MAKE) -s -C image prereq TARGET_BUILD=
174
175 prereq: image-prereq
176
177 endef