summaryrefslogtreecommitdiff
path: root/mk/toolchain.mk
blob: 447bd9a20e22747bc8f2164a41f6696b87208669 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
################################################################################
# Copyright(C) 2009-2013 Abdoulaye Walsimou GAYE <awg@embtoolkit.org>.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
#
# \file         toolchain.mk
# \brief	toolchain.mk of Embtoolkit
# \author       Abdoulaye Walsimou GAYE <awg@embtoolkit.org>
# \date         May 2009
################################################################################

TARGETGCC		:= $(embtk_tools)/bin/$(STRICT_GNU_TARGET)-gcc
TARGETGCXX		:= $(embtk_tools)/bin/$(STRICT_GNU_TARGET)-g++
TARGETCLANG		:= $(embtk_tools)/bin/$(STRICT_GNU_TARGET)-clang
TARGETCLANGXX		:= $(embtk_tools)/bin/$(STRICT_GNU_TARGET)-clang++

#
# Default compilers to use for packages.
#
__TARGETCC-$(CONFIG_EMBTK_GCC_ONLY_TOOLCHAIN)		:= $(TARGETGCC)
__TARGETCC-$(CONFIG_EMBTK_GCC_DEFAULT_TOOLCHAIN)	:= $(TARGETGCC)
__TARGETCXX-$(CONFIG_EMBTK_GCC_ONLY_TOOLCHAIN)		:= $(TARGETGCXX)
__TARGETCXX-$(CONFIG_EMBTK_GCC_DEFAULT_TOOLCHAIN)	:= $(TARGETGCXX)

__TARGETCC-$(CONFIG_EMBTK_LLVM_ONLY_TOOLCHAIN)		:= $(TARGETCLANG)
__TARGETCC-$(CONFIG_EMBTK_LLVM_DEFAULT_TOOLCHAIN)	:= $(TARGETCLANG)
#
# FIXME: remove this when clang++ will support exceptions in c++ for arm,
# as exceptions seem to work for mips.
#
ifeq ($(CONFIG_EMBTK_ARCH_MIPS),y)
__TARGETCXX-$(CONFIG_EMBTK_LLVM_ONLY_TOOLCHAIN)		:= $(TARGETCLANGXX)
__TARGETCXX-$(CONFIG_EMBTK_LLVM_DEFAULT_TOOLCHAIN)	:= $(TARGETCLANGXX)
else
__TARGETCXX-$(CONFIG_EMBTK_LLVM_ONLY_TOOLCHAIN)		:= $(TARGETGCXX)
__TARGETCXX-$(CONFIG_EMBTK_LLVM_DEFAULT_TOOLCHAIN)	:= $(TARGETGCXX)
endif

TARGETCC		:= $(__TARGETCC-y)
TARGETCXX		:= $(__TARGETCXX-y)

#
# Some binutils components.
#
TARGETAR		:= $(embtk_tools)/bin/$(STRICT_GNU_TARGET)-ar
TARGETRANLIB		:= $(embtk_tools)/bin/$(STRICT_GNU_TARGET)-ranlib
TARGETLD		:= $(embtk_tools)/bin/$(STRICT_GNU_TARGET)-ld
TARGETNM		:= $(embtk_tools)/bin/$(STRICT_GNU_TARGET)-nm
TARGETSTRIP		:= $(embtk_tools)/bin/$(STRICT_GNU_TARGET)-strip
TARGETOBJDUMP		:= $(embtk_tools)/bin/$(STRICT_GNU_TARGET)-objdump
TARGETOBJCOPY		:= $(embtk_tools)/bin/$(STRICT_GNU_TARGET)-objcopy

#
# TARGET cflags
#
__kconfig-cflags	:= $(strip $(CONFIG_EMBTK_TARGET_COMPILER_CFLAGS))
__TARGET_CFLAGS		:= $(subst ",,$(__kconfig-cflags))
__TARGET_CFLAGS		+= $(if $(CONFIG_EMBTK_TARGET_NONE_OPTIMIZED),-O0)
__TARGET_CFLAGS		+= $(if $(CONFIG_EMBTK_TARGET_SIZE_OPTIMIZED),-Os)
__TARGET_CFLAGS		+= $(if $(CONFIG_EMBTK_TARGET_SPEED_OPTIMIZED),-O2)
__TARGET_CFLAGS		+= $(if $(CONFIG_EMBTK_TARGET_WITH_DEBUG_DATA),-g)

# cflags for clang
__clang_cflags		:= -Qunused-arguments -fcolor-diagnostics
__TARGET_CFLAGS		+= $(if $(CONFIG_EMBTK_LLVM_ONLY_TOOLCHAIN),$(__clang_cflags))
__TARGET_CFLAGS		+= $(if $(CONFIG_EMBTK_LLVM_DEFAULT_TOOLCHAIN),$(__clang_cflags))

TARGET_CFLAGS		:= $(strip $(__TARGET_CFLAGS))
TARGET_CXXFLAGS		:= $(filter-out $(__clang_cflags),$(TARGET_CFLAGS))
CROSS_COMPILE		:= $(embtk_tools)/bin/$(STRICT_GNU_TARGET)-

export TARGETCC TARGETCXX TARGETAR TARGETRANLIB TARGETLD TARGETNM
export TARGETSTRIP TARGETOBJDUMP TARGETOBJCOPY TARGET_CFLAGS CROSS_COMPILE

ac_cv_func_malloc_0_nonnull=yes
export ac_cv_func_malloc_0_nonnull
ac_cv_func_realloc_0_nonnull=yes
export ac_cv_func_realloc_0_nonnull

PATH			:= $(embtk_htools)/usr/bin:$(embtk_htools)/usr/sbin:$(PATH)
export PATH

LIBDIR			:= $(if $(CONFIG_EMBTK_64BITS_FS_COMPAT32),lib32,lib)
export LIBDIR

# ccache
include mk/ccache.mk

# GMP
include mk/gmp.mk

# MPFR
include mk/mpfr.mk

# MPC
include mk/mpc.mk

# binutils
include mk/binutils.mk

# GCC
include mk/gcc.mk

# llvm/clang compiler infrastructure
include mk/llvm/clang.mk
include mk/llvm/llvm.mk
include mk/llvm/compiler-rt/compiler-rt.mk
include mk/libc++/libcxxrt/libcxxrt.mk
include mk/libc++/libc++/libcxx.mk

# linux kernel headers
include mk/linux.mk

# toolchain addon: strace
include mk/strace.mk
TOOLCHAIN_ADDONS-$(CONFIG_EMBTK_HAVE_STRACE) += strace_install

# toolchain addon: gdb
include packages/development/gdb/gdb.mk
TOOLCHAIN_ADDONS-$(CONFIG_EMBTK_HAVE_GDB) += gdb_install
TOOLCHAIN_ADDONS-$(CONFIG_EMBTK_HAVE_GDBSERVER) += gdbserver_install
TOOLCHAIN_ADDONS-$(CONFIG_EMBTK_HOST_HAVE_GDB) += gdb_host_install

# Autotools
include mk/libtool.mk
include mk/autoconf.mk
include mk/automake.mk
include mk/m4.mk
AUTOTOOLS_INSTALL	:= m4_install libtool_install autoconf_install
AUTOTOOLS_INSTALL	+= automake_install

# GNU sed
include mk/gsed.mk
__toolchain_gsed-y	:= $(if $(findstring freebsd,$(embtk_buildhost_os)),gsed_install)

# GNU make
include mk/gmake.mk
__toolchain_gmake-y	:= $(if $(findstring freebsd,$(embtk_buildhost_os)),gmake_install)

# Toolchain internals
__xtools_compiler-$(CONFIG_EMBTK_LLVM_ONLY_TOOLCHAIN)		:= clangllvm-$(LLVM_VERSION)
__xtools_compiler-$(CONFIG_EMBTK_LLVM_DEFAULT_TOOLCHAIN)	:= clangllvm-$(LLVM_VERSION)
__xtools_compiler-$(CONFIG_EMBTK_GCC_ONLY_TOOLCHAIN)		:= gcc-$(GCC_VERSION)
__xtools_compiler-$(CONFIG_EMBTK_GCC_DEFAULT_TOOLCHAIN)		:= gcc-$(GCC_VERSION)
__xtools_bins		:= $(__xtools_compiler-y)-$(embtk_clib)-$(embtk_clib_version)

TOOLCHAIN_PACKAGE	:= toolchain-$(HOST_ARCH)-target-$(__xtools_archos)-$(__xtools_bins)-$(__xtools_env).tar.bz2
TOOLCHAIN_DIR		:= $(embtk_generated)/toolchain-$(__xtools_archos)-$(__xtools_bins)-$(__xtools_env)
TOOLCHAIN_NAME		:= toolchain
TOOLCHAIN_BUILD_DIR	:= $(TOOLCHAIN_DIR)
TOOLCHAIN_SRC_DIR	:= $(TOOLCHAIN_DIR)

TOOLCHAIN_PRE_DEPS-y	:= ccache_install $(AUTOTOOLS_INSTALL)
TOOLCHAIN_PRE_DEPS-y	+= $(__toolchain_gsed-y) $(__toolchain_gmake-y)
TOOLCHAIN_PRE_DEPS-y	+= $(if $(CONFIG_EMBTK_TOOLCHAIN_PREDEP_GPERF_HOST),	\
				gperf_host_install)

__gcc3_toolchain-$(CONFIG_EMBTK_GCC_ONLY_TOOLCHAIN)		:= gcc3_install
__gcc3_toolchain-$(CONFIG_EMBTK_GCC_DEFAULT_TOOLCHAIN)		:= gcc3_install
# FIXME: When libc++ will be used with clang/llvm toolchain, remove this
__gcc3_toolchain-$(CONFIG_EMBTK_GCC_LANGUAGE_CPP)		:= gcc3_install

__gcc3_toolchain-$(CONFIG_EMBTK_GCC_LANGUAGE_OBJECTIVEC) 	:= gcc3_install
__gcc3_toolchain-$(CONFIG_EMBTK_GCC_LANGUAGE_OBJECTIVECPP)	:= gcc3_install

__llvm_toolchain-$(CONFIG_EMTK_HAVE_LLVM)			:= llvm_install

#
# Handle clang/llvm/uClibc based toolchain where linuxthread.old is used or non
# threading is used at all.
# FIXME: print a warning

ifeq ($(CONFIG_EMTK_HAVE_COMPILER-RT)$(CONFIG_KEMBTK_UCLIBC_LINUXTHREADS_OLD),yy)
else ifeq ($(CONFIG_EMTK_HAVE_COMPILER-RT)$(CONFIG_KEMBTK_UCLIBC_LINUXTHREADS_OLD),yy)
else
__llvm_compiler-rt-$(CONFIG_EMTK_HAVE_COMPILER-RT) := compiler-rt_install
endif

TOOLCHAIN_DEPS		:= linux_headers_install gmp_host_install
TOOLCHAIN_DEPS		+= mpfr_host_install mpc_host_install binutils_install
TOOLCHAIN_DEPS		+= $(__llvm_toolchain-y)
TOOLCHAIN_DEPS		+= gcc1_install $(embtk_clib)_headers_install
TOOLCHAIN_DEPS		+= gcc2_install $(embtk_clib)_install
TOOLCHAIN_DEPS		+= $(__gcc3_toolchain-y) $(__llvm_compiler-rt-y)

TOOLCHAIN_ADDONS_NAME		:= toolchain-addons
TOOLCHAIN_ADDONS_DEPS		:= $(TOOLCHAIN_ADDONS-y)
TOOLCHAIN_ADDONS_BUILD_DIR	:= $(TOOLCHAIN_BUILD_DIR)/.addons
TOOLCHAIN_ADDONS_SRC_DIR	:= $(TOOLCHAIN_BUILD_DIR)/.addons

-include mk/$(embtk_clib).mk

define __embtk_toolchain_mkinitdirs
	mkdir -p $(embtk_generated)
	mkdir -p $(TOOLCHAIN_DIR)
	mkdir -p $(TOOLCHAIN_ADDONS_BUILD_DIR)
	$(__embtk_mk_initsysrootdirs)
	$(__embtk_mk_inittoolsdirs)
	$(__embtk_mk_inithosttoolsdirs)
	$(__embtk_mk_initpkgdirs)
endef

define __embtk_toolchain_symlinktools
	cd $(embtk_tools)/bin;							\
	tools=$$(ls $(STRICT_GNU_TARGET)-*);					\
	toolsnames=$$(echo $$tools | sed 's/$(STRICT_GNU_TARGET)-*//g');	\
	for tool in $$toolsnames; do						\
		ln -sf $(STRICT_GNU_TARGET)-$$tool $(GNU_TARGET)-$$tool;	\
	done
endef

define __embtk_toolchain_compress
	tar -cjf $(TOOLCHAIN_PACKAGE)						\
		$(notdir $(embtk_sysroot)) $(notdir $(embtk_tools)) &&		\
	mv $(TOOLCHAIN_PACKAGE) $(TOOLCHAIN_DIR)/$(TOOLCHAIN_PACKAGE)
endef

define ___embtk_toolchain_decompress
	rm -rf $(embtk_sysroot) $(embtk_tools)
	cd $(EMBTK_ROOT) && tar xjf $(TOOLCHAIN_DIR)/$(TOOLCHAIN_PACKAGE)
	$(__embtk_toolchain_mkinitdirs)
	$(MAKE) $(TOOLCHAIN_PRE_DEPS-y)
endef

define __embtk_toolchain_decompress
	$(if $(call __embtk_mk_pathnotexist,$(call __embtk_pkg_dotdecompressed_f,toolchain)),
		$(call embtk_pinfo,"Decompressing cached $(GNU_TARGET)/$(EMBTK_MCU_FLAG) toolchain - please wait...")
		$(___embtk_toolchain_decompress)
		touch $(call __embtk_pkg_dotdecompressed_f,toolchain))
endef

__embtk_toolchain_deps-y	= $(patsubst %_install,%,$(TOOLCHAIN_DEPS))
__embtk_toolchain_predeps-y	= $(patsubst %_install,%,$(TOOLCHAIN_PRE_DEPS-y))
__embtk_toolchain_addons-y	= $(patsubst %_install,%,$(TOOLCHAIN_ADDONS-y))
__embtk_toolchain_addons-n	= $(patsubst %_install,%,$(TOOLCHAIN_ADDONS-))
__embtk_toolchain_built_msg	= $(call embtk_pinfo,"New $(GNU_TARGET)/$(EMBTK_MCU_FLAG) toolchain successfully built!")
__embtk_toolchain_building_msg	= $(call embtk_pinfo,"Building new $(GNU_TARGET)/$(EMBTK_MCU_FLAG) CORE toolchain - please wait...")
__embtk_toolsaddons_build_msg	= $(call embtk_pinfo,"Building new $(GNU_TARGET)/$(EMBTK_MCU_FLAG) toolchain ADDONS - please wait...")

define __embtk_toolchain_build_core
	$(__embtk_toolchain_building_msg)
	rm -rf $(call __embtk_pkg_dotinstalled_f,toolchain)
	rm -rf $(call __embtk_pkg_dotdecompressed_f,toolchain)
	$(foreach dep,$(__embtk_toolchain_deps-y),
				$(call embtk_cleanup_pkg,$(dep)))
	$(foreach pkg,$(__embtk_rootfs_pkgs-y),
				$(call embtk_cleanup_pkg,$(pkg)))
	$(foreach pkgn,$(__embtk_rootfs_pkgs-n),
				$(call embtk_cleanup_pkg,$(pkgn)))
	rm -rf $(embtk_sysroot) $(embtk_tools)
	$(__embtk_toolchain_mkinitdirs)
	$(foreach pdep,$(__embtk_toolchain_predeps-y),
				$(call embtk_install_xpkg,$(pdep)))
	$(foreach dep,$(__embtk_toolchain_deps-y),
				$(call embtk_install_xpkg,$(dep)))
	touch $(call __embtk_pkg_dotinstalled_f,toolchain)
	$(call __embtk_pkg_gen_dotkconfig_f,toolchain)
endef

define __embtk_toolchain_build_addons
	$(__embtk_toolsaddons_build_msg)
	rm -rf $(call __embtk_pkg_dotinstalled_f,toolchain_addons)
	rm -rf $(call __embtk_pkg_dotdecompressed_f,toolchain_addons)
	$(__embtk_toolchain_mkinitdirs)
	$(if $(findstring core,$(1)),,
		$(foreach rootfspkg,$(__embtk_rootfs_pkgs-y),
				$(call embtk_cleanup_pkg,$(rootfspkg)))
		$(foreach rootfsnpkg,$(__embtk_rootfs_pkgs-n),
				$(call embtk_cleanup_pkg,$(rootfsnpkg)))
		$(___embtk_toolchain_decompress))
	$(if $(findstring core,$(1)),
		$(foreach addon,$(__embtk_toolchain_addons-y),
				$(call embtk_cleanup_pkg,$(addon))))
	$(if $(TOOLCHAIN_ADDONS-),
		$(foreach addon,$(__embtk_toolchain_addons-n),
				$(call embtk_cleanup_pkg,$(addon))))
	$(if $(TOOLCHAIN_ADDONS-y),
		$(foreach pdep,$(__embtk_toolchain_predeps-y),
				$(call embtk_install_xpkg,$(pdep)))
		$(foreach addon,$(__embtk_toolchain_addons-y),
				$(call embtk_install_xpkg,$(addon))))
	touch $(call __embtk_pkg_dotinstalled_f,toolchain_addons)
	$(if $(TOOLCHAIN_ADDONS-y),
		$(call __embtk_pkg_gen_dotkconfig_f,toolchain_addons),
		touch $(call __embtk_pkg_dotkconfig_f,toolchain_addons))
endef

define __embtk_toolchain_build
	$(if $(findstring core,$(1)),$(__embtk_toolchain_build_core))
	$(if $(findstring addons,$(1)),$(__embtk_toolchain_build_addons))
	$(if $(findstring core,$(1))$(findstring addons,$(1)),
		$(__embtk_toolchain_symlinktools)
		$(call embtk_pinfo,"Packaging new $(GNU_TARGET)/$(EMBTK_MCU_FLAG) toolchain - please wait...")
		$(__embtk_toolchain_compress)
		touch $(call __embtk_pkg_dotdecompressed_f,toolchain)
		touch $(call __embtk_pkg_dotdecompressed_f,toolchain_addons)
		$(__embtk_toolchain_built_msg),
		$(__embtk_toolchain_decompress))
endef

define __embtk_toolchain_core_inst-y
	 $(and $(call __embtk_pkg_installed-y,toolchain),
		$(wildcard $(TOOLCHAIN_DIR)/$(TOOLCHAIN_PACKAGE)))
endef
__embtk_toolchain_core_inst = $(if $(strip $(__embtk_toolchain_core_inst-y)),,core)

define __embtk_toolchain_addons_inst-y
	$(and $(call __embtk_pkg_installed-y,toolchain_addons),
		$(wildcard $(TOOLCHAIN_DIR)/$(TOOLCHAIN_PACKAGE)))
endef
__embtk_toolchain_addons_inst = $(if $(strip $(__embtk_toolchain_addons_inst-y)),,addons)

__embtk_toolchain_buildargs = $(if $(__embtk_toolchain_core_inst),core-addons)
__embtk_toolchain_buildargs += $(__embtk_toolchain_addons_inst)

toolchain_install:
	$(Q)$(call __embtk_toolchain_build,$(__embtk_toolchain_buildargs))

define __embtk_toolchain_clean
	rm -rf $(call __embtk_pkg_dotdecompressed_f,toolchain)
endef

toolchain_clean:
	$(Q)$(__embtk_toolchain_clean)

pembtk_toolchain_mkinitdirs:
	$(call __embtk_toolchain_mkinitdirs)

pembtk_toolchain_predeps_install:
	$(call __embtk_toolchain_mkinitdirs)
	$(MAKE) $(TOOLCHAIN_PRE_DEPS-y)

# Download target for offline build
TOOLCHAIN_ALL_DEPS := $(TOOLCHAIN_PRE_DEPS-y) $(TOOLCHAIN_DEPS)
TOOLCHAIN_ALL_DEPS += $(TOOLCHAIN_ADDONS_DEPS)

packages_fetch:: $(patsubst %_install,download_%,$(TOOLCHAIN_ALL_DEPS))