kernel-build.mk 4.6 KB

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