kernel-build.mk 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #
  2. # Copyright (C) 2006 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. KERNEL_BUILD:=1
  8. include $(INCLUDE_DIR)/prereq.mk
  9. -include ./config
  10. ifneq ($(CONFIG_ATM),)
  11. FEATURES += atm
  12. endif
  13. ifneq ($(CONFIG_PCI),)
  14. FEATURES += pci
  15. endif
  16. ifneq ($(CONFIG_USB),)
  17. FEATURES += usb
  18. endif
  19. ifneq ($(CONFIG_PCMCIA),)
  20. FEATURES += pcmcia
  21. endif
  22. # remove duplicates
  23. FEATURES:=$(sort $(FEATURES))
  24. # For target profile selection - the default set
  25. DEFAULT_PACKAGES:=base-files libgcc uclibc bridge busybox dnsmasq dropbear iptables mtd ppp ppp-mod-pppoe mtd
  26. ifeq ($(DUMP),1)
  27. all: dumpinfo
  28. else
  29. all: compile
  30. endif
  31. KERNEL:=2.$(word 2,$(subst ., ,$(strip $(LINUX_VERSION))))
  32. include $(INCLUDE_DIR)/host.mk
  33. include $(INCLUDE_DIR)/kernel.mk
  34. LINUX_CONFIG:=./config
  35. ifneq (,$(findstring uml,$(BOARD)))
  36. LINUX_KARCH:=um
  37. else
  38. LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
  39. -e 's/mipsel/mips/' \
  40. -e 's/mipseb/mips/' \
  41. -e 's/powerpc/ppc/' \
  42. -e 's/sh[234]/sh/' \
  43. -e 's/armeb/arm/' \
  44. )
  45. endif
  46. KERNELNAME=
  47. ifneq (,$(findstring x86,$(BOARD)))
  48. KERNELNAME="bzImage"
  49. endif
  50. ifneq (,$(findstring ppc,$(BOARD)))
  51. KERNELNAME="uImage"
  52. endif
  53. define Kernel/Prepare/Default
  54. bzcat $(DL_DIR)/$(LINUX_SOURCE) | tar -C $(KERNEL_BUILD_DIR) $(TAR_OPTIONS)
  55. [ -d ../generic-$(KERNEL)/patches ] && $(PATCH) $(LINUX_DIR) ../generic-$(KERNEL)/patches
  56. [ -d ./patches ] && $(PATCH) $(LINUX_DIR) ./patches
  57. endef
  58. define Kernel/Prepare
  59. $(call Kernel/Prepare/Default)
  60. endef
  61. define Kernel/Configure/2.4
  62. $(SED) "s,\-mcpu=,\-mtune=,g;" $(LINUX_DIR)/arch/mips/Makefile
  63. $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) oldconfig include/linux/compile.h include/linux/version.h
  64. $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" ARCH=$(LINUX_KARCH) dep
  65. endef
  66. define Kernel/Configure/2.6
  67. $(MAKE) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) oldconfig prepare scripts
  68. endef
  69. define Kernel/Configure/Default
  70. @$(CP) $(LINUX_CONFIG) $(LINUX_DIR)/.config
  71. $(call Kernel/Configure/$(KERNEL))
  72. endef
  73. define Kernel/Configure
  74. $(call Kernel/Configure/Default)
  75. endef
  76. define Kernel/CompileModules/Default
  77. $(MAKE) -j$(CONFIG_JLEVEL) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) modules
  78. $(MAKE) -C "$(LINUX_DIR)" CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) DEPMOD=true INSTALL_MOD_PATH=$(KERNEL_BUILD_DIR)/modules modules_install
  79. endef
  80. define Kernel/CompileModules
  81. $(call Kernel/CompileModules/Default)
  82. endef
  83. ifeq ($(KERNEL),2.6)
  84. ifeq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),y)
  85. define Kernel/SetInitramfs
  86. mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
  87. grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
  88. echo 'CONFIG_INITRAMFS_SOURCE="../../root"' >> $(LINUX_DIR)/.config
  89. echo 'CONFIG_INITRAMFS_ROOT_UID=0' >> $(LINUX_DIR)/.config
  90. echo 'CONFIG_INITRAMFS_ROOT_GID=0' >> $(LINUX_DIR)/.config
  91. mkdir -p $(BUILD_DIR)/root/etc/init.d
  92. $(CP) ../generic-2.6/files/init $(BUILD_DIR)/root/
  93. endef
  94. else
  95. define Kernel/SetInitramfs
  96. mv $(LINUX_DIR)/.config $(LINUX_DIR)/.config.old
  97. grep -v INITRAMFS $(LINUX_DIR)/.config.old > $(LINUX_DIR)/.config
  98. rm -f $(BUILD_DIR)/root/init $(BUILD_DIR)/root/etc/init.d/S00initramfs
  99. echo 'CONFIG_INITRAMFS_SOURCE=""' >> $(LINUX_DIR)/.config
  100. endef
  101. endif
  102. endif
  103. define Kernel/CompileImage/Default
  104. $(call Kernel/SetInitramfs)
  105. $(MAKE) -j$(CONFIG_JLEVEL) -C $(LINUX_DIR) CROSS_COMPILE="$(KERNEL_CROSS)" CC="$(KERNEL_CC)" ARCH=$(LINUX_KARCH) $(KERNELNAME)
  106. $(KERNEL_CROSS)objcopy -O binary -R .reginfo -R .note -R .comment -R .mdebug -S $(LINUX_DIR)/vmlinux $(LINUX_KERNEL)
  107. endef
  108. define Kernel/CompileImage
  109. $(call Kernel/CompileImage/Default)
  110. endef
  111. define Kernel/Clean/Default
  112. rm -f $(LINUX_DIR)/.linux-compile
  113. rm -f $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION)/.configured
  114. rm -f $(LINUX_KERNEL)
  115. $(MAKE) -C $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) clean
  116. endef
  117. define Kernel/Clean
  118. $(call Kernel/Clean/Default)
  119. endef
  120. define BuildKernel
  121. ifneq ($(LINUX_SITE),)
  122. $(DL_DIR)/$(LINUX_SOURCE):
  123. -mkdir -p $(DL_DIR)
  124. $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
  125. endif
  126. $(LINUX_DIR)/.prepared: $(DL_DIR)/$(LINUX_SOURCE)
  127. -rm -rf $(KERNEL_BUILD_DIR)
  128. -mkdir -p $(KERNEL_BUILD_DIR)
  129. $(call Kernel/Prepare)
  130. touch $$@
  131. $(LINUX_DIR)/.configured: $(LINUX_DIR)/.prepared $(LINUX_CONFIG)
  132. $(call Kernel/Configure)
  133. touch $$@
  134. $(LINUX_DIR)/.modules: $(LINUX_DIR)/.configured
  135. rm -rf $(KERNEL_BUILD_DIR)/modules
  136. @rm -f $(BUILD_DIR)/linux
  137. ln -sf $(KERNEL_BUILD_DIR)/linux-$(LINUX_VERSION) $(BUILD_DIR)/linux
  138. $(call Kernel/CompileModules)
  139. touch $$@
  140. $(LINUX_DIR)/.image: $(LINUX_DIR)/.configured FORCE
  141. $(call Kernel/CompileImage)
  142. touch $$@
  143. mostlyclean: FORCE
  144. $(call Kernel/Clean)
  145. ifeq ($(DUMP),1)
  146. dumpinfo:
  147. @echo 'Target: $(BOARD)-$(KERNEL)'
  148. @echo 'Target-Name: $(BOARDNAME) [$(KERNEL)]'
  149. @echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'
  150. @echo 'Target-Arch: $(ARCH)'
  151. @echo 'Target-Features: $(FEATURES)'
  152. @echo 'Linux-Version: $(LINUX_VERSION)'
  153. @echo 'Linux-Release: $(LINUX_RELEASE)'
  154. @echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'
  155. @echo 'Target-Description:'
  156. @getvar $(call shvar,Target/Description)
  157. @echo '@@'
  158. @echo 'Default-Packages: $(DEFAULT_PACKAGES)'
  159. ifneq ($(DUMPINFO),)
  160. @$(DUMPINFO)
  161. endif
  162. endif
  163. define BuildKernel
  164. endef
  165. endef
  166. define Profile/Default
  167. NAME:=
  168. PACKAGES:=
  169. endef
  170. define Profile
  171. $(eval $(call Profile/Default))
  172. $(eval $(call Profile/$(1)))
  173. DUMPINFO += \
  174. echo "Target-Profile: $(1)"; \
  175. echo "Target-Profile-Name: $(NAME)"; \
  176. echo "Target-Profile-Packages: $(PACKAGES)";
  177. endef
  178. $(eval $(call shexport,Target/Description))
  179. download: $(DL_DIR)/$(LINUX_SOURCE)
  180. prepare: $(LINUX_DIR)/.configured $(TMP_DIR)/.kernel.mk
  181. compile: $(LINUX_DIR)/.modules
  182. install: $(LINUX_DIR)/.image
  183. clean: FORCE
  184. rm -f $(STAMP_DIR)/.linux-compile
  185. rm -rf $(KERNEL_BUILD_DIR)
  186. rebuild: FORCE
  187. @$(MAKE) mostlyclean
  188. @if [ -f $(LINUX_KERNEL) ]; then \
  189. $(MAKE) clean; \
  190. fi
  191. @$(MAKE) compile