source: trunk/make/linux/kernel.mk @ 6384

Letzte Änderung dieser Datei seit 6384 war 6384, erstellt von er13 vor 8 Jahren

toolchain:

  • exclude kernel-headers from the download-toolchain
  • install the right ones at the build-time
  • refs #842, refs #348
Dateigröße: 9.4 KB
Zeile 
1comma:=,
2space:=$(empty) $(empty)
3AVM_SOURCE:=$(strip $(subst ",, $(subst $(space),\ ,$(FREETZ_DL_KERNEL_SOURCE))))
4
5AVM_UNPACK__INT_.gz:=z
6AVM_UNPACK__INT_.bz2:=j
7
8KERNEL_SUBVERSION:=iln6
9KERNEL_BOARD_REF:=$(KERNEL_REF)
10KERNEL_MAKE_DIR:=$(MAKE_DIR)/linux
11KERNEL_BUILD_DIR:=$(KERNEL_DIR)
12KERNEL_BUILD_ROOT_DIR:=$(KERNEL_BUILD_DIR)/linux-$(KERNEL_VERSION)
13
14KERNEL_IMAGE:=vmlinux.eva_pad
15KERNEL_TARGET_BINARY:=kernel-$(KERNEL_LAYOUT)-$(KERNEL_REF)-$(AVM_VERSION).bin
16KERNEL_CONFIG_FILE:=$(KERNEL_MAKE_DIR)/Config.$(KERNEL_LAYOUT)-$(KERNEL_REF).$(AVM_VERSION)
17
18$(DL_FW_DIR)/$(AVM_SOURCE): | $(DL_FW_DIR)
19    @$(call _ECHO, downloading...)
20    $(DL_TOOL) $(DL_FW_DIR) .config $(FREETZ_DL_KERNEL_SOURCE) $(FREETZ_DL_KERNEL_SITE) $(FREETZ_DL_KERNEL_SOURCE_MD5) $(SILENT)
21
22# Make sure that a perfectly clean build is performed whenever Freetz package
23# options have changed. The safest way to achieve this is by starting over
24# with the source directory.
25$(KERNEL_DIR)/.unpacked: $(DL_FW_DIR)/$(AVM_SOURCE) | gcc-kernel
26    $(RM) -r $(KERNEL_DIR)
27    mkdir -p $(KERNEL_BUILD_DIR)
28    @$(call _ECHO,checking structure... )
29    @KERNEL_SOURCE_CONTENT=` \
30        tar \
31            -t$(AVM_UNPACK__INT_$(suffix $(strip $(FREETZ_DL_KERNEL_SOURCE)))) \
32            -f $(DL_FW_DIR)/$(FREETZ_DL_KERNEL_SOURCE)| \
33        grep -m 1 -e '^.*\/\(GPL-\(release_\|\)kernel\.tar\.gz\|linux-2\.6\...\..\/\)$$'`; \
34    if [ -z "$${KERNEL_SOURCE_CONTENT}" ]; then \
35        $(call ERROR,1,KERNEL_SOURCE_CONTENT is empty) \
36    else \
37        $(call _ECHO, unpacking... ) \
38        if [ ! -z $$(echo "$$KERNEL_SOURCE_CONTENT"|grep -e '.*\/GPL-\(release_\|\)kernel\.tar\.gz') ]; then \
39            tar -O $(VERBOSE) \
40                -x$(AVM_UNPACK__INT_$(suffix $(strip $(FREETZ_DL_KERNEL_SOURCE)))) \
41                -f $(DL_FW_DIR)/$(FREETZ_DL_KERNEL_SOURCE) \
42                --wildcards "*/$${KERNEL_SOURCE_CONTENT##*/}" | \
43            tar -C $(KERNEL_BUILD_DIR) $(VERBOSE) \
44                -xz \
45                --transform="s|^.*\(linux-2\.6\...\..\/\)|\1|g" --show-transformed; \
46        else \
47            tar -C $(KERNEL_BUILD_DIR) $(VERBOSE) \
48                -x$(AVM_UNPACK__INT_$(suffix $(strip $(FREETZ_DL_KERNEL_SOURCE)))) \
49                -f $(DL_FW_DIR)/$(FREETZ_DL_KERNEL_SOURCE) \
50                --transform="s|^.*\(linux-2\.6\...\..\/\)|\1|g" --show-transformed \
51                "$$KERNEL_SOURCE_CONTENT"; \
52        fi \
53    fi
54    @if [ ! -d $(KERNEL_BUILD_ROOT_DIR) ]; then \
55        $(call ERROR,1,KERNEL_BUILD_ROOT_DIR has wrong structure) \
56    fi
57    @$(call _ECHO, preparing... )
58    @set -e; for i in $(KERNEL_MAKE_DIR)/patches/$(KERNEL_VERSION)/*.patch; do \
59        $(PATCH_TOOL) $(KERNEL_BUILD_DIR) $$i; \
60    done
61    #Version specific patches
62    @set -e; shopt -s nullglob; for i in $(KERNEL_MAKE_DIR)/patches/$(KERNEL_VERSION)/$(AVM_VERSION)/*.patch; do \
63        $(PATCH_TOOL) $(KERNEL_BUILD_DIR) $$i; \
64    done
65    @for i in $(KERNEL_LINKING_FILES); do \
66        if [ -e $(KERNEL_BUILD_ROOT_DIR)/$$i -a \
67        ! -e $(KERNEL_BUILD_ROOT_DIR)/include/linux/$${i##*\/linux_} ]; then \
68            $(call MESSAGE, Linking  $(KERNEL_BUILD_ROOT_DIR)/include/linux/$${i##*\/linux_}); \
69            ln -sf ../../$$i $(KERNEL_BUILD_ROOT_DIR)/include/linux/$${i##*\/linux_}; \
70        fi \
71    done
72    @for i in avm_net_trace.h avm_net_trace_ioctl.h; do \
73        if [ -e $(KERNEL_BUILD_ROOT_DIR)/drivers/char/avm_net_trace/$$i -a \
74            ! -e $(KERNEL_BUILD_ROOT_DIR)/include/linux/$$i ]; then \
75                $(call MESSAGE, Linking  $(KERNEL_BUILD_ROOT_DIR)/include/linux/$$i); \
76                ln -sf ../../drivers/char/avm_net_trace/$$i \
77                    $(KERNEL_BUILD_ROOT_DIR)/include/linux/$$i; \
78        fi \
79    done
80    @for i in $$(find $(KERNEL_BUILD_ROOT_DIR) -name Makefile.26 -printf '%h\n'); do \
81        if [ ! -e $$i/Makefile ] ; then \
82            $(call MESSAGE, Linking  $$i/Makefile); \
83            ln -sf Makefile.26 $$i/Makefile; \
84        fi \
85    done
86    @for i in $$(find $(KERNEL_BUILD_ROOT_DIR) -name Makefile -exec \
87        awk '/(obj|subdir)-.*=/{ \
88        while (match ($$0,/\\/)) {sub(/\\/," "); getline l;$$0=$$0""l} \
89        gsub(/(#.*|.*=)/,""); \
90        if (! match ($$0,/,/)) { \
91            dirname=substr(FILENAME,1,length(FILENAME)-8); \
92            for (i=1;i<=NF;i++) { \
93                if (match ($$i,/\.o$$|\$$/)) { \
94                    $$i=""; \
95                } else if (substr($$i,length($$i))!="/") { \
96                    $$i=$$i"/"; \
97                } \
98                if ($$i!="") { \
99                    if (system("test -e "dirname""$$i"Makefile")) { \
100                        print dirname""$$i"Makefile"; \
101                    } \
102                } \
103            } \
104        } \
105    }' {} '+'|sort -u); do \
106        $(call MESSAGE, Creating $$i); \
107        mkdir -p $$(dirname "$$i"); \
108        [ -h $$i ] && $(RM) $$i; \
109        touch $$i; \
110    done
111    @for i in $$(find $(KERNEL_BUILD_ROOT_DIR) -name Kconfig -exec grep -hs "source.*Kconfig" {} '+'| \
112        sed -e 's/\(.*\)#.*/\1/g;s/.*source //g;s/"//g'|sort -u); do \
113        if [ ! -e $(KERNEL_BUILD_ROOT_DIR)/$$i ]; then \
114            $(call MESSAGE, Creating $(KERNEL_BUILD_ROOT_DIR)/$$i); \
115            mkdir -p $(KERNEL_BUILD_ROOT_DIR)/$${i%\/*}; \
116            [ -h $(KERNEL_BUILD_ROOT_DIR)/$$i ] && \
117                $(RM) $(KERNEL_BUILD_ROOT_DIR)/$$i; \
118            touch $(KERNEL_BUILD_ROOT_DIR)/$$i; \
119        fi \
120    done
121    ln -s linux-$(KERNEL_VERSION) $(KERNEL_DIR)/linux
122    touch $@
123
124$(KERNEL_DIR)/.configured: $(KERNEL_DIR)/.unpacked $(KERNEL_CONFIG_FILE)
125    $(call _ECHO, configuring... )
126    cp $(KERNEL_CONFIG_FILE) $(KERNEL_BUILD_ROOT_DIR)/.config
127    $(SUBMAKE) -C $(KERNEL_BUILD_ROOT_DIR) \
128        CROSS_COMPILE="$(KERNEL_CROSS)" \
129        KERNEL_MAKE_PATH="$(KERNEL_MAKE_PATH):$(PATH)" \
130        ARCH="$(KERNEL_ARCH)" \
131        KERNEL_LAYOUT="$(KERNEL_BOARD_REF)" \
132        oldconfig
133    touch $@
134
135$(KERNEL_DIR)/.prepared: $(KERNEL_DIR)/.configured
136    $(SUBMAKE) -C $(KERNEL_BUILD_ROOT_DIR) \
137        CROSS_COMPILE="$(KERNEL_CROSS)" \
138        KERNEL_MAKE_PATH="$(KERNEL_MAKE_PATH):$(PATH)" \
139        ARCH="$(KERNEL_ARCH)" \
140        KERNEL_LAYOUT="$(KERNEL_BOARD_REF)" \
141        prepare
142    touch $@
143
144$(KERNEL_HEADERS_DEVEL_DIR)/include/linux/version.h: $(KERNEL_DIR)/.prepared
145ifeq ($(strip $(FREETZ_KERNEL_VERSION_2_6_13_1)),y)
146    $(call COPY_KERNEL_HEADERS,$(KERNEL_BUILD_ROOT_DIR),$(KERNEL_HEADERS_DEVEL_DIR),{asm$(comma)asm-generic$(comma)linux})
147else
148    $(SUBMAKE) -C $(KERNEL_BUILD_ROOT_DIR) \
149        CROSS_COMPILE="$(KERNEL_CROSS)" \
150        ARCH=$(KERNEL_ARCH) \
151        INSTALL_HDR_PATH=$(KERNEL_HEADERS_DEVEL_DIR) \
152        headers_install
153    find "$(KERNEL_HEADERS_DEVEL_DIR)" \( -name "..install.cmd" -o -name ".install" \) -exec rm -f \{\} \+
154endif
155    touch $@
156
157target-toolchain-kernel-headers: $(TARGET_TOOLCHAIN_KERNEL_VERSION_HEADER)
158$(TARGET_TOOLCHAIN_KERNEL_VERSION_HEADER): $(TOPDIR)/.config $(KERNEL_HEADERS_DEVEL_DIR)/include/linux/version.h | $(if $(FREETZ_BUILD_TOOLCHAIN),$(TARGET_TOOLCHAIN_STAGING_DIR),$(TARGET_CROSS_COMPILER))
159    @$(call COPY_KERNEL_HEADERS,$(KERNEL_HEADERS_DEVEL_DIR),$(TARGET_TOOLCHAIN_STAGING_DIR)/usr)
160    @touch $@
161
162$(KERNEL_BUILD_ROOT_DIR)/$(KERNEL_IMAGE): $(KERNEL_DIR)/.prepared $(TOOLS_DIR)/lzma $(TOOLS_DIR)/lzma2eva
163    $(call _ECHO, kernel image... )
164    $(SUBMAKE) -C $(KERNEL_BUILD_ROOT_DIR) \
165        CROSS_COMPILE="$(KERNEL_CROSS)" \
166        ARCH=$(KERNEL_ARCH) \
167        $(KERNEL_IMAGE)
168    touch -c $@
169
170kernel-force:
171    $(SUBMAKE) -C $(KERNEL_BUILD_ROOT_DIR) \
172        CROSS_COMPILE="$(KERNEL_CROSS)" \
173        ARCH=$(KERNEL_ARCH) \
174        $(KERNEL_IMAGE)
175
176$(KERNEL_TARGET_DIR)/$(KERNEL_TARGET_BINARY): $(KERNEL_BUILD_ROOT_DIR)/$(KERNEL_IMAGE)
177    cp $(KERNEL_BUILD_ROOT_DIR)/$(KERNEL_IMAGE) $(KERNEL_TARGET_DIR)/$(KERNEL_TARGET_BINARY)
178    cp $(KERNEL_BUILD_ROOT_DIR)/System.map $(KERNEL_TARGET_DIR)/System-$(KERNEL_LAYOUT)-$(KERNEL_REF)-$(AVM_VERSION).map
179    echo "$(KERNEL_SUBVERSION)" > $(KERNEL_TARGET_DIR)/.version-$(KERNEL_LAYOUT)-$(KERNEL_REF)-$(AVM_VERSION)
180    touch -c $@
181
182$(KERNEL_DIR)/.modules-$(KERNEL_LAYOUT): $(KERNEL_BUILD_ROOT_DIR)/$(KERNEL_IMAGE)
183    @$(call _ECHO, modules... )
184    $(SUBMAKE) -C $(KERNEL_BUILD_ROOT_DIR) \
185        CROSS_COMPILE="$(KERNEL_CROSS)" \
186        KERNEL_MAKE_PATH="$(KERNEL_MAKE_PATH):$(PATH)" \
187        KERNEL_LAYOUT="$(KERNEL_BOARD_REF)" \
188        ARCH=$(KERNEL_ARCH) \
189        INSTALL_MOD_PATH="$(FREETZ_BASE_DIR)/$(KERNEL_DIR)" \
190        modules
191    $(SUBMAKE) -C $(KERNEL_BUILD_ROOT_DIR) \
192        CROSS_COMPILE="$(KERNEL_CROSS)" \
193        KERNEL_MAKE_PATH="$(KERNEL_MAKE_PATH):$(PATH)" \
194        KERNEL_LAYOUT="$(KERNEL_BOARD_REF)" \
195        ARCH=$(KERNEL_ARCH) \
196        INSTALL_MOD_PATH="$(FREETZ_BASE_DIR)/$(KERNEL_DIR)" \
197        modules_install
198    touch $@
199
200$(KERNEL_MODULES_DIR)/.modules-$(KERNEL_LAYOUT): $(KERNEL_DIR)/.modules-$(KERNEL_LAYOUT)
201    $(RM) -r $(KERNEL_MODULES_DIR)/lib
202    mkdir -p $(KERNEL_MODULES_DIR)
203    KERNEL_MODULES_SOURCE_DIR=$(KERNEL_DIR)/lib/modules/*/kernel; \
204    tar -cf - -C $$KERNEL_MODULES_SOURCE_DIR \
205        . | tar -xf - -C $(KERNEL_MODULES_DIR)
206    touch $@
207
208kernel-precompiled: pkg-echo-start $(KERNEL_TARGET_DIR)/$(KERNEL_TARGET_BINARY) $(KERNEL_MODULES_DIR)/.modules-$(KERNEL_LAYOUT) pkg-echo-done
209
210kernel-configured: $(KERNEL_DIR)/.prepared
211
212kernel-modules: $(KERNEL_DIR)/.modules-$(KERNEL_LAYOUT)
213
214kernel-menuconfig: $(KERNEL_DIR)/.configured
215    $(SUBMAKE) -C $(KERNEL_BUILD_ROOT_DIR) \
216        CROSS_COMPILE="$(KERNEL_CROSS)" \
217        KERNEL_MAKE_PATH="$(KERNEL_MAKE_PATH):$(PATH)" \
218        ARCH="$(KERNEL_ARCH)" \
219        KERNEL_LAYOUT="$(KERNEL_BOARD_REF)" \
220        menuconfig
221    -cp -f $(KERNEL_BUILD_ROOT_DIR)/.config $(KERNEL_CONFIG_FILE) && \
222    touch $(KERNEL_DIR)/.configured
223
224kernel-oldconfig: $(KERNEL_DIR)/.configured
225    -cp -f $(KERNEL_BUILD_ROOT_DIR)/.config $(KERNEL_CONFIG_FILE) && \
226    touch $(KERNEL_DIR)/.configured
227
228kernel-source: $(KERNEL_DIR)/.unpacked
229
230kernel-clean:
231    $(SUBMAKE) -C $(KERNEL_BUILD_ROOT_DIR) \
232        CROSS_COMPILE="$(KERNEL_CROSS)" \
233        KERNEL_MAKE_PATH="$(KERNEL_MAKE_PATH):$(PATH)" \
234        ARCH="$(KERNEL_ARCH)" \
235        KERNEL_LAYOUT="$(KERNEL_BOARD_REF)" \
236        clean
237
238kernel-dirclean:
239    $(RM) -r $(SOURCE_DIR_ROOT)/kernel
240    $(RM) $(KERNEL_TARGET_DIR)/.version-*
241    $(RM) $(KERNEL_TARGET_DIR)/System*
242    $(RM) $(KERNEL_TARGET_DIR)/kernel-*
243    $(RM) -r $(KERNEL_TARGET_DIR)/modules-*
244
245kernel-distclean: kernel-dirclean
246
247pkg-echo-start:
248    @$(RM) $(ECHO_ITEM_START) $(ECHO_ITEM_BUILD)
249
250pkg-echo-done:
251    @$(call _ECHO_DONE)
252
253.PHONY: kernel-configured kernel-modules kernel-menuconfig kernel-oldconfig target-toolchain-kernel-headers
Hinweis: Hilfe zum Repository-Browser finden Sie in TracBrowser.