source: trunk/include/target.mk @ 27407

Last change on this file since 27407 was 27407, checked in by blogic, 5 years ago

automatic subtarget enumaration

  • Property svn:eol-style set to native
File size: 7.9 KB
Line 
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
8ifneq ($(__target_inc),1)
9__target_inc=1
10
11# default device type
12DEVICE_TYPE?=router
13
14# Default packages - the really basic set
15DEFAULT_PACKAGES:=base-files libc libgcc busybox dropbear mtd uci opkg hotplug2
16# For router targets
17DEFAULT_PACKAGES.router:=dnsmasq iptables ppp ppp-mod-pppoe kmod-ipt-nathelper firewall
18DEFAULT_PACKAGES.bootloader:=
19
20ifneq ($(DUMP),)
21  all: dumpinfo
22endif
23
24target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
25ifeq ($(DUMP),)
26  PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
27  SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
28else
29  PLATFORM_DIR:=${CURDIR}
30  ifeq ($(SUBTARGETS),)
31    SUBTARGETS:=$(strip $(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)))
32  endif
33endif
34
35TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
36PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
37
38ifneq ($(TARGET_BUILD),1)
39  ifndef DUMP
40    include $(PLATFORM_DIR)/Makefile
41    ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
42      include $(PLATFORM_SUBDIR)/target.mk
43    endif
44  endif
45else
46  ifneq ($(SUBTARGET),)
47    -include ./$(SUBTARGET)/target.mk
48  endif
49endif
50
51# Add device specific packages (here below to allow device type set from subtarget)
52DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
53
54define Profile/Default
55  NAME:=
56  PACKAGES:=
57endef
58
59ifndef Profile
60define Profile
61  $(eval $(call Profile/Default))
62  $(eval $(call Profile/$(1)))
63  $(eval $(call shexport,Profile/$(1)/Config))
64  $(eval $(call shexport,Profile/$(1)/Description))
65  DUMPINFO += \
66        echo "Target-Profile: $(1)"; \
67        echo "Target-Profile-Name: $(NAME)"; \
68        echo "Target-Profile-Packages: $(PACKAGES)"; \
69        if [ -f ./config/profile-$(1) ]; then \
70                echo "Target-Profile-Kconfig: yes"; \
71        fi; \
72        echo "Target-Profile-Config: "; \
73        $(SH_FUNC) getvar "$(call shvar,Profile/$(1)/Config)"; \
74        echo "@@"; \
75        echo "Target-Profile-Description:"; \
76        $(SH_FUNC) getvar "$(call shvar,Profile/$(1)/Description)"; \
77        echo "@@"; \
78        echo;
79  ifeq ($(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(if $(SUBTARGET),$(SUBTARGET)_)$(1))),y)
80    PROFILE=$(1)
81  endif
82endef
83endif
84
85ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
86  define IncludeProfiles
87    -include $(PLATFORM_DIR)/profiles/*.mk
88    -include $(PLATFORM_SUBDIR)/profiles/*.mk
89  endef
90else
91  define IncludeProfiles
92    -include $(PLATFORM_DIR)/profiles/*.mk
93  endef
94endif
95
96ifeq ($(TARGET_BUILD),1)
97  $(eval $(call IncludeProfiles))
98else
99  ifeq ($(DUMP),)
100    $(eval $(call IncludeProfiles))
101  endif
102endif
103
104$(eval $(call shexport,Target/Description))
105
106ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
107  include $(INCLUDE_DIR)/kernel-version.mk
108endif
109
110GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic
111GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/patches$(if $(wildcard $(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
112GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
113
114__config_name_list = $(1)/config-$(KERNEL_PATCHVER) $(1)/config-default
115__config_list = $(firstword $(wildcard $(call __config_name_list,$(1))))
116find_kernel_config=$(if $(__config_list),$(__config_list),$(lastword $(__config_name_list)))
117
118GENERIC_LINUX_CONFIG = $(call find_kernel_config,$(GENERIC_PLATFORM_DIR))
119LINUX_TARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_DIR))
120ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
121  LINUX_SUBTARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_SUBDIR))
122endif
123
124# config file list used for compiling
125LINUX_KCONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(TOPDIR)/env/kernel-config)
126
127# default config list for reconfiguring
128# defaults to subtarget if subtarget exists and target does not
129# defaults to target otherwise
130USE_SUBTARGET_CONFIG = $(if $(wildcard $(LINUX_TARGET_CONFIG)),,$(if $(LINUX_SUBTARGET_CONFIG),1))
131
132LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG)))
133LINUX_RECONFIG_TARGET = $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG),$(LINUX_TARGET_CONFIG))
134
135# select the config file to be cahnged by kernel_menuconfig/kernel_oldconfig
136ifeq ($(CONFIG_TARGET),platform)
137  LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG))
138  LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
139endif
140ifeq ($(CONFIG_TARGET),subtarget)
141  LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG))
142  LINUX_RECONFIG_TARGET = $(LINUX_SUBTARGET_CONFIG)
143endif
144ifeq ($(CONFIG_TARGET),env)
145  LINUX_RECONFIG_LIST = $(LINUX_KCONFIG_LIST)
146  LINUX_RECONFIG_TARGET = $(TOPDIR)/env/kernel-config
147endif
148
149__linux_confcmd = $(SCRIPT_DIR)/kconfig.pl $(2) $(patsubst %,+,$(wordlist 2,9999,$(1))) $(1)
150
151LINUX_CONF_CMD = $(call __linux_confcmd,$(LINUX_KCONFIG_LIST),)
152LINUX_RECONF_CMD = $(call __linux_confcmd,$(LINUX_RECONFIG_LIST),)
153LINUX_RECONF_DIFF = $(call __linux_confcmd,$(filter-out $(LINUX_RECONFIG_TARGET),$(LINUX_RECONFIG_LIST)),'>')
154
155ifeq ($(DUMP),1)
156  BuildTarget=$(BuildTargets/DumpCurrent)
157
158  ifneq ($(BOARD),)
159    TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
160    $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
161                $(LINUX_CONF_CMD) > $@ || rm -f $@
162    -include $(TMP_CONFIG)
163    .SILENT: $(TMP_CONFIG)
164    .PRECIOUS: $(TMP_CONFIG)
165
166    ifneq ($(CONFIG_GENERIC_GPIO),)
167      FEATURES += gpio
168    endif
169    ifneq ($(CONFIG_PCI),)
170      FEATURES += pci
171    endif
172    ifneq ($(CONFIG_PCIEPORTBUS),)
173      FEATURES += pcie
174    endif
175    ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
176      ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
177        FEATURES += usb
178      endif
179    endif
180    ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
181      FEATURES += pcmcia
182    endif
183    ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
184      FEATURES += display
185    endif
186
187    # remove duplicates
188    FEATURES:=$(sort $(FEATURES))
189  endif
190  DEFAULT_CFLAGS_i386=-O2 -pipe -march=i486 -fno-caller-saves
191  DEFAULT_CFLAGS_x86_64=-O2 -pipe -march=athlon64 -fno-caller-saves
192  DEFAULT_CFLAGS_m68k=-Os -pipe -mcfv4e -fno-caller-saves
193  DEFAULT_CFLAGS_mips=-Os -pipe -mips32 -mtune=mips32 -fno-caller-saves
194  DEFAULT_CFLAGS_mipsel=$(DEFAULT_CFLAGS_mips)
195  DEFAULT_CFLAGS_mips64=-Os -pipe -mips64 -mtune=mips64 -mabi=64 -fno-caller-saves
196  DEFAULT_CFLAGS_mips64el=$(DEFAULT_CFLAGS_mips64)
197  DEFAULT_CFLAGS_sparc=-Os -pipe -mcpu=ultrasparc -fno-caller-saves
198  DEFAULT_CFLAGS_arm=-Os -pipe -march=armv5te -mtune=xscale -fno-caller-saves
199  DEFAULT_CFLAGS_armeb=$(DEFAULT_CFLAGS_arm)
200  DEFAULT_CFLAGS=$(if $(DEFAULT_CFLAGS_$(ARCH)),$(DEFAULT_CFLAGS_$(ARCH)),-Os -pipe -fno-caller-saves)
201endif
202
203define BuildTargets/DumpCurrent
204  .PHONY: dumpinfo
205  dumpinfo:
206        @echo 'Target: $(TARGETID)'; \
207         echo 'Target-Board: $(BOARD)'; \
208         echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \
209         echo 'Target-Path: $(subst $(TOPDIR)/,,$(PWD))'; \
210         echo 'Target-Arch: $(ARCH)'; \
211         echo 'Target-Arch-Packages: $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD))'; \
212         echo 'Target-Features: $(FEATURES)'; \
213         echo 'Target-Depends: $(DEPENDS)'; \
214         echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
215         echo 'Linux-Version: $(LINUX_VERSION)'; \
216         echo 'Linux-Release: $(LINUX_RELEASE)'; \
217         echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
218         echo 'Target-Description:'; \
219         $(SH_FUNC) getvar $(call shvar,Target/Description); \
220         echo '@@'; \
221         echo 'Default-Packages: $(DEFAULT_PACKAGES)'; \
222         $(DUMPINFO)
223        $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
224endef
225
226include $(INCLUDE_DIR)/kernel.mk
227ifeq ($(TARGET_BUILD),1)
228  include $(INCLUDE_DIR)/kernel-build.mk
229  BuildTarget?=$(BuildKernel)
230endif
231
232endif #__target_inc
Note: See TracBrowser for help on using the repository browser.