2 # This helper is for void system crosstoolchain templates.
6 # - cross_gcc_skip_go - do not build gccgo support
7 # - cross_binutils_configure_args
8 # - cross_gcc_bootstrap_configure_args
9 # - cross_gcc_configure_args
10 # - cross_glibc_cflags
11 # - cross_glibc_ldflags
12 # - cross_glibc_configure_args
14 # - cross_musl_ldflags
15 # - cross_musl_configure_args
17 # configure_args is passed to both bootstrap gcc and final gcc
18 # if you need to pass some to one and not the other, use the
19 # respective cross_ variables for final gcc and bootstrap gcc
22 _void_cross_apply_patch
() {
23 local pname
="$(basename $1)"
24 if [ ! -f ".${pname}_done" ]; then
25 patch -Np1 $args -i $1
30 _void_cross_build_binutils
() {
31 [ -f ${wrksrc}/.binutils_done
] && return 0
36 msg_normal
"Patching binutils for ${tgt}\n"
38 cd ${wrksrc}/binutils-
${ver}
39 if [ -d "${XBPS_SRCPKGDIR}/binutils/patches" ]; then
40 for f
in ${XBPS_SRCPKGDIR}/binutils
/patches
/*.
patch; do
41 _void_cross_apply_patch
"$f"
46 msg_normal
"Building binutils for ${tgt}\n"
48 mkdir
-p ${wrksrc}/binutils_build
49 cd ${wrksrc}/binutils_build
51 ..
/binutils-
${ver}/configure \
55 --libexecdir=/usr
/lib \
58 --with-sysroot=/usr
/${tgt} \
69 --enable-deterministic-archives \
70 --enable-default-hash-style=gnu \
74 ${cross_binutils_configure_args}
79 make install DESTDIR
=${wrksrc}/build_root
81 touch ${wrksrc}/.binutils_done
84 _void_cross_build_bootstrap_gcc
() {
85 [ -f ${wrksrc}/.gcc_bootstrap_done
] && return 0
90 msg_normal
"Patching GCC for ${tgt}\n"
92 cd ${wrksrc}/gcc-
${ver}
94 # Do not run fixincludes
95 sed -i 's@./fixinc.sh@-c true@' Makefile.
in
97 for f
in ${XBPS_SRCPKGDIR}/gcc
/patches
/*.
patch; do
98 _void_cross_apply_patch
"$f"
100 if [ -f ${wrksrc}/.musl_version
]; then
101 for f
in ${XBPS_SRCPKGDIR}/gcc
/files
/*-musl.
patch; do
102 _void_cross_apply_patch
"$f"
107 msg_normal
"Building bootstrap GCC for ${tgt}\n"
109 mkdir
-p gcc_bootstrap
113 if [ -f ${wrksrc}/.musl_version
]; then
114 extra_args
+=" --with-newlib"
115 extra_args
+=" --disable-symvers"
116 extra_args
+=" libat_cv_have_ifunc=no"
118 extra_args
+=" --without-headers"
121 ..
/gcc-
${ver}/configure \
125 --libexecdir=/usr
/lib \
130 --disable-libquadmath \
131 --disable-decimal-float \
134 --disable-libmudflap \
137 --disable-libatomic --disable-autolink-libatomic \
140 --disable-sjlj-exceptions \
141 --enable-languages=c \
146 ${cross_gcc_bootstrap_configure_args}
149 make install DESTDIR
=${wrksrc}/build_root
151 local ptrs
=$
(${tgt}-gcc -dM -E - < /dev
/null | \
152 grep __SIZEOF_POINTER__
)
156 8) echo 64 > ${wrksrc}/.gcc_wordsize
;;
157 4) echo 32 > ${wrksrc}/.gcc_wordsize
;;
158 *) msg_error
"Unknown word size: ${ws}\n" ;;
161 touch ${wrksrc}/.gcc_bootstrap_done
164 _void_cross_build_kernel_headers
() {
165 [ -f ${wrksrc}/.linux_headers_done
] && return 0
171 msg_normal
"Patching Linux headers for ${tgt}\n"
173 cd ${wrksrc}/linux-
${ver}
174 if [ -d "${XBPS_SRCPKGDIR}/kernel-libc-headers/patches" ]; then
175 for f
in ${XBPS_SRCPKGDIR}/kernel-libc-headers
/patches
/*.
patch; do
176 _void_cross_apply_patch
"$f"
181 msg_normal
"Building Linux headers for ${tgt}\n"
186 x86_64
*|i686
*) arch
=x86
;;
187 powerpc
*) arch
=powerpc
;;
189 aarch64
*) arch
=arm64
;;
191 riscv
*) arch
=riscv
;;
193 *) msg_error
"Unknown Linux arch for ${tgt}\n" ;;
196 make ARCH
=${arch} headers
197 find usr
/include
-name '.*' -delete
198 rm usr
/include
/Makefile
199 rm -r usr
/include
/drm
200 cp -a usr
/include
${wrksrc}/build_root
/usr
/${tgt}/usr
202 touch ${wrksrc}/.linux_headers_done
205 _void_cross_build_glibc_headers
() {
206 [ -f ${wrksrc}/.glibc_headers_done
] && return 0
211 msg_normal
"Patching glibc for ${tgt}\n"
213 cd ${wrksrc}/glibc-
${ver}
214 if [ -d "${XBPS_SRCPKGDIR}/glibc/patches" ]; then
215 for f
in ${XBPS_SRCPKGDIR}/glibc
/patches
/*.
patch; do
216 _void_cross_apply_patch
"$f"
221 msg_normal
"Building glibc headers for ${tgt}\n"
223 mkdir
-p glibc_headers
226 echo "libc_cv_forced_unwind=yes" > config.cache
227 echo "libc_cv_c_cleanup=yes" >> config.cache
229 # we don't need any custom args here, it's just headers
230 CC
="${tgt}-gcc" CXX="${tgt}-g++" CPP="${tgt}-cpp" LD="${tgt}-ld" \
231 AS
="${tgt}-as" NM
="${tgt}-nm" CFLAGS
="-pipe" CXXFLAGS
="" CPPFLAGS
="" \
233 ..
/glibc-
${ver}/configure \
236 --with-headers=${wrksrc}/build_root
/usr
/${tgt}/usr
/include \
238 --enable-kernel=2.6.27 \
239 ${cross_glibc_configure_args}
241 make -k install-headers cross_compiling
=yes \
242 install_root
=${wrksrc}/build_root
/usr
/${tgt}
244 touch ${wrksrc}/.glibc_headers_done
247 _void_cross_build_glibc
() {
248 [ -f ${wrksrc}/.glibc_build_done
] && return 0
253 msg_normal
"Building glibc for ${tgt}\n"
255 mkdir
-p ${wrksrc}/glibc_build
256 cd ${wrksrc}/glibc_build
258 local ws
=$
(cat ${wrksrc}/.gcc_wordsize
)
260 echo "slibdir=/usr/lib${ws}" > configparms
262 echo "libc_cv_forced_unwind=yes" > config.cache
263 echo "libc_cv_c_cleanup=yes" >> config.cache
265 CC
="${tgt}-gcc" CXX="${tgt}-g++" CPP="${tgt}-cpp" LD="${tgt}-ld" \
266 AR
="${tgt}-ar" AS="${tgt}-as" NM="${tgt}-nm" \
267 OBJDUMP
="${tgt}-objdump" OBJCOPY
="${tgt}-objcopy" \
268 CFLAGS
="-pipe ${cross_glibc_cflags}" \
269 CXXFLAGS
="-pipe ${cross_glibc_cflags}" \
271 LDFLAGS
="${cross_glibc_ldflags}" \
272 ..
/glibc-
${ver}/configure \
274 --libdir=/usr
/lib
${ws} \
275 --libexecdir=/usr
/libexec \
277 --with-headers=${wrksrc}/build_root
/usr
/${tgt}/usr
/include \
281 --enable-kernel=2.6.27 \
282 ${cross_glibc_configure_args}
285 make install_root
=${wrksrc}/build_root
/usr
/${tgt} install
287 touch ${wrksrc}/.glibc_build_done
290 _void_cross_build_musl
() {
291 [ -f ${wrksrc}/.musl_build_done
] && return 0
296 msg_normal
"Patching musl for ${tgt}\n"
298 cd ${wrksrc}/musl-
${ver}
299 if [ -d "${XBPS_SRCPKGDIR}/musl/patches" ]; then
300 for f
in ${XBPS_SRCPKGDIR}/musl
/patches
/*.
patch; do
301 _void_cross_apply_patch
"$f"
306 msg_normal
"Building musl for ${tgt}\n"
311 CC
="${tgt}-gcc" CXX="${tgt}-g++" CPP="${tgt}-cpp" LD="${tgt}-ld" \
312 AR
="${tgt}-ar" AS="${tgt}-as" NM="${tgt}-nm" \
313 CFLAGS
="-pipe -fPIC ${cross_musl_cflags}" \
314 CPPFLAGS
="${cross_musl_cflags}" LDFLAGS
="${cross_musl_ldflags}" \
315 ..
/musl-
${ver}/configure \
318 ${cross_musl_configure_args}
321 make DESTDIR
=${wrksrc}/build_root
/usr
/${tgt} install
323 CFLAGS
="-pipe -fPIC ${cross_musl_cflags}" \
324 CPPFLAGS
="${cross_musl_cflags}" LDFLAGS
="${cross_musl_ldflags}" \
325 ${tgt}-gcc -pipe -fPIC ${cross_musl_cflags} ${cross_musl_ldflags} -fpie \
326 -c ${XBPS_SRCPKGDIR}/musl
/files
/__stack_chk_fail_local.c \
327 -o __stack_chk_fail_local.o
328 ${tgt}-ar r libssp_nonshared.a __stack_chk_fail_local.o
329 cp libssp_nonshared.a
${wrksrc}/build_root
/usr
/${tgt}/usr
/lib
331 touch ${wrksrc}/.musl_build_done
334 _void_cross_build_libucontext
() {
335 [ -n "$cross_gcc_skip_go" ] && return 0
336 [ -f ${wrksrc}/.libucontext_build_done
] && return 0
342 msg_normal
"Building libucontext for ${tgt}\n"
345 x86_64
*) arch
=x86_64
;;
347 powerpc64
*) arch
=ppc64
;;
348 powerpc
*) arch
=ppc
;;
349 mips
*64*) arch
=mips64
;;
351 aarch64
*) arch
=aarch64
;;
353 riscv64
*) arch
=riscv64
;;
354 s390x
*) arch
=s390x
;;
355 *) msg_error
"Unknown libucontext arch for ${tgt}\n" ;;
358 cd ${wrksrc}/libucontext-
${ver}
359 # a terrible hack but seems to work for now
360 # we build a static-only library to prevent linking to a runtime
361 # since it's tiny it can be linked into libgo and we don't have
362 # to keep it around (which would possibly conflict with crossdeps)
363 incpath
="${wrksrc}/build_root/usr/${tgt}/usr/include"
364 CC
="${tgt}-gcc" AS="${tgt}-as" AR="${tgt}-ar" \
365 make ARCH
=$arch libucontext.a \
366 CFLAGS
="${cross_musl_cflags} -g0 -nostdinc -isystem ${incpath}"
368 cp libucontext.a
${wrksrc}/build_root
/usr
/${tgt}/usr
/lib
370 touch ${wrksrc}/.libucontext_build_done
373 _void_cross_build_gcc
() {
374 [ -f ${wrksrc}/.gcc_build_done
] && return 0
379 msg_normal
"Building gcc for ${tgt}\n"
381 # GIANT HACK: create an empty libatomic.a so gcc cross-compile
383 ar r
${wrksrc}/build_root
/usr
/${tgt}/usr
/lib
/libatomic.a
385 mkdir
-p ${wrksrc}/gcc_build
386 cd ${wrksrc}/gcc_build
388 local langs
="c,c++,fortran,objc,obj-c++,ada,lto"
389 if [ -z "$cross_gcc_skip_go" ]; then
394 if [ -f ${wrksrc}/.musl_version
]; then
395 # otherwise glibc hosts get confused and use the gnu impl
396 extra_args
+=" --enable-clocale=generic"
397 extra_args
+=" --disable-symvers"
398 extra_args
+=" --disable-gnu-unique-object"
399 extra_args
+=" libat_cv_have_ifunc=no"
401 extra_args
+=" --enable-clocale=gnu"
402 extra_args
+=" --enable-gnu-unique-object"
405 # note on --disable-libquadmath:
406 # on some platforms the library is actually necessary for the
407 # fortran frontend to build, platforms where this is a problem
408 # should explicitly force libquadmath to be on via cross_gcc_configure_args
410 ..
/gcc-
${ver}/configure \
414 --libexecdir=/usr
/lib \
416 --with-sysroot=/usr
/${tgt} \
417 --with-build-sysroot=${wrksrc}/build_root
/usr
/${tgt} \
418 --enable-languages=${langs} \
421 --disable-sjlj-exceptions \
422 --disable-libquadmath \
423 --disable-libmudflap \
426 --disable-libsanitizer \
427 --disable-libstdcxx-pch \
430 --enable-threads=posix \
431 --enable-__cxa_atexit \
432 --enable-linker-build-id \
435 --enable-default-pie \
436 --enable-default-ssp \
439 --with-linker-hash-style=gnu \
442 ${cross_gcc_configure_args}
446 touch ${wrksrc}/.gcc_build_done
449 _void_cross_test_ver
() {
453 for p
in ${proj}-*; do
455 if [ -z "$noerr" -a -n "$ver" ]; then
456 msg_error
"multiple versions of ${proj} found: ${ver}, ${cver}"
460 if [ -d "${proj}-${ver}" ]; then
461 echo ${ver} > ${wrksrc}/.${proj}_version
464 if [ -z "$noerr" ]; then
465 msg_error
"project ${proj} not available for build\n"
470 # Verify toolchain versions
473 local binutils_ver linux_ver gcc_ver libc_ver libucontext_ver
474 local tgt
=${sourcepkg/cross-}
476 export CFLAGS
="${CFLAGS/-D_FORTIFY_SOURCE=2/}"
477 export CXXFLAGS
="${CXXFLAGS/-D_FORTIFY_SOURCE=2/}"
479 # Disable explicit -fno-PIE, gcc/binutils/libc will figure this out itself.
480 export CFLAGS
="${CFLAGS//-fno-PIE/}"
481 export CXXFLAGS
="${CXXFLAGS//-fno-PIE/}"
482 export LDFLAGS
="${LDFLAGS//-no-pie/}"
484 _void_cross_test_ver binutils
485 _void_cross_test_ver linux
486 _void_cross_test_ver gcc
488 binutils_ver
=$
(cat .binutils_version
)
489 linux_ver
=$
(cat .linux_version
)
490 gcc_ver
=$
(cat .gcc_version
)
492 _void_cross_test_ver musl noerr
493 if [ ! -f .musl_version
]; then
494 _void_cross_test_ver glibc
495 libc_ver
=$
(cat .glibc_version
)
497 libc_ver
=$
(cat .musl_version
)
498 if [ -z "$cross_gcc_skip_go" ]; then
499 _void_cross_test_ver libucontext
500 libucontext_ver
=$
(cat .libucontext_version
)
504 local sysroot
="/usr/${tgt}"
506 # Prepare environment
509 # Core directories for the build root
510 mkdir
-p build_root
/usr
/{bin
,lib
,include
,share
}
511 mkdir
-p build_root
/usr
/${tgt}/usr
/{bin
,lib
,include
,share
}
513 # Host root uses host wordsize
514 ln -sf usr
/lib build_root
/lib
515 ln -sf usr
/lib build_root
/lib
${XBPS_TARGET_WORDSIZE}
516 ln -sf lib build_root
/usr
/lib
${XBPS_TARGET_WORDSIZE}
518 # Prepare target sysroot
519 ln -sf usr
/lib build_root
/${sysroot}/lib
520 ln -sf lib build_root
/${sysroot}/usr
/libexec
522 _void_cross_build_binutils
${tgt} ${binutils_ver}
524 # Prepare environment so we can use temporary prefix
525 local oldpath
="$PATH"
526 local oldldlib
="$LD_LIBRARY_PATH"
528 export PATH
="${wrksrc}/build_root/usr/bin:$PATH"
529 export LD_LIBRARY_PATH
="${wrksrc}/build_root/usr/lib:$PATH"
531 _void_cross_build_bootstrap_gcc
${tgt} ${gcc_ver}
532 _void_cross_build_kernel_headers
${tgt} ${linux_ver}
534 local ws
=$
(cat ${wrksrc}/.gcc_wordsize
)
536 # Now that we know the target wordsize, prepare symlinks
537 ln -sf usr
/lib
${wrksrc}/build_root/${sysroot}/lib${ws}
538 ln -sf lib
${wrksrc}/build_root/${sysroot}/usr/lib${ws}
540 if [ -f ${wrksrc}/.musl_version
]; then
541 _void_cross_build_musl
${tgt} ${libc_ver}
542 _void_cross_build_libucontext
${tgt} ${libucontext_ver}
544 _void_cross_build_glibc_headers
${tgt} ${libc_ver}
545 _void_cross_build_glibc
${tgt} ${libc_ver}
548 _void_cross_build_gcc
${tgt} ${gcc_ver}
550 # restore this stuff in case later hooks depend on it
551 export PATH
="$oldpath"
552 export LD_LIBRARY_PATH
="$oldldlib"
556 # We need to be able to access binutils in the root
557 local oldpath
="$PATH"
558 local oldldlib
="$LD_LIBRARY_PATH"
559 export PATH
="${wrksrc}/build_root/usr/bin:$PATH"
560 export LD_LIBRARY_PATH
="${wrksrc}/build_root/usr/lib:$PATH"
562 local tgt
=${sourcepkg/cross-}
563 local sysroot
="/usr/${tgt}"
564 local ws
=$
(cat ${wrksrc}/.gcc_wordsize
)
566 # Core directories for the sysroot
568 # libexec is created for sysroot but not for dest, since in sysroot
569 # we configure glibc with separate libexec, elsewhere it's just lib
570 # and we want to delete the libexec from glibc afterwards to save space
571 mkdir
-p ${DESTDIR}/${sysroot}/usr/{bin,lib,libexec,include,share}
572 # Sysroot base symlinks
573 ln -sf usr
/bin
${DESTDIR}/${sysroot}/bin
574 ln -sf usr
/lib
${DESTDIR}/${sysroot}/lib
575 ln -sf usr
/lib
${DESTDIR}/${sysroot}/lib${ws}
576 ln -sf lib
${DESTDIR}/${sysroot}/usr/lib${ws}
577 ln -sf usr
/include
${DESTDIR}/${sysroot}/include
579 # Install Linux headers
580 cd ${wrksrc}/linux-$
(cat ${wrksrc}/.linux_version
)
581 cp -a usr
/include
${DESTDIR}/${sysroot}/usr
584 cd ${wrksrc}/binutils_build
585 make install DESTDIR
=${DESTDIR}
588 cd ${wrksrc}/gcc_build
589 make install DESTDIR
=${DESTDIR}
591 # Move libcc1.so* to the sysroot
592 mv ${DESTDIR}/usr/lib/libcc1.so* ${DESTDIR}/${sysroot}/usr
/lib
594 local gcc_ver
=$
(cat ${wrksrc}/.gcc_version
)
595 local gcc_patch
=${gcc_ver/_*}
596 local gcc_minor
=${gcc_patch%.*}
597 local gcc_major
=${gcc_minor%.*}
599 if [ -f ${wrksrc}/.musl_version
]; then
601 cd ${wrksrc}/musl_build
602 make DESTDIR
=${DESTDIR}/${sysroot} install
604 # Remove useless headers
605 rm -rf ${DESTDIR}/usr
/lib
/gcc
/${tgt}/*/include-fixed
607 # Make ld-musl.so symlinks relative
608 for f
in ${DESTDIR}/${sysroot}/usr
/lib
/ld-musl-
*.so.
*; do
612 cp libssp_nonshared.a
${DESTDIR}/${sysroot}/usr
/lib
/
615 cd ${wrksrc}/glibc_build
616 make install_root
=${DESTDIR}/${sysroot} install install-headers
619 rm -f ${DESTDIR}/usr/lib/gcc/${tgt}/${gcc_patch}/include-fixed
/bits
/statx.h
622 # minor-versioned symlinks
623 mv ${DESTDIR}/usr/lib/gcc/${tgt}/${gcc_patch} \
624 ${DESTDIR}/usr/lib/gcc/${tgt}/${gcc_minor}
625 ln -sfr ${DESTDIR}/usr/lib/gcc/${tgt}/${gcc_minor} \
626 ${DESTDIR}/usr/lib/gcc/${tgt}/${gcc_patch}
628 # ditto for c++ headers
629 mv ${DESTDIR}/${sysroot}/usr/include/c++/${gcc_patch} \
630 ${DESTDIR}/${sysroot}/usr/include/c++/${gcc_minor}
631 ln -sfr ${DESTDIR}/${sysroot}/usr/include/c++/${gcc_minor} \
632 ${DESTDIR}/${sysroot}/usr/include/c++/${gcc_patch}
634 # Symlinks for gnarl and gnat shared libraries
635 local adalib
=usr
/lib
/gcc
/${tgt}/${gcc_patch}/adalib
636 mv ${DESTDIR}/${adalib}/libgnarl-${gcc_major}.so \
637 ${DESTDIR}/${sysroot}/usr
/lib
638 mv ${DESTDIR}/${adalib}/libgnat-${gcc_major}.so \
639 ${DESTDIR}/${sysroot}/usr
/lib
640 ln -sf libgnarl-
${gcc_major}.so ${DESTDIR}/${sysroot}/usr
/lib
/libgnarl.so
641 ln -sf libgnat-
${gcc_major}.so ${DESTDIR}/${sysroot}/usr
/lib
/libgnat.so
642 rm -vf ${DESTDIR}/${adalib}/libgna{rl,t}.so
644 # Remove libgomp library because it conflicts with libgomp and
645 # libgomp-devel packages
646 rm -f ${DESTDIR}/${sysroot}/usr
/lib
/libgomp
*
648 # Remove libdep linker plugin because it conflicts with system binutils
649 rm -f ${DESTDIR}/usr
/lib
/bfd-plugins
/libdep
*
651 # Remove leftover symlinks
652 rm -f ${DESTDIR}/usr
/lib
${XBPS_TARGET_WORDSIZE}
653 rm -f ${DESTDIR}/lib
*
654 rm -f ${DESTDIR}/*bin
655 # Remove unnecessary stuff
656 rm -rf ${DESTDIR}/${sysroot}/{sbin,etc,var,libexec}
657 rm -rf ${DESTDIR}/${sysroot}/usr/{sbin,share,libexec}
658 rm -rf ${DESTDIR}/usr
/share
659 rm -f ${DESTDIR}/usr
/lib
*/libiberty.a
661 export PATH
="$oldpath"
662 export LD_LIBRARY_PATH
="$oldldlib"