kernel-build.mk 5.8 KB

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