kernel-build.mk 5.8 KB

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