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)/kernel-version.mk
  9. include $(INCLUDE_DIR)/host.mk
  10. include $(INCLUDE_DIR)/kernel.mk
  11. include $(INCLUDE_DIR)/prereq.mk
  12. override MAKEFLAGS=
  13. GENERIC_LINUX_CONFIG:=$(GENERIC_PLATFORM_DIR)/config-$(shell [ -f "$(GENERIC_PLATFORM_DIR)/config-$(KERNEL_PATCHVER)" ] && echo "$(KERNEL_PATCHVER)" || echo template )
  14. LINUX_CONFIG_DIR ?= ./config$(shell [ -d "./config-$(KERNEL_PATCHVER)" ] && printf -- "-$(KERNEL_PATCHVER)" || true )
  15. LINUX_CONFIG ?= $(LINUX_CONFIG_DIR)/default
  16. ifneq ($(DUMP),)
  17. TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(BOARD)-$(KERNEL)
  18. $(TMP_CONFIG): $(GENERIC_LINUX_CONFIG) $(LINUX_CONFIG)
  19. $(SCRIPT_DIR)/config.pl + $^ > $@
  20. -include $(TMP_CONFIG)
  21. .SILENT: $(TMP_CONFIG)
  22. endif
  23. ifneq ($(CONFIG_PCI),)
  24. FEATURES += pci
  25. endif
  26. ifneq ($(CONFIG_USB),)
  27. FEATURES += usb
  28. endif
  29. ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
  30. FEATURES += pcmcia
  31. endif
  32. # remove duplicates
  33. FEATURES:=$(sort $(FEATURES))
  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. STAMP_PREPARED:=$(LINUX_DIR)/.prepared
  51. STAMP_CONFIGURED:=$(LINUX_DIR)/.configured
  52. include $(INCLUDE_DIR)/quilt.mk
  53. include $(INCLUDE_DIR)/kernel-defaults.mk
  54. define Kernel/Prepare
  55. $(call Kernel/Prepare/Default)
  56. endef
  57. define Kernel/Configure
  58. $(call Kernel/Configure/Default)
  59. endef
  60. define Kernel/CompileModules
  61. $(call Kernel/CompileModules/Default)
  62. endef
  63. define Kernel/CompileImage
  64. $(call Kernel/CompileImage/Default)
  65. endef
  66. define Kernel/Clean
  67. $(call Kernel/Clean/Default)
  68. endef
  69. define BuildKernel
  70. ifneq ($(LINUX_SITE),)
  71. $(DL_DIR)/$(LINUX_SOURCE):
  72. -mkdir -p $(DL_DIR)
  73. $(SCRIPT_DIR)/download.pl $(DL_DIR) $(LINUX_SOURCE) $(LINUX_KERNEL_MD5SUM) $(LINUX_SITE)
  74. endif
  75. $(STAMP_PREPARED): $(DL_DIR)/$(LINUX_SOURCE)
  76. -rm -rf $(KERNEL_BUILD_DIR)
  77. -mkdir -p $(KERNEL_BUILD_DIR)
  78. $(call Kernel/Prepare)
  79. touch $$@
  80. $(STAMP_CONFIGURED): $(STAMP_PREPARED) $(LINUX_CONFIG) $(GENERIC_LINUX_CONFIG) $(TOPDIR)/.config
  81. $(call Kernel/Configure)
  82. touch $$@
  83. $(LINUX_DIR)/.modules: $(STAMP_CONFIGURED) $(LINUX_DIR)/.config FORCE
  84. $(call Kernel/CompileModules)
  85. touch $$@
  86. $(LINUX_DIR)/.image: $(STAMP_CONFIGURED) FORCE
  87. $(call Kernel/CompileImage)
  88. touch $$@
  89. mostlyclean: FORCE
  90. $(call Kernel/Clean)
  91. ifeq ($(DUMP),1)
  92. dumpinfo:
  93. @echo 'Target: $(BOARD)-$(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