kernel-build.mk 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. 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)-$(KERNEL)'
  93. @echo 'Target-Name: $(BOARDNAME) [$(KERNEL)]'
  94. @echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'
  95. @echo 'Target-Arch: $(ARCH)'
  96. @echo 'Target-Features: $(FEATURES)'
  97. @echo 'Linux-Version: $(LINUX_VERSION)'
  98. @echo 'Linux-Release: $(LINUX_RELEASE)'
  99. @echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'
  100. @echo 'Target-Description:'
  101. @getvar $(call shvar,Target/Description)
  102. @echo '@@'
  103. @echo 'Default-Packages: $(DEFAULT_PACKAGES)'
  104. ifneq ($(DUMPINFO),)
  105. @$(DUMPINFO)
  106. endif
  107. endif
  108. define BuildKernel
  109. endef
  110. endef
  111. define Profile/Default
  112. NAME:=
  113. PACKAGES:=
  114. endef
  115. confname=$(subst .,_,$(subst -,_,$(1)))
  116. define Profile
  117. $(eval $(call Profile/Default))
  118. $(eval $(call Profile/$(1)))
  119. $(eval $(call shexport,Profile/$(1)/Config))
  120. $(eval $(call shexport,Profile/$(1)/Description))
  121. DUMPINFO += \
  122. echo "Target-Profile: $(1)"; \
  123. echo "Target-Profile-Name: $(NAME)"; \
  124. echo "Target-Profile-Packages: $(PACKAGES)"; \
  125. if [ -f ./config/profile-$(1) ]; then \
  126. echo "Target-Profile-Kconfig: yes"; \
  127. fi; \
  128. echo "Target-Profile-Config: "; \
  129. getvar "$(call shvar,Profile/$(1)/Config)"; \
  130. echo "@@"; \
  131. echo "Target-Profile-Description:"; \
  132. getvar "$(call shvar,Profile/$(1)/Description)"; \
  133. echo "@@"; \
  134. echo;
  135. ifeq ($(CONFIG_LINUX_$(call confname,$(KERNEL)_$(1))),y)
  136. PROFILE=$(1)
  137. endif
  138. endef
  139. $(eval $(call shexport,Target/Description))
  140. download: $(DL_DIR)/$(LINUX_SOURCE)
  141. prepare: $(STAMP_CONFIGURED)
  142. compile: $(LINUX_DIR)/.modules
  143. oldconfig menuconfig: $(STAMP_PREPARED) FORCE
  144. $(call Kernel/Configure)
  145. $(SCRIPT_DIR)/config.pl '+' $(GENERIC_LINUX_CONFIG) $(LINUX_CONFIG) > $(LINUX_DIR)/.config
  146. $(MAKE) -C $(LINUX_DIR) $(KERNEL_MAKEOPTS) $@
  147. $(SCRIPT_DIR)/config.pl '>' $(GENERIC_LINUX_CONFIG) $(LINUX_DIR)/.config > $(LINUX_CONFIG)
  148. install: $(LINUX_DIR)/.image
  149. clean: FORCE
  150. rm -f $(STAMP_DIR)/.linux-compile
  151. rm -rf $(KERNEL_BUILD_DIR)
  152. rebuild: FORCE
  153. @$(MAKE) mostlyclean
  154. @if [ -f $(LINUX_KERNEL) ]; then \
  155. $(MAKE) clean; \
  156. fi
  157. @$(MAKE) compile