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