1 ################################################################################
3 # toolchain.cygclass - for building and using toolchains
5 # Part of cygport - Cygwin packaging application
6 # Copyright (C) 2006-2020 Cygport authors
7 # Provided by the Cygwin project <https://cygwin.com/>
9 # cygport is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
14 # cygport is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with cygport. If not, see <https://www.gnu.org/licenses/>.
22 ################################################################################
24 #****h* Cygclasses/toolchain.cygclass
26 # TOOLCHAIN_TARGET="..."
29 # The GNU toolchain, consisting of Binutils, the GCC compilers, and the GDB
30 # debugger, are used to build code in C and related languages into an executable
31 # or library, either for the system on which it runs (a "native" compiler) or
32 # for another system (a "cross" compiler).
34 # This cygclass assists in building both native- and cross-compilers which will
42 #****v* toolchain.cygclass/TOOLCHAIN_TARGET
44 # The CPU-VENDOR-OS triplet, or customary abbreviation thereof, describing the
45 # compiler's "target" system; for example:
46 # * i686-pc-linux-gnu: i686 GNU/Linux
47 # * x86_64-w64-mingw32: Win64
48 # * arm-eabi [arm-unknown-eabi]: Embedded ARM ELF system (e.g. with Newlib)
49 # * avr [avr-unknown-none]: Atmel AVR bare metal (e.g. Arduino)
50 # Note that while the 'unknown' vendor tag is usually omitted from embedded
51 # systems, particularly in conjunction with a 'none' OS tag, as above, this
52 # does not apply to e.g. 'x86_64-unknown-linux-gnu' and other systems.
54 # The keyword "native" is also accepted, which will cause a host-native
55 # Cygwin compiler to be built, and TOOLCHAIN_TARGET to be redefined
58 # * TOOLCHAIN_TARGET must be defined before inherit()ing toolchain.cygclass.
60 if ! defined TOOLCHAIN_TARGET
62 error "TOOLCHAIN_TARGET must be defined before 'inherit toolchain'"
64 case ${TOOLCHAIN_TARGET} in
65 [Nn][Aa][Tt][Ii][Vv][Ee])
66 inform "Building native toolchain for ${CTARGET} host"
67 TOOLCHAIN_TARGET=${CTARGET}
70 *) __check_triplet ${TOOLCHAIN_TARGET}
71 CTARGET=${TOOLCHAIN_TARGET}
72 if __target_is_embedded
74 TOOLCHAIN_SYSROOT="/usr/${CTARGET}"
76 TOOLCHAIN_SYSROOT="/usr/${CTARGET}/sys-root"
81 #****d* toolchain.cygclass/TOOLCHAIN_SYSROOT
83 # GCC cross-compilers provide the concept of a sysroot: a directory which
84 # acts as the virtual root of the target filesystem, resulting in
85 # TOOLCHAIN_SYSROOT/$prefix/include and TOOLCHAIN_SYSROOT/$prefix/lib being in
86 # the default search paths without requiring -I or -L flags.
88 # This means that software natively compiled for the host system can be unpacked
89 # into the sysroot without needing to mangle paths. This is especially
90 # useful when bootstrapping a new toolchain; e.g. for Linux, one can just download
91 # glibc and kernel headers packages from a Linux distro, unpack them into the
92 # TOOLCHAIN_SYSROOT, and use those to build a cross-GCC for the first time.
95 #****d* toolchain.cygclass/TOOLCHAIN_PREFIX
97 # The $prefix directory under the sysroot. This definition is meant to
98 # be used in configure or cmake arguments to avoid dealing with different
99 # prefixes on various systems.
101 TOOLCHAIN_PREFIX="${TOOLCHAIN_SYSROOT}$(__target_prefix)"
103 #****d* toolchain.cygclass/TOOLCHAIN_BINDIR
105 # The $prefix/bin directory under the sysroot. This definition is meant to
106 # be used in configure or cmake arguments to avoid dealing with different
107 # prefixes on various systems.
109 TOOLCHAIN_BINDIR="${TOOLCHAIN_PREFIX}/bin"
111 #****d* toolchain.cygclass/TOOLCHAIN_INCLUDEDIR
113 # The $prefix/include directory under the sysroot. This definition is
114 # meant to be used in configure or cmake arguments to avoid dealing with
115 # different prefixes on various systems.
117 TOOLCHAIN_INCLUDEDIR="${TOOLCHAIN_PREFIX}/include"
119 #****d* toolchain.cygclass/TOOLCHAIN_LIBDIR
121 # The $prefix/lib directory under the sysroot. This definition is meant to
122 # be used in configure or cmake arguments to avoid dealing with different
123 # prefixes on various systems.
125 TOOLCHAIN_LIBDIR="${TOOLCHAIN_PREFIX}/lib"
127 #****d* toolchain.cygclass/TOOLCHAIN_DATADIR
129 # The $prefix/share directory under the sysroot. This definition is meant to
130 # be used in configure or cmake arguments to avoid dealing with different
131 # prefixes on various systems.
133 TOOLCHAIN_DATADIR="${TOOLCHAIN_PREFIX}/share"
135 # A normal cross-compiler uses the stage1 xgcc to cross-compile
136 # libgcc/libstdc++/etc. However, in a "Canadian cross" scenario,
137 # the stage1 compiler will not run on the build system, as it is itself
138 # cross-compiled, so you also need a $target toolchain to build
139 # libgcc and friends instead. Of course, if $target is the same
140 # as the build system (a "crossback"), then the question is moot.
141 if test ${CHOST} != ${CBUILD} && test ${CTARGET} != ${CBUILD} \
142 && (! check_target_tool gcc || ! check_target_tool strip)
144 error "This package requires ${CTARGET} binutils and gcc"
147 #****C* toolchain.cygclass/toolchain_compile
149 # toolchain_compile [CONFIGURE_ARGS]
151 # Configures the toolchain package with the necessary options for the given
152 # TOOLCHAIN_TARGET, then runs cygmake to build.
154 toolchain_compile() {
157 if test ${CTARGET} != ${CHOST} && ! __target_is_embedded
159 sysroot="--with-sysroot=${TOOLCHAIN_SYSROOT} --with-build-sysroot=${TOOLCHAIN_SYSROOT}"
162 cygconf ${sysroot} ${@}
166 #****o* toolchain.cygclass/src_compile (toolchain)
168 # An autoreconf stage is not run by default, because GNU toolchain packages
169 # require specific versions of the autotools which do not match the latest
170 # versions in the distribution. They also do not recurse with AC_CONFIG_SUBDIRS.
178 readonly -f toolchain_compile