d593a5f0df643592225e2d6540a45a4be67e6ff1
[openwrt/staging/wigyori.git] / include / target.mk
1 #
2 # Copyright (C) 2007-2008 OpenWrt.org
3 # Copyright (C) 2016 LEDE Project
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8
9 ifneq ($(__target_inc),1)
10 __target_inc=1
11
12 # default device type
13 DEVICE_TYPE?=router
14
15 # Default packages - the really basic set
16 DEFAULT_PACKAGES:=\
17 base-files \
18 busybox \
19 ca-bundle \
20 dropbear \
21 fstools \
22 libc \
23 libgcc \
24 libustream-wolfssl \
25 logd \
26 mtd \
27 netifd \
28 opkg \
29 uci \
30 uclient-fetch \
31 urandom-seed \
32 urngd
33 # For the basic set
34 DEFAULT_PACKAGES.basic:=
35 # For nas targets
36 DEFAULT_PACKAGES.nas:=\
37 block-mount \
38 fdisk \
39 lsblk \
40 mdadm
41 # For router targets
42 DEFAULT_PACKAGES.router:=\
43 dnsmasq \
44 firewall \
45 ip6tables \
46 iptables \
47 kmod-ipt-offload \
48 odhcp6c \
49 odhcpd-ipv6only \
50 ppp \
51 ppp-mod-pppoe
52
53 ifneq ($(DUMP),)
54 all: dumpinfo
55 endif
56
57 target_conf=$(subst .,_,$(subst -,_,$(subst /,_,$(1))))
58 ifeq ($(DUMP),)
59 PLATFORM_DIR:=$(TOPDIR)/target/linux/$(BOARD)
60 SUBTARGET:=$(strip $(foreach subdir,$(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)),$(if $(CONFIG_TARGET_$(call target_conf,$(BOARD)_$(subdir))),$(subdir))))
61 else
62 PLATFORM_DIR:=${CURDIR}
63 ifeq ($(SUBTARGETS),)
64 SUBTARGETS:=$(strip $(patsubst $(PLATFORM_DIR)/%/target.mk,%,$(wildcard $(PLATFORM_DIR)/*/target.mk)))
65 endif
66 endif
67
68 TARGETID:=$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))
69 PLATFORM_SUBDIR:=$(PLATFORM_DIR)$(if $(SUBTARGET),/$(SUBTARGET))
70
71 ifneq ($(TARGET_BUILD),1)
72 ifndef DUMP
73 include $(PLATFORM_DIR)/Makefile
74 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
75 include $(PLATFORM_SUBDIR)/target.mk
76 endif
77 endif
78 else
79 ifneq ($(SUBTARGET),)
80 -include ./$(SUBTARGET)/target.mk
81 endif
82 endif
83
84 # Add device specific packages (here below to allow device type set from subtarget)
85 DEFAULT_PACKAGES += $(DEFAULT_PACKAGES.$(DEVICE_TYPE))
86
87 filter_packages = $(filter-out -% $(patsubst -%,%,$(filter -%,$(1))),$(1))
88 extra_packages = $(if $(filter wpad wpad-% nas,$(1)),iwinfo)
89
90 define ProfileDefault
91 NAME:=
92 PRIORITY:=
93 PACKAGES:=
94 endef
95
96 ifndef Profile
97 define Profile
98 $(eval $(call ProfileDefault))
99 $(eval $(call Profile/$(1)))
100 dumpinfo : $(call shexport,Profile/$(1)/Description)
101 PACKAGES := $(filter-out -%,$(PACKAGES))
102 DUMPINFO += \
103 echo "Target-Profile: $(1)"; \
104 $(if $(PRIORITY), echo "Target-Profile-Priority: $(PRIORITY)"; ) \
105 echo "Target-Profile-Name: $(NAME)"; \
106 echo "Target-Profile-Packages: $(PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES) $(PACKAGES))"; \
107 echo "Target-Profile-Description:"; \
108 echo "$$$$$$$$$(call shvar,Profile/$(1)/Description)"; \
109 echo "@@"; \
110 echo;
111 endef
112 endif
113
114 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
115 define IncludeProfiles
116 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
117 -include $(sort $(wildcard $(PLATFORM_SUBDIR)/profiles/*.mk))
118 endef
119 else
120 define IncludeProfiles
121 -include $(sort $(wildcard $(PLATFORM_DIR)/profiles/*.mk))
122 endef
123 endif
124
125 PROFILE?=$(call qstrip,$(CONFIG_TARGET_PROFILE))
126
127 ifeq ($(TARGET_BUILD),1)
128 ifneq ($(DUMP),)
129 $(eval $(call IncludeProfiles))
130 endif
131 endif
132
133 ifneq ($(TARGET_BUILD)$(if $(DUMP),,1),)
134 include $(INCLUDE_DIR)/kernel-version.mk
135 endif
136
137 GENERIC_PLATFORM_DIR := $(TOPDIR)/target/linux/generic
138 GENERIC_BACKPORT_DIR := $(GENERIC_PLATFORM_DIR)/backport$(if $(wildcard $(GENERIC_PLATFORM_DIR)/backport-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
139 GENERIC_PATCH_DIR := $(GENERIC_PLATFORM_DIR)/pending$(if $(wildcard $(GENERIC_PLATFORM_DIR)/pending-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
140 GENERIC_HACK_DIR := $(GENERIC_PLATFORM_DIR)/hack$(if $(wildcard $(GENERIC_PLATFORM_DIR)/hack-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER))
141 GENERIC_FILES_DIR := $(foreach dir,$(wildcard $(GENERIC_PLATFORM_DIR)/files $(GENERIC_PLATFORM_DIR)/files-$(KERNEL_PATCHVER)),"$(dir)")
142
143 __config_name_list = $(1)/config-$(KERNEL_PATCHVER) $(1)/config-default
144 __config_list = $(firstword $(wildcard $(call __config_name_list,$(1))))
145 find_kernel_config=$(if $(__config_list),$(__config_list),$(lastword $(__config_name_list)))
146
147 GENERIC_LINUX_CONFIG = $(call find_kernel_config,$(GENERIC_PLATFORM_DIR))
148 LINUX_TARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_DIR))
149 ifneq ($(PLATFORM_DIR),$(PLATFORM_SUBDIR))
150 LINUX_SUBTARGET_CONFIG = $(call find_kernel_config,$(PLATFORM_SUBDIR))
151 endif
152
153 # config file list used for compiling
154 LINUX_KCONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(TOPDIR)/env/kernel-config)
155
156 # default config list for reconfiguring
157 # defaults to subtarget if subtarget exists and target does not
158 # defaults to target otherwise
159 USE_SUBTARGET_CONFIG = $(if $(wildcard $(LINUX_TARGET_CONFIG)),,$(if $(LINUX_SUBTARGET_CONFIG),1))
160
161 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG)))
162 LINUX_RECONFIG_TARGET = $(if $(USE_SUBTARGET_CONFIG),$(LINUX_SUBTARGET_CONFIG),$(LINUX_TARGET_CONFIG))
163
164 # select the config file to be changed by kernel_menuconfig/kernel_oldconfig
165 ifeq ($(CONFIG_TARGET),platform)
166 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG))
167 LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
168 endif
169 ifeq ($(CONFIG_TARGET),subtarget)
170 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_TARGET_CONFIG) $(LINUX_SUBTARGET_CONFIG))
171 LINUX_RECONFIG_TARGET = $(LINUX_SUBTARGET_CONFIG)
172 endif
173 ifeq ($(CONFIG_TARGET),subtarget_platform)
174 LINUX_RECONFIG_LIST = $(wildcard $(GENERIC_LINUX_CONFIG) $(LINUX_SUBTARGET_CONFIG) $(LINUX_TARGET_CONFIG))
175 LINUX_RECONFIG_TARGET = $(LINUX_TARGET_CONFIG)
176 endif
177 ifeq ($(CONFIG_TARGET),env)
178 LINUX_RECONFIG_LIST = $(LINUX_KCONFIG_LIST)
179 LINUX_RECONFIG_TARGET = $(TOPDIR)/env/kernel-config
180 endif
181
182 __linux_confcmd = $(SCRIPT_DIR)/kconfig.pl $(2) $(patsubst %,+,$(wordlist 2,9999,$(1))) $(1)
183
184 LINUX_CONF_CMD = $(call __linux_confcmd,$(LINUX_KCONFIG_LIST),)
185 LINUX_RECONF_CMD = $(call __linux_confcmd,$(LINUX_RECONFIG_LIST),)
186 LINUX_RECONF_DIFF = $(call __linux_confcmd,$(filter-out $(LINUX_RECONFIG_TARGET),$(LINUX_RECONFIG_LIST)),'>')
187
188 ifeq ($(DUMP),1)
189 BuildTarget=$(BuildTargets/DumpCurrent)
190
191 CPU_CFLAGS = -Os -pipe
192 ifneq ($(findstring mips,$(ARCH)),)
193 ifneq ($(findstring mips64,$(ARCH)),)
194 CPU_TYPE ?= mips64
195 else
196 CPU_TYPE ?= mips32
197 endif
198 CPU_CFLAGS += -mno-branch-likely
199 CPU_CFLAGS_mips32 = -mips32 -mtune=mips32
200 CPU_CFLAGS_mips64 = -mips64 -mtune=mips64 -mabi=64
201 CPU_CFLAGS_mips64r2 = -mips64r2 -mtune=mips64r2 -mabi=64
202 CPU_CFLAGS_24kc = -mips32r2 -mtune=24kc
203 CPU_CFLAGS_74kc = -mips32r2 -mtune=74kc
204 CPU_CFLAGS_octeonplus = -march=octeon+ -mabi=64
205 endif
206 ifeq ($(ARCH),i386)
207 CPU_TYPE ?= pentium-mmx
208 CPU_CFLAGS_pentium-mmx = -march=pentium-mmx
209 CPU_CFLAGS_pentium4 = -march=pentium4
210 endif
211 ifneq ($(findstring arm,$(ARCH)),)
212 CPU_TYPE ?= xscale
213 endif
214 ifeq ($(ARCH),powerpc)
215 CPU_CFLAGS_603e:=-mcpu=603e
216 CPU_CFLAGS_8540:=-mcpu=8540
217 CPU_CFLAGS_405:=-mcpu=405
218 CPU_CFLAGS_440:=-mcpu=440
219 CPU_CFLAGS_464fp:=-mcpu=464fp
220 endif
221 ifeq ($(ARCH),powerpc64)
222 CPU_TYPE ?= powerpc64
223 CPU_CFLAGS_powerpc64:=-mcpu=powerpc64
224 endif
225 ifeq ($(ARCH),sparc)
226 CPU_TYPE = sparc
227 CPU_CFLAGS_ultrasparc = -mcpu=ultrasparc
228 endif
229 ifeq ($(ARCH),aarch64)
230 CPU_TYPE ?= generic
231 CPU_CFLAGS_generic = -mcpu=generic
232 CPU_CFLAGS_cortex-a53 = -mcpu=cortex-a53
233 endif
234 ifeq ($(ARCH),arc)
235 CPU_TYPE ?= arc700
236 CPU_CFLAGS += -matomic
237 CPU_CFLAGS_arc700 = -mcpu=arc700
238 CPU_CFLAGS_archs = -mcpu=archs
239 endif
240 ifneq ($(CPU_TYPE),)
241 ifndef CPU_CFLAGS_$(CPU_TYPE)
242 $(warning CPU_TYPE "$(CPU_TYPE)" doesn't correspond to a known type)
243 endif
244 endif
245 DEFAULT_CFLAGS=$(strip $(CPU_CFLAGS) $(CPU_CFLAGS_$(CPU_TYPE)) $(CPU_CFLAGS_$(CPU_SUBTYPE)))
246
247 ifneq ($(BOARD),)
248 TMP_CONFIG:=$(TMP_DIR)/.kconfig-$(call target_conf,$(TARGETID))
249 $(TMP_CONFIG): $(LINUX_KCONFIG_LIST)
250 $(LINUX_CONF_CMD) > $@ || rm -f $@
251 -include $(TMP_CONFIG)
252 .SILENT: $(TMP_CONFIG)
253 .PRECIOUS: $(TMP_CONFIG)
254
255 ifdef KERNEL_TESTING_PATCHVER
256 ifneq ($(KERNEL_TESTING_PATCHVER),$(KERNEL_PATCHVER))
257 FEATURES += testing-kernel
258 endif
259 endif
260 ifneq ($(CONFIG_OF),)
261 FEATURES += dt
262 endif
263 ifneq ($(CONFIG_GENERIC_GPIO)$(CONFIG_GPIOLIB),)
264 FEATURES += gpio
265 endif
266 ifneq ($(CONFIG_PCI),)
267 FEATURES += pci
268 endif
269 ifneq ($(CONFIG_PCIEPORTBUS),)
270 FEATURES += pcie
271 endif
272 ifneq ($(CONFIG_USB)$(CONFIG_USB_SUPPORT),)
273 ifneq ($(CONFIG_USB_ARCH_HAS_HCD)$(CONFIG_USB_EHCI_HCD),)
274 FEATURES += usb
275 endif
276 endif
277 ifneq ($(CONFIG_PCMCIA)$(CONFIG_PCCARD),)
278 FEATURES += pcmcia
279 endif
280 ifneq ($(CONFIG_VGA_CONSOLE)$(CONFIG_FB),)
281 FEATURES += display
282 endif
283 ifneq ($(CONFIG_RTC_CLASS),)
284 FEATURES += rtc
285 endif
286 ifneq ($(CONFIG_VIRTIO),)
287 FEATURES += virtio
288 endif
289 ifneq ($(CONFIG_CPU_MIPS32_R2),)
290 FEATURES += mips16
291 endif
292 FEATURES += $(foreach v,6 7,$(if $(CONFIG_CPU_V$(v)),arm_v$(v)))
293
294 # remove duplicates
295 FEATURES:=$(sort $(FEATURES))
296 endif
297 endif
298
299 CUR_SUBTARGET:=$(SUBTARGET)
300 ifeq ($(SUBTARGETS),)
301 CUR_SUBTARGET := default
302 endif
303
304 define BuildTargets/DumpCurrent
305 .PHONY: dumpinfo
306 dumpinfo : export DESCRIPTION=$$(Target/Description)
307 dumpinfo:
308 @echo 'Target: $(TARGETID)'; \
309 echo 'Target-Board: $(BOARD)'; \
310 echo 'Target-Name: $(BOARDNAME)$(if $(SUBTARGETS),$(if $(SUBTARGET),))'; \
311 echo 'Target-Arch: $(ARCH)'; \
312 echo 'Target-Arch-Packages: $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(ARCH)$(if $(CPU_TYPE),_$(CPU_TYPE))$(if $(CPU_SUBTYPE),_$(CPU_SUBTYPE)))'; \
313 echo 'Target-Features: $(FEATURES)'; \
314 echo 'Target-Depends: $(DEPENDS)'; \
315 echo 'Target-Optimization: $(if $(CFLAGS),$(CFLAGS),$(DEFAULT_CFLAGS))'; \
316 echo 'CPU-Type: $(CPU_TYPE)$(if $(CPU_SUBTYPE),+$(CPU_SUBTYPE))'; \
317 echo 'Linux-Version: $(LINUX_VERSION)'; \
318 $(if $(LINUX_TESTING_VERSION),echo 'Linux-Testing-Version: $(LINUX_TESTING_VERSION)';) \
319 echo 'Linux-Release: $(LINUX_RELEASE)'; \
320 echo 'Linux-Kernel-Arch: $(LINUX_KARCH)'; \
321 $(if $(SUBTARGET),,$(if $(DEFAULT_SUBTARGET), echo 'Default-Subtarget: $(DEFAULT_SUBTARGET)'; )) \
322 echo 'Target-Description:'; \
323 echo "$$$$DESCRIPTION"; \
324 echo '@@'; \
325 echo 'Default-Packages: $(DEFAULT_PACKAGES) $(call extra_packages,$(DEFAULT_PACKAGES))'; \
326 $(DUMPINFO)
327 $(if $(CUR_SUBTARGET),$(SUBMAKE) -r --no-print-directory -C image -s DUMP=1 SUBTARGET=$(CUR_SUBTARGET))
328 $(if $(SUBTARGET),,@$(foreach SUBTARGET,$(SUBTARGETS),$(SUBMAKE) -s DUMP=1 SUBTARGET=$(SUBTARGET); ))
329 endef
330
331 include $(INCLUDE_DIR)/kernel.mk
332 ifeq ($(TARGET_BUILD),1)
333 include $(INCLUDE_DIR)/kernel-build.mk
334 BuildTarget?=$(BuildKernel)
335 endif
336
337 endif #__target_inc