target.mk 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #
  2. # Copyright (C) 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. ifneq ($(DUMP),)
  8. all: dumpinfo
  9. endif
  10. ifneq ($(__target_inc),1)
  11. __target_inc=1
  12. target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
  13. ifeq ($(DUMP),)
  14. PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
  15. SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
  16. else
  17. PLATFORM_DIR:=${CURDIR}
  18. endif
  19. TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
  20. PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
  21. define Target
  22. KERNEL_TARGETS+=$(1)
  23. ifeq ($(DUMP),1)
  24. ifeq ($(SUBTARGET),)
  25. BuildTarget=$$(BuildTargets/DumpAll)
  26. endif
  27. endif
  28. endef
  29. ifneq ($(TARGET_BUILD),1)
  30. include $(PLATFORM_DIR)/Makefile
  31. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  32. include $(PLATFORM_SUBDIR)/target.mk
  33. endif
  34. else
  35. ifneq ($(SUBTARGET),)
  36. -include ./$(SUBTARGET)/target.mk
  37. endif
  38. endif
  39. define Profile/Default
  40. NAME:=
  41. PACKAGES:=
  42. endef
  43. define Profile
  44. $(eval $(call Profile/Default))
  45. $(eval $(call Profile/$(1)))
  46. $(eval $(call shexport,Profile/$(1)/Config))
  47. $(eval $(call shexport,Profile/$(1)/Description))
  48. DUMPINFO += \
  49. echo "Target-Profile: $(1)"; \
  50. echo "Target-Profile-Name: $(NAME)"; \
  51. echo "Target-Profile-Packages: $(PACKAGES)"; \
  52. if [ -f ./config/profile-$(1) ]; then \
  53. echo "Target-Profile-Kconfig: yes"; \
  54. fi; \
  55. echo "Target-Profile-Config: "; \
  56. getvar "$(call shvar,Profile/$(1)/Config)"; \
  57. echo "@@"; \
  58. echo "Target-Profile-Description:"; \
  59. getvar "$(call shvar,Profile/$(1)/Description)"; \
  60. echo "@@"; \
  61. echo;
  62. ifeq ($(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(if $(SUBTARGET),$(SUBTARGET)_)$(1))),y)
  63. PROFILE=$(1)
  64. endif
  65. endef
  66. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  67. define IncludeProfiles
  68. -include $(PLATFORM_DIR)/profiles/*.mk
  69. -include $(PLATFORM_SUBDIR)/profiles/*.mk
  70. endef
  71. else
  72. define IncludeProfiles
  73. -include $(PLATFORM_DIR)/profiles/*.mk
  74. endef
  75. endif
  76. ifeq ($(TARGET_BUILD),1)
  77. $(eval $(call IncludeProfiles))
  78. else
  79. ifeq ($(DUMP),)
  80. $(eval $(call IncludeProfiles))
  81. endif
  82. endif
  83. $(eval $(call shexport,Target/Description))
  84. include $(INCLUDE_DIR)/kernel-version.mk
  85. GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic-$(KERNEL)
  86. GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/patches$(shell [ -d "$(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)" ] && printf -- "-$(KERNEL_PATCHVER)" || true )
  87. GENERIC_LINUX_CONFIG?=$(firstword $(wildcard $(GENERIC_PLATFORM_DIR)/config-$(KERNEL_PATCHVER) $(GENERIC_PLATFORM_DIR)/config-default))
  88. LINUX_CONFIG?=$(firstword $(wildcard $(foreach subdir,$(PLATFORM_DIR) $(PLATFORM_SUBDIR),$(subdir)/config-$(KERNEL_PATCHVER) $(subdir)/config-default)))
  89. LINUX_SUBCONFIG?=$(firstword $(wildcard $(PLATFORM_SUBDIR)/config-$(KERNEL_PATCHVER) $(PLATFORM_SUBDIR)/config-default))
  90. ifeq ($(LINUX_CONFIG),$(LINUX_SUBCONFIG))
  91. LINUX_SUBCONFIG:=
  92. endif
  93. LINUX_CONFCMD=$(if $(LINUX_CONFIG),$(SCRIPT_DIR)/kconfig.pl + $(GENERIC_LINUX_CONFIG) $(if $(LINUX_SUBCONFIG),+ $(LINUX_CONFIG) $(LINUX_SUBCONFIG),$(LINUX_CONFIG)),true)
  94. ifeq ($(DUMP),1)
  95. BuildTarget=$(BuildTargets/DumpCurrent)
  96. ifneq ($(BOARD),)
  97. TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
  98. $(TMP_CONFIG): $(GENERIC_LINUX_CONFIG) $(LINUX_CONFIG) $(LINUX_SUBCONFIG)
  99. $(LINUX_CONFCMD) > $@ || rm -f $@
  100. -include $(TMP_CONFIG)
  101. .SILENT: $(TMP_CONFIG)
  102. .PRECIOUS: $(TMP_CONFIG)
  103. ifneq ($(CONFIG_PCI),)
  104. FEATURES += pci
  105. endif
  106. ifneq ($(CONFIG_USB),)
  107. FEATURES += usb
  108. endif
  109. ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
  110. FEATURES += pcmcia
  111. endif
  112. # remove duplicates
  113. FEATURES:=$(sort $(FEATURES))
  114. endif
  115. endif
  116. define BuildTargets/DumpAll
  117. dumpinfo:
  118. @$(foreach SUBTARGET,$(KERNEL_TARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); )
  119. endef
  120. define BuildTargets/DumpCurrent
  121. dumpinfo:
  122. @echo 'Target: $(TARGETID)'; \
  123. echo 'Target-Board: $(BOARD)'; \
  124. echo 'Target-Kernel: $(KERNEL)'; \
  125. echo 'Target-Name: $(BOARDNAME) [$(KERNEL)]'; \
  126. echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'; \
  127. echo 'Target-Arch: $(ARCH)'; \
  128. echo 'Target-Features: $(FEATURES)'; \
  129. echo 'Target-Depends: $(DEPENDS)'; \
  130. echo 'Linux-Version: $(LINUX_VERSION)'; \
  131. echo 'Linux-Release: $(LINUX_RELEASE)'; \
  132. echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
  133. echo 'Target-Description:'; \
  134. getvar $(call shvar,Target/Description); \
  135. echo '@@'; \
  136. echo 'Default-Packages: $(DEFAULT_PACKAGES)'; \
  137. $(DUMPINFO)
  138. endef
  139. include $(INCLUDE_DIR)/kernel.mk
  140. ifeq ($(TARGET_BUILD),1)
  141. include $(INCLUDE_DIR)/kernel-build.mk
  142. BuildTarget?=$(BuildKernel)
  143. endif
  144. endif #__target_inc