numato-mimasv2: works fine with 6.6.x/6.9.x
[openadk.git] / toolchain / gcc / Makefile
blob8798b06d29549d714c874580b06c2fcd391fb061
1 # This file is part of the OpenADK project. OpenADK is copyrighted
2 # material, please see the LICENCE file in the top-level directory.
4 include $(ADK_TOPDIR)/rules.mk
5 include ../rules.mk
6 include Makefile.inc
8 # disable SSP for libstdc++
9 ifeq ($(ADK_TARGET_LIB_MUSL),y)
10 TARGET_CFLAGS:= $(filter-out -fstack-protector-all,$(TARGET_CFLAGS))
11 TARGET_CXXFLAGS:= $(filter-out -fstack-protector-all,$(TARGET_CXXFLAGS))
12 endif
14 # disable lto for gcc
15 TARGET_CFLAGS:= $(filter-out -flto,$(TARGET_CFLAGS))
16 TARGET_CXXFLAGS:= $(filter-out -flto,$(TARGET_CXXFLAGS))
18 # for uClinux, we need to filter out some flags
19 ifeq ($(ADK_TARGET_UCLINUX),y)
20 TARGET_CFLAGS:= $(filter-out -msep-data,$(TARGET_CFLAGS))
21 TARGET_CXXFLAGS:= $(filter-out -msep-data,$(TARGET_CXXFLAGS))
22 endif
24 # for ARM, we need to filter out some flags
25 ifeq ($(ADK_TARGET_ARCH_ARM),y)
26 TARGET_CFLAGS:= $(filter-out -mcpu=cortex-a9,$(TARGET_CFLAGS))
27 TARGET_CXXFLAGS:= $(filter-out -mcpu=cortex-a9,$(TARGET_CXXFLAGS))
28 endif
29 ifeq ($(ADK_TARGET_ARCH_ARM),y)
30 TARGET_CFLAGS:= $(filter-out -mcpu=cortex-a7,$(TARGET_CFLAGS))
31 TARGET_CXXFLAGS:= $(filter-out -mcpu=cortex-a7,$(TARGET_CXXFLAGS))
32 endif
34 ifeq ($(ADK_TARGET_ARCH_ARM),y)
35 TARGET_CFLAGS:= $(filter-out -mcpu=xscale,$(TARGET_CFLAGS))
36 TARGET_CXXFLAGS:= $(filter-out -mcpu=xscale,$(TARGET_CXXFLAGS))
37 endif
39 ifeq ($(ADK_TARGET_USE_STATIC_AND_SHARED_LIBS),y)
40 TARGET_CFLAGS:= $(filter-out -static,$(TARGET_CFLAGS))
41 TARGET_CXXFLAGS:= $(filter-out -static,$(TARGET_CXXFLAGS))
42 endif
44 GCC_CONFOPTS:= --prefix=$(TOOLCHAIN_DIR)/usr \
45 --with-bugurl="$(ADK_VENDOR_URL)" \
46 --build=$(GNU_HOST_NAME) \
47 --host=$(GNU_HOST_NAME) \
48 --target=$(GNU_TARGET_NAME) \
49 --with-gmp=$(STAGING_HOST_DIR)/usr \
50 --with-mpfr=$(STAGING_HOST_DIR)/usr \
51 --enable-__cxa_atexit \
52 --with-system-zlib \
53 --with-gnu-ld \
54 --with-gnu-as \
55 --disable-libsanitizer \
56 --disable-install-libiberty \
57 --disable-libitm \
58 --disable-libmudflap \
59 --disable-libgomp \
60 --disable-libcc1 \
61 --disable-libmpx \
62 --disable-libcilkrts \
63 --disable-libquadmath \
64 --disable-libquadmath-support \
65 --disable-decimal-float \
66 --disable-gcov \
67 --disable-libstdcxx-pch \
68 --disable-ppl-version-check \
69 --disable-cloog-version-check \
70 --without-ppl \
71 --without-cloog \
72 --without-isl \
73 --disable-werror \
74 --disable-nls \
75 --enable-obsolete
77 ifeq ($(ADK_TARGET_OS_LINUX),y)
78 ifeq ($(ADK_TARGET_LIB_UCLIBC_NG),y)
79 ifeq ($(ADK_TARGET_WITH_NPTL),y)
80 GCC_FINAL_CONFOPTS:= --enable-tls --enable-threads --enable-libatomic
81 GCC_TLS_CONFOPTS:= --enable-tls
82 endif
83 ifeq ($(ADK_TARGET_WITH_LT),y)
84 GCC_FINAL_CONFOPTS:= --disable-tls --enable-threads --disable-libatomic
85 GCC_TLS_CONFOPTS:= --disable-tls
86 endif
87 ifeq ($(ADK_TARGET_LIB_WITHOUT_THREADS)$(ADK_TARGET_WITHOUT_THREADS),y)
88 GCC_FINAL_CONFOPTS:= --disable-tls --disable-threads --disable-libatomic
89 GCC_TLS_CONFOPTS:= --disable-tls
90 endif
91 else
92 GCC_FINAL_CONFOPTS:= --enable-tls --enable-threads --enable-libatomic
93 GCC_TLS_CONFOPTS:= --enable-tls
94 endif
95 endif
97 ifeq ($(ADK_TARGET_OS_BAREMETAL),y)
98 GCC_FINAL_CONFOPTS:= --disable-libatomic
99 endif
101 ifeq ($(ADK_TARGET_LIB_NEWLIB),y)
102 GCC_FINAL_CONFOPTS+= --with-newlib
103 endif
105 ifeq ($(ADK_TARGET_USE_STATIC_LIBS_ONLY),y)
106 GCC_FINAL_CONFOPTS+= --disable-shared
107 else
108 GCC_FINAL_CONFOPTS+= --enable-shared --enable-cxx-flags='-fPIC'
109 endif
111 ifeq ($(ADK_TOOLCHAIN_WITH_SSP),y)
112 GCC_FINAL_CONFOPTS+= --enable-libssp
113 else
114 GCC_FINAL_CONFOPTS+= --disable-libssp
115 endif
117 ifeq ($(ADK_TOOLCHAIN_WITH_LTO),y)
118 GCC_CONFOPTS+= --enable-lto
119 else
120 GCC_CONFOPTS+= --disable-lto
121 endif
124 # architecture specific
126 ifneq ($(ADK_TARGET_GCC_CPU),)
127 GCC_CONFOPTS+= --with-cpu=$(ADK_TARGET_GCC_CPU)
128 endif
130 ifneq ($(ADK_TARGET_GCC_ARCH),)
131 GCC_CONFOPTS+= --with-arch=$(ADK_TARGET_GCC_ARCH)
132 endif
134 ifneq ($(ADK_TARGET_FLOAT),)
135 GCC_CONFOPTS+= --with-float=$(ADK_TARGET_FLOAT)
136 endif
138 ifneq ($(ADK_TARGET_FPU),)
139 GCC_CONFOPTS+= --with-fpu=$(ADK_TARGET_FPU)
140 endif
142 ifneq ($(ADK_TARGET_INSTRUCTION_SET),)
143 GCC_CONFOPTS+= --with-mode=$(ADK_TARGET_INSTRUCTION_SET)
144 endif
146 ifneq ($(ADK_TARGET_NAN_MODE),)
147 GCC_CONFOPTS+= --with-nan=$(ADK_TARGET_NAN_MODE)
148 endif
150 # .symver is broken for Blackfin, simple C++ apps fail to link
151 ifeq ($(ADK_TARGET_ARCH_BFIN),y)
152 GCC_CONFOPTS+= --disable-symvers
153 endif
155 ifeq ($(ADK_TARGET_ARCH_CSKY),y)
156 GCC_CONFOPTS+= --with-cskyabi=abiv2 --disable-multilib
157 ifeq ($(ADK_TARGET_LITTLE_ENDIAN),y)
158 GCC_CONFOPTS+= --with-endian=little
159 else
160 GCC_CONFOPTS+= --with-endian=big
161 endif
162 endif
164 ifeq ($(ADK_TARGET_ARCH_METAG),y)
165 GCC_CONFOPTS+= --with-cpu=2.1 --enable-meta-default --disable-symvers
166 endif
168 ifeq ($(ADK_TARGET_ARCH_NDS32),y)
169 GCC_CONFOPTS+= --with-arch=v3
170 endif
172 ifeq ($(ADK_TARGET_ARCH_M68K)$(ADK_TARGET_ARCH_X86_64)$(ADK_TARGET_ARCH_X86),)
173 GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
174 endif
176 ifeq ($(ADK_TARGET_CPU_CF),y)
177 GCC_CONFOPTS+= --with-arch=cf
178 GCC_INITIAL_CONFOPTS+= --enable-multilib
179 ifeq ($(ADK_TARGET_BINFMT_ELF)$(ADK_TARGET_WITH_MMU),y)
180 GCC_FINAL_CONFOPTS+= --disable-multilib --disable-threads --disable-libatomic
181 endif
182 else
183 GCC_INITIAL_CONFOPTS+= --disable-multilib
184 endif
186 ifeq ($(ADK_TARGET_ARCH_SH),y)
188 ifeq ($(ADK_TARGET_LITTLE_ENDIAN),y)
189 GCC_CONFOPTS+= --with-endian=little
190 else
191 GCC_CONFOPTS+= --with-endian=big
192 endif
193 ifeq ($(ADK_TARGET_BINFMT_FDPIC),y)
194 GCC_CONFOPTS+= --enable-fdpic
195 endif
197 ifeq ($(ADK_TARGET_CPU_SH_J2),y)
198 GCC_CONFOPTS+= --with-multilib-list=mj2
199 endif
200 ifeq ($(ADK_TARGET_CPU_SH_SH2),y)
201 GCC_CONFOPTS+= --with-multilib-list=m2
202 endif
203 ifeq ($(ADK_TARGET_CPU_SH_SH2A),y)
204 GCC_CONFOPTS+= --with-multilib-list=m2a,m2a-nofpu
205 endif
206 ifeq ($(ADK_TARGET_CPU_SH_SH3),y)
207 GCC_CONFOPTS+= --with-multilib-list=m3
208 endif
209 ifeq ($(ADK_TARGET_CPU_SH_SH4),y)
210 GCC_CONFOPTS+= --with-multilib-list=m4,m4-nofpu
211 endif
212 ifeq ($(ADK_TARGET_CPU_SH_SH4A),y)
213 GCC_CONFOPTS+= --with-multilib-list=m4a,m4a-nofpu
214 endif
216 endif
218 ifeq ($(ADK_TARGET_ARCH_X86),y)
219 ifeq ($(ADK_TARGET_KERNEL_64),y)
220 GCC_FINAL_CONFOPTS+= --enable-biarch --enable-targets=all --disable-multilib
221 else
222 GCC_FINAL_CONFOPTS+= --disable-biarch --disable-multilib
223 endif
224 endif
226 ifeq ($(ADK_TARGET_ARCH_X86_64),y)
227 ifneq ($(ADK_TARGET_ABI_X32),)
228 GCC_CONFOPTS+= --with-abi=x32 --enable-multilib
229 else
230 GCC_CONFOPTS+= --disable-biarch --disable-multilib
231 endif
232 endif
234 ifeq ($(ADK_TARGET_ARCH_ALPHA),y)
235 GCC_CONFOPTS+= --without-long-double-128
236 endif
238 ifeq ($(ADK_TARGET_ARCH_PPC),y)
239 GCC_CONFOPTS+= --with-long-double-64 --enable-secureplt
240 endif
242 ifeq ($(ADK_TARGET_ARCH_PPC64),y)
243 ifeq ($(ADK_TARGET_LIB_GLIBC),y)
244 GCC_CONFOPTS+= --with-long-double-128 --with-abi=elfv2
245 else
246 GCC_CONFOPTS+= --without-long-double-128 --with-abi=elfv2
247 endif
248 endif
250 ifeq ($(ADK_TARGET_ARCH_S390),y)
251 GCC_CONFOPTS+= --with-long-double-128
252 endif
254 ifneq ($(ADK_TARGET_ABI_MIPS64),)
255 GCC_CONFOPTS+= --with-abi=${ADK_TARGET_ABI_MIPS64}
256 endif
258 ifneq ($(ADK_TARGET_ABI_RISCV),)
259 GCC_CONFOPTS+= --with-abi=${ADK_TARGET_ABI_RISCV}
260 endif
262 ifeq ($(ADK_TOOLCHAIN_GCC_NDS32),y)
263 EXTRA_CXXFLAGS:= --std=c++03
264 endif
266 ifeq (${ADK_MAKE_PARALLEL},y)
267 GCC_MAKEOPTS+= -j${ADK_MAKE_JOBS}
268 endif
270 USE_LANG:=c
271 ifeq ($(ADK_TOOLCHAIN_WITH_CXX),y)
272 USE_LANG+=c++
273 endif
274 ifeq ($(ADK_TOOLCHAIN_WITH_OBJC),y)
275 USE_LANG+=objc
276 endif
277 ifeq ($(ADK_TOOLCHAIN_WITH_FORTRAN),y)
278 USE_LANG+=fortran
279 endif
280 ifeq ($(ADK_TOOLCHAIN_WITH_GO),y)
281 USE_LANG+=go
282 endif
284 LANGUAGES=$(shell echo ${USE_LANG} |tr ' ' ',')
286 include ${ADK_TOPDIR}/mk/buildhlp.mk
288 GCC_BUILD_DIR_INITIAL:= $(WRKBUILD)-initial
289 GCC_BUILD_DIR_FINAL:= $(WRKBUILD)-final
291 $(GCC_BUILD_DIR_INITIAL)/.configured:
292 ifeq ($(ADK_TARGET_ARCH_XTENSA),y)
293 ifeq ($(ADK_TARGET_ABI),)
294 tar xf $(ADK_TOPDIR)/target/xtensa/overlay/xtensa_$(ADK_TARGET_CPU_TYPE).tar \
295 --strip-components=1 -C $(WRKSRC) gcc
296 else
297 tar xf $(ADK_TOPDIR)/target/xtensa/overlay/xtensa_$(ADK_TARGET_CPU_TYPE)_$(ADK_TARGET_ABI).tar \
298 --strip-components=1 -C $(WRKSRC) gcc
299 endif
300 endif
301 mkdir -p $(GCC_BUILD_DIR_INITIAL)
302 # these symlinks are very important, do not remove
303 rm -rf $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/sys-include
304 mkdir -p $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)
305 (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
306 ln -s ../$(STAGING_HOST2TARGET)/usr/include sys-include)
307 rm -rf ${TOOLCHAIN_DIR}/usr/$(GNU_TARGET_NAME)/lib
308 (cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME); \
309 ln -s ../$(STAGING_HOST2TARGET)/usr/lib lib)
310 ifeq ($(ADK_TARGET_ARCH_SH),y)
311 ifeq ($(ADK_TARGET_CPU_SH_SH2),y)
312 (cd ${STAGING_TARGET_DIR}/ && ln -sf . m2)
313 endif
314 ifeq ($(ADK_TARGET_CPU_SH_SH2A),y)
315 (cd ${STAGING_TARGET_DIR}/ && ln -sf . m2a)
316 endif
317 ifeq ($(ADK_TARGET_CPU_SH_SH3),y)
318 (cd ${STAGING_TARGET_DIR}/ && ln -sf . m3)
319 endif
320 ifeq ($(ADK_TARGET_CPU_SH_SH4),y)
321 (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4)
322 endif
323 ifeq ($(ADK_TARGET_CPU_SH_SH4A),y)
324 (cd ${STAGING_TARGET_DIR}/ && ln -sf . m4a)
325 endif
326 endif
327 ifeq ($(ADK_TARGET_ARCH_M68K),y)
328 # Need to get gcc to generate _all_ the multilib variants
329 # (so both MMU and non-mmu M68k and ColdFire).
330 $(SED) 's/M68K_MLIB_CPU +=/#M68K_MLIB_CPU +=/' $(WRKBUILD)/gcc/config/m68k/t-m68k
331 $(SED) 's/&& (FLAGS ~ "FL_MMU")//' $(WRKBUILD)/gcc/config/m68k/t-linux
332 endif
333 $(SED) '/k prot/agcc_cv_libc_provides_ssp=yes' $(WRKBUILD)/gcc/configure
334 cd $(GCC_BUILD_DIR_INITIAL); \
335 PATH='$(TARGET_PATH)' \
336 CC='$(HOST_CC)' \
337 CXX='$(HOST_CXX)' \
338 CFLAGS="-O0 -g0 -fomit-frame-pointer" \
339 CXXFLAGS="-O0 -g0 -fomit-frame-pointer $(EXTRA_CXXFLAGS)" \
340 $(WRKBUILD)/configure \
341 ${GCC_INITIAL_CONFOPTS} \
342 ${GCC_CONFOPTS} \
343 ${GCC_TLS_CONFOPTS} \
344 --enable-languages=c \
345 --with-newlib \
346 --disable-shared \
347 --disable-threads \
348 --without-headers
349 touch $@
351 $(GCC_BUILD_DIR_INITIAL)/.compiled: $(GCC_BUILD_DIR_INITIAL)/.configured
352 ifeq ($(ADK_TOOLCHAIN_GCC_METAG),y)
353 PATH='$(TARGET_PATH)' \
354 $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc
355 else
356 PATH='$(TARGET_PATH)' \
357 $(MAKE) ${GCC_MAKEOPTS} -C $(GCC_BUILD_DIR_INITIAL) all-gcc all-target-libgcc
358 endif
359 touch $@
361 $(WRKBUILD)/.configured: $(GCC_BUILD_DIR_INITIAL)/.compiled
362 ifeq ($(ADK_TOOLCHAIN_GCC_METAG),y)
363 PATH='$(TARGET_PATH)' \
364 $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc
365 else
366 PATH='$(TARGET_PATH)' \
367 $(MAKE) -C $(GCC_BUILD_DIR_INITIAL) install-gcc install-target-libgcc
368 endif
369 # required for newlib
370 (cd $(TOOLCHAIN_DIR)/usr/bin && \
371 ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-cc \
373 touch $@
375 $(WRKBUILD)/.compiled:
376 mkdir -p $(GCC_BUILD_DIR_FINAL)
377 cd $(GCC_BUILD_DIR_FINAL); \
378 PATH='$(TARGET_PATH)' \
379 CC='$(HOST_CC)' \
380 CXX='$(HOST_CXX) $(EXTRA_CXXFLAGS)' \
381 CFLAGS_FOR_TARGET='$(TARGET_CFLAGS)' \
382 CXXFLAGS_FOR_TARGET='$(TARGET_CXXFLAGS)' \
383 $(WRKBUILD)/configure \
384 ${GCC_CONFOPTS} \
385 ${GCC_FINAL_CONFOPTS} \
386 --enable-languages=$(LANGUAGES) \
387 --with-build-sysroot='$${prefix}/${STAGING_HOST2TARGET}' \
388 --with-sysroot='$${prefix}/${STAGING_HOST2TARGET}'
389 PATH='$(TARGET_PATH)' $(MAKE) -C $(GCC_BUILD_DIR_FINAL) configure-host
390 cd $(GCC_BUILD_DIR_FINAL); \
391 PATH='$(TARGET_PATH)' \
392 $(MAKE) ${GCC_MAKEOPTS} all
393 touch $@
395 $(WRKBUILD)/.installed: $(WRKBUILD)/.compiled
396 cd $(GCC_BUILD_DIR_FINAL); \
397 PATH='$(TARGET_PATH)' \
398 $(MAKE) install
399 # remove duplicate tools, convert hardlinks to symlinks
400 set -e; \
401 cd $(TOOLCHAIN_DIR)/usr/$(GNU_TARGET_NAME)/bin; \
402 for app in ar as c++ g++ gcc ld ld.gold ld.bfd nm objcopy objdump ranlib strip; do \
403 ln -sf ../../bin/$(GNU_TARGET_NAME)-$${app} $${app}; \
404 done;
405 (cd $(TOOLCHAIN_DIR)/usr/bin && \
406 ln -sf $(GNU_TARGET_NAME)-gcc $(GNU_TARGET_NAME)-gcc-${PKG_VERSION} && \
407 ln -sf $(GNU_TARGET_NAME)-g++ $(GNU_TARGET_NAME)-g++-${PKG_VERSION} \
409 touch $@
411 $(WRKBUILD)/.final:
412 ifeq ($(ADK_TARGET_CPU_CF),y)
413 find $(STAGING_TARGET_DIR) -name libgcc.a -print | while read t; do $(GNU_TARGET_NAME)-ar dv "$t" _ctors.o; done
414 endif
415 # cleanup unneeded docs
416 rm -rf $(TOOLCHAIN_DIR)/usr/share
417 # cleanup unneeded libtool files
418 -find $(STAGING_TARGET_DIR) $(STAGING_HOST_DIR) -name \*.la -exec rm {} \;
419 # strip target libs and host tools for toolchain builds in non-Debug mode
420 ifeq ($(ADK_DEBUG),)
421 PATH="$(TARGET_PATH)" debug='0' prefix='${TARGET_CROSS}' ${BASH} ${SCRIPT_DIR}/rstrip.sh \
422 $(STAGING_TARGET_DIR) $(TOOLCHAIN_DIR)/usr/lib/gcc/$(GNU_TARGET_NAME)
423 debug='0' prefix=' ' ${BASH} ${SCRIPT_DIR}/rstrip.sh $(TOOLCHAIN_DIR)/usr/bin
424 endif
425 touch $@
427 include ${ADK_TOPDIR}/mk/toolchain.mk