kernel-build.mk 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. KERNEL_BUILD:=1
  8. include $(INCLUDE_DIR)/host.mk
  9. include $(INCLUDE_DIR)/kernel.mk
  10. include $(INCLUDE_DIR)/prereq.mk
  11. override MAKEFLAGS=
  12. GENERIC_LINUX_CONFIG:=$(GENERIC_PLATFORM_DIR)/config-$(shell [ -f "$(GENERIC_PLATFORM_DIR)/config-$(KERNEL_PATCHVER)" ] && echo "$(KERNEL_PATCHVER)" || echo template )
  13. LINUX_CONFIG_DIR ?= ./config$(shell [ -d "./config-$(KERNEL_PATCHVER)" ] && printf -- "-$(KERNEL_PATCHVER)" || true )
  14. LINUX_CONFIG ?= $(LINUX_CONFIG_DIR)/default
  15. ifneq ($(DUMP),)
  16. TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(BOARD)-$(KERNEL)
  17. $(TMP_CONFIG): $(GENERIC_LINUX_CONFIG) $(LINUX_CONFIG)
  18. $(SCRIPT_DIR)/config.pl + $^ > $@
  19. -include $(TMP_CONFIG)
  20. .SILENT: $(TMP_CONFIG)
  21. endif
  22. ifneq ($(CONFIG_PCI),)
  23. FEATURES += pci
  24. endif
  25. ifneq ($(CONFIG_USB),)
  26. FEATURES += usb
  27. endif
  28. ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
  29. FEATURES += pcmcia
  30. endif
  31. # remove duplicates
  32. FEATURES:=$(sort $(FEATURES))
  33. ifeq ($(DUMP),1)
  34. all: dumpinfo
  35. else
  36. all: compile
  37. endif
  38. ifneq (,$(findstring uml,$(BOARD)))
  39. LINUX_KARCH:=um
  40. else
  41. LINUX_KARCH:=$(shell echo $(ARCH) | sed -e 's/i[3-9]86/i386/' \
  42. -e 's/mipsel/mips/' \
  43. -e 's/mipseb/mips/' \
  44. -e 's/powerpc/ppc/' \
  45. -e 's/sh[234]/sh/' \
  46. -e 's/armeb/arm/' \
  47. )
  48. endif
  49. STAMP_PREPARED:=$(LINUX_DIR)/.prepared
  50. STAMP_CONFIGURED:=$(LINUX_DIR)/.configured
  51. include $(INCLUDE_DIR)/quilt.mk
  52. include $(INCLUDE_DIR)/kernel-defaults.mk
  53. define Kernel/Prepare
  54. $(call Kernel/Prepare/Default)
  55. endef
  56. define Kernel/Configure
  57. $(call Kernel/Configure/Default)
  58. endef
  59. define Kernel/CompileModules
  60. $(call Kernel/CompileModules/Default)
  61. endef
  62. define Kernel/CompileImage
  63. $(call Kernel/CompileImage/Default)
  64. endef
  65. define Kernel/Clean
  66. $(call Kernel/Clean/Default)
  67. endef
  68. define BuildKernel
  69. ifneq ($(LINUX_SITE),)
  70. $(DL_DIR)/$(LINUX_SOURCE):
  71. -mkdir -p $(DL_DIR)
  72. $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
  73. endif
  74. $(STAMP_PREPARED): $(DL_DIR)/$(LINUX_SOURCE)
  75. -rm -rf $(KERNEL_BUILD_DIR)
  76. -mkdir -p $(KERNEL_BUILD_DIR)
  77. $(call Kernel/Prepare)
  78. touch $$@
  79. $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_CONFIG) $(GENERIC_LINUX_CONFIG) $(TOPDIR)/.config
  80. $(call Kernel/Configure)
  81. touch $$@
  82. $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
  83. $(call Kernel/CompileModules)
  84. touch $$@
  85. $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) FORCE
  86. $(call Kernel/CompileImage)
  87. touch $$@
  88. mostlyclean: FORCE
  89. $(call Kernel/Clean)
  90. ifeq ($(DUMP),1)
  91. dumpinfo:
  92. @echo 'Target: $(BOARD)'
  93. @echo 'Target-Kernel: $(KERNEL)'
  94. @echo 'Target-Name: $(BOARDNAME) [$(KERNEL)]'
  95. @echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'
  96. @echo 'Target-Arch: $(ARCH)'
  97. @echo 'Target-Features: $(FEATURES)'
  98. @echo 'Linux-Version: $(LINUX_VERSION)'
  99. @echo 'Linux-Release: $(LINUX_RELEASE)'
  100. @echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'
  101. @echo 'Target-Description:'
  102. @getvar $(call shvar,Target/Description)
  103. @echo '@@'
  104. @echo 'Default-Packages: $(DEFAULT_PACKAGES)'
  105. ifneq ($(DUMPINFO),)
  106. @$(DUMPINFO)
  107. endif
  108. endif
  109. define BuildKernel
  110. endef
  111. endef
  112. define Profile/Default
  113. NAME:=
  114. PACKAGES:=
  115. endef
  116. confname=$(subst .,_,$(subst -,_,$(1)))
  117. define Profile
  118. $(eval $(call Profile/Default))
  119. $(eval $(call Profile/$(1)))
  120. $(eval $(call shexport,Profile/$(1)/Config))
  121. $(eval $(call shexport,Profile/$(1)/Description))
  122. DUMPINFO += \
  123. echo "Target-Profile: $(1)"; \
  124. echo "Target-Profile-Name: $(NAME)"; \
  125. echo "Target-Profile-Packages: $(PACKAGES)"; \
  126. if [ -f ./config/profile-$(1) ]; then \
  127. echo "Target-Profile-Kconfig: yes"; \
  128. fi; \
  129. echo "Target-Profile-Config: "; \
  130. getvar "$(call shvar,Profile/$(1)/Config)"; \
  131. echo "@@"; \
  132. echo "Target-Profile-Description:"; \
  133. getvar "$(call shvar,Profile/$(1)/Description)"; \
  134. echo "@@"; \
  135. echo;
  136. ifeq ($(CONFIG_LINUX_$(call confname,$(KERNEL)_$(1))),y)
  137. PROFILE=$(1)
  138. endif
  139. endef
  140. $(eval $(call shexport,Target/Description))
  141. download: $(DL_DIR)/$(LINUX_SOURCE)
  142. prepare: $(STAMP_CONFIGURED)
  143. compile: $(LINUX_DIR)/.modules
  144. $(MAKE) -C image compile
  145. oldconfig menuconfig: $(STAMP_PREPARED) FORCE
  146. $(call Kernel/Configure)
  147. $(SCRIPT_DIR)/config.pl '+' $(GENERIC_LINUX_CONFIG) $(LINUX_CONFIG) > $(LINUX_DIR)/.config
  148. $(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) $@
  149. $(SCRIPT_DIR)/config.pl '>' $(GENERIC_LINUX_CONFIG) $(LINUX_DIR)/.config > $(LINUX_CONFIG)
  150. install: $(LINUX_DIR)/.image
  151. $(MAKE) -C image compile install
  152. clean: FORCE
  153. rm -f $(STAMP_DIR)/.linux-compile
  154. rm -rf $(KERNEL_BUILD_DIR)
  155. rebuild: FORCE
  156. @$(MAKE) mostlyclean
  157. @if [ -f $(LINUX_KERNEL) ]; then \
  158. $(MAKE) clean; \
  159. fi
  160. @$(MAKE) compile
  161. image-prereq:
  162. $(SUBMAKE) -s -C image prereq
  163. prereq: image-prereq