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