target.mk 4.6 KB

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