Refactor downloading code into download.mk
[15.05/openwrt.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
10 ifneq ($(DUMP),1)
11   override MAKEFLAGS=
12 endif
13
14 ifneq ($(DUMP),1)
15   all: compile
16 endif
17
18 STAMP_PREPARED:=$(LINUX_DIR)/.prepared
19 STAMP_CONFIGURED:=$(LINUX_DIR)/.configured
20 include $(INCLUDE_DIR)/download.mk
21 include $(INCLUDE_DIR)/quilt.mk
22 include $(INCLUDE_DIR)/kernel-defaults.mk
23
24 define Kernel/Prepare
25         $(call Kernel/Prepare/Default)
26 endef
27
28 define Kernel/Configure
29         $(call Kernel/Configure/Default)
30 endef
31
32 define Kernel/CompileModules
33         $(call Kernel/CompileModules/Default)
34 endef
35
36 define Kernel/CompileImage
37         $(call Kernel/CompileImage/Default)
38 endef
39
40 define Kernel/Clean
41         $(call Kernel/Clean/Default)
42 endef
43
44 define Download/kernel
45   URL:=$(LINUX_SITE)
46   FILE:=$(LINUX_SOURCE)
47   MD5SUM:=$(LINUX_KERNEL_MD5SUM)
48 endef
49
50 define BuildKernel
51   $(if $(LINUX_SITE),$(call Download,kernel))
52
53   $(STAMP_PREPARED): $(DL_DIR)/$(LINUX_SOURCE)
54         -rm -rf $(KERNEL_BUILD_DIR)
55         -mkdir -p $(KERNEL_BUILD_DIR)
56         $(Kernel/Prepare)
57         touch $$@
58
59   $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_CONFIG) $(GENERIC_LINUX_CONFIG) $(TOPDIR)/.config
60         $(Kernel/Configure)
61         touch $$@
62
63   $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
64         $(Kernel/CompileModules)
65         touch $$@
66
67   $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) FORCE
68         $(Kernel/CompileImage)
69         touch $$@
70         
71   mostlyclean: FORCE
72         $(Kernel/Clean)
73
74   define BuildKernel
75   endef
76
77   download: $(DL_DIR)/$(LINUX_SOURCE)
78   prepare: $(STAMP_CONFIGURED)
79   compile: $(LINUX_DIR)/.modules
80         $(MAKE) -C image compile TARGET_BUILD=
81
82   oldconfig menuconfig: $(STAMP_PREPARED) FORCE
83         $(LINUX_CONFCMD) > $(LINUX_DIR)/.config
84         $(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) $$@
85         $(SCRIPT_DIR)/kconfig.pl '>' $(GENERIC_LINUX_CONFIG) $(LINUX_DIR)/.config > $(LINUX_CONFIG)
86         $(Kernel/Configure)
87
88   install: $(LINUX_DIR)/.image
89         TARGET_BUILD="" $(MAKE) -C image compile install
90
91   clean: FORCE
92         rm -rf $(KERNEL_BUILD_DIR)
93
94   rebuild: FORCE
95         @$(MAKE) mostlyclean
96         @if [ -f $(LINUX_KERNEL) ]; then \
97                 $(MAKE) clean; \
98         fi
99         @$(MAKE) compile
100
101   image-prereq:
102         $(SUBMAKE) -s -C image prereq TARGET_BUILD=
103
104   prereq: image-prereq
105
106 endef