target.mk 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. #
  2. # Copyright (C) 2007-2008 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 ($(__target_inc),1)
  8. __target_inc=1
  9. # default device type
  10. DEVICE_TYPE?=router
  11. # Default packages - the really basic set
  12. DEFAULT_PACKAGES:=base-files libc libgcc busybox dropbear mtd uci opkg ucitrigger
  13. # For router targets
  14. DEFAULT_PACKAGES.router:=dnsmasq iptables ppp ppp-mod-pppoe kmod-ipt-nathelper firewall
  15. DEFAULT_PACKAGES.bootloader:=
  16. # Additional packages for Linux 2.6
  17. ifneq ($(KERNEL),2.4)
  18. DEFAULT_PACKAGES += udevtrigger hotplug2
  19. endif
  20. # Add device specific packages
  21. DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
  22. ifneq ($(DUMP),)
  23. all: dumpinfo
  24. endif
  25. target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
  26. ifeq ($(DUMP),)
  27. PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
  28. SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
  29. else
  30. PLATFORM_DIR:=${CURDIR}
  31. endif
  32. TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
  33. PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
  34. ifneq ($(TARGET_BUILD),1)
  35. ifndef DUMP
  36. include $(PLATFORM_DIR)/Makefile
  37. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  38. include $(PLATFORM_SUBDIR)/target.mk
  39. endif
  40. endif
  41. else
  42. ifneq ($(SUBTARGET),)
  43. -include ./$(SUBTARGET)/target.mk
  44. endif
  45. endif
  46. define Profile/Default
  47. NAME:=
  48. PACKAGES:=
  49. endef
  50. ifndef Profile
  51. define Profile
  52. $(eval $(call Profile/Default))
  53. $(eval $(call Profile/$(1)))
  54. $(eval $(call shexport,Profile/$(1)/Config))
  55. $(eval $(call shexport,Profile/$(1)/Description))
  56. DUMPINFO += \
  57. echo "Target-Profile: $(1)"; \
  58. echo "Target-Profile-Name: $(NAME)"; \
  59. echo "Target-Profile-Packages: $(PACKAGES)"; \
  60. if [ -f ./config/profile-$(1) ]; then \
  61. echo "Target-Profile-Kconfig: yes"; \
  62. fi; \
  63. echo "Target-Profile-Config: "; \
  64. getvar "$(call shvar,Profile/$(1)/Config)"; \
  65. echo "@@"; \
  66. echo "Target-Profile-Description:"; \
  67. getvar "$(call shvar,Profile/$(1)/Description)"; \
  68. echo "@@"; \
  69. echo;
  70. ifeq ($(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(if $(SUBTARGET),$(SUBTARGET)_)$(1))),y)
  71. PROFILE=$(1)
  72. endif
  73. endef
  74. endif
  75. ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
  76. define IncludeProfiles
  77. -include $(PLATFORM_DIR)/profiles/*.mk
  78. -include $(PLATFORM_SUBDIR)/profiles/*.mk
  79. endef
  80. else
  81. define IncludeProfiles
  82. -include $(PLATFORM_DIR)/profiles/*.mk
  83. endef
  84. endif
  85. ifeq ($(TARGET_BUILD),1)
  86. $(eval $(call IncludeProfiles))
  87. else
  88. ifeq ($(DUMP),)
  89. $(eval $(call IncludeProfiles))
  90. endif
  91. endif
  92. $(eval $(call shexport,Target/Description))
  93. ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
  94. include $(INCLUDE_DIR)/kernel-version.mk
  95. endif
  96. GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic-$(KERNEL)
  97. GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/patches$(if $(wildcard $(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
  98. GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
  99. GENERIC_LINUX_CONFIG?=$(firstword $(wildcard $(GENERIC_PLATFORM_DIR)/config-$(KERNEL_PATCHVER) $(GENERIC_PLATFORM_DIR)/config-default))
  100. LINUX_CONFIG?=$(firstword $(wildcard $(foreach subdir,$(PLATFORM_DIR) $(PLATFORM_SUBDIR),$(subdir)/config-$(KERNEL_PATCHVER) $(subdir)/config-default)) $(PLATFORM_DIR)/config-$(KERNEL_PATCHVER))
  101. LINUX_SUBCONFIG?=$(firstword $(wildcard $(PLATFORM_SUBDIR)/config-$(KERNEL_PATCHVER) $(PLATFORM_SUBDIR)/config-default))
  102. ifeq ($(LINUX_CONFIG),$(LINUX_SUBCONFIG))
  103. LINUX_SUBCONFIG:=
  104. endif
  105. LINUX_CONFCMD=$(if $(LINUX_CONFIG), \
  106. $(if $(GENERIC_LINUX_CONFIG),,$(error The generic kernel config for your kernel version is missing)) \
  107. $(if $(LINUX_CONFIG),,$(error The target kernel config for your kernel version is missing)) \
  108. $(SCRIPT_DIR)/kconfig.pl \
  109. + $(GENERIC_LINUX_CONFIG) \
  110. $(if $(LINUX_SUBCONFIG),+ $(LINUX_CONFIG) $(LINUX_SUBCONFIG),$(LINUX_CONFIG)), \
  111. true)
  112. ifeq ($(DUMP),1)
  113. BuildTarget=$(BuildTargets/DumpCurrent)
  114. ifneq ($(BOARD),)
  115. TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
  116. $(TMP_CONFIG): $(GENERIC_LINUX_CONFIG) $(LINUX_CONFIG) $(LINUX_SUBCONFIG)
  117. $(LINUX_CONFCMD) > $@ || rm -f $@
  118. -include $(TMP_CONFIG)
  119. .SILENT: $(TMP_CONFIG)
  120. .PRECIOUS: $(TMP_CONFIG)
  121. ifneq ($(CONFIG_GENERIC_GPIO),)
  122. FEATURES += gpio
  123. endif
  124. ifneq ($(CONFIG_PCI),)
  125. FEATURES += pci
  126. endif
  127. ifneq ($(CONFIG_PCIEPORTBUS),)
  128. FEATURES += pcie
  129. endif
  130. ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
  131. FEATURES += usb
  132. endif
  133. ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
  134. FEATURES += pcmcia
  135. endif
  136. ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
  137. FEATURES += display
  138. endif
  139. # remove duplicates
  140. FEATURES:=$(sort $(FEATURES))
  141. endif
  142. DEFAULT_CFLAGS_i386=-O2 -pipe -march=i486 -funit-at-a-time
  143. DEFAULT_CFLAGS_x86_64=-O2 -pipe -march=athlon64 -funit-at-a-time
  144. DEFAULT_CFLAGS_mips=-Os -pipe -mips32 -mtune=mips32 -funit-at-a-time
  145. DEFAULT_CFLAGS_mipsel=$(DEFAULT_CFLAGS_mips)
  146. DEFAULT_CFLAGS_mips64=-Os -pipe -mips64 -mtune=mips64 -mabi=64 -funit-at-a-time
  147. DEFAULT_CFLAGS_mips64el=$(DEFAULT_CFLAGS_mips64)
  148. DEFAULT_CFLAGS_arm=-Os -pipe -march=armv5te -mtune=xscale -funit-at-a-time
  149. DEFAULT_CFLAGS_armeb=$(DEFAULT_CFLAGS_arm)
  150. DEFAULT_CFLAGS=$(if $(DEFAULT_CFLAGS_$(ARCH)),$(DEFAULT_CFLAGS_$(ARCH)),-Os -pipe -funit-at-a-time)
  151. endif
  152. define BuildTargets/DumpCurrent
  153. .PHONY: dumpinfo
  154. dumpinfo:
  155. @echo 'Target: $(TARGETID)'; \
  156. echo 'Target-Board: $(BOARD)'; \
  157. echo 'Target-Kernel: $(KERNEL)'; \
  158. echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),, [$(KERNEL)])$(if $(SUBTARGETS),$(if $(SUBTARGET), [$(KERNEL)]))'; \
  159. echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'; \
  160. echo 'Target-Arch: $(ARCH)'; \
  161. echo 'Target-Features: $(FEATURES)'; \
  162. echo 'Target-Depends: $(DEPENDS)'; \
  163. echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
  164. echo 'Linux-Version: $(LINUX_VERSION)'; \
  165. echo 'Linux-Release: $(LINUX_RELEASE)'; \
  166. echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
  167. echo 'Target-Description:'; \
  168. getvar $(call shvar,Target/Description); \
  169. echo '@@'; \
  170. echo 'Default-Packages: $(DEFAULT_PACKAGES)'; \
  171. $(DUMPINFO)
  172. $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
  173. endef
  174. include $(INCLUDE_DIR)/kernel.mk
  175. ifeq ($(TARGET_BUILD),1)
  176. include $(INCLUDE_DIR)/kernel-build.mk
  177. BuildTarget?=$(BuildKernel)
  178. endif
  179. endif #__target_inc