kernel-build.mk 7.1 KB

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