Bump version to 0.36.9
[cygport.git] / cygclass / toolchain.cygclass
blob4e12d0b5047486425a6d729f603a6c5073d03f85
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
25 #  SYNOPSIS
26 #  TOOLCHAIN_TARGET="..."
27 #  inherit toolchain
28 #  DESCRIPTION
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
35 #  run on Cygwin.
36 #  INHERITS
37 #  autotools.cygclass
38 #  SEE ALSO
39 #  cross.cygclass
40 #****
42 #****v* toolchain.cygclass/TOOLCHAIN_TARGET
43 #  DESCRIPTION
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
56 #  accordingly.
57 #  NOTES
58 #  * TOOLCHAIN_TARGET must be defined before inherit()ing toolchain.cygclass.
59 #****
60 if ! defined TOOLCHAIN_TARGET
61 then
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}
68         TOOLCHAIN_SYSROOT=
69         ;;
70 *)      __check_triplet ${TOOLCHAIN_TARGET}
71         CTARGET=${TOOLCHAIN_TARGET}
72         if __target_is_embedded
73         then
74                 TOOLCHAIN_SYSROOT="/usr/${CTARGET}"
75         else
76                 TOOLCHAIN_SYSROOT="/usr/${CTARGET}/sys-root"
77         fi
78         ;;
79 esac
81 #****d* toolchain.cygclass/TOOLCHAIN_SYSROOT
82 #  DESCRIPTION
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.
93 #****
95 #****d* toolchain.cygclass/TOOLCHAIN_PREFIX
96 #  DESCRIPTION
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.
100 #****
101 TOOLCHAIN_PREFIX="${TOOLCHAIN_SYSROOT}$(__target_prefix)"
103 #****d* toolchain.cygclass/TOOLCHAIN_BINDIR
104 #  DESCRIPTION
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.
108 #****
109 TOOLCHAIN_BINDIR="${TOOLCHAIN_PREFIX}/bin"
111 #****d* toolchain.cygclass/TOOLCHAIN_INCLUDEDIR
112 #  DESCRIPTION
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.
116 #****
117 TOOLCHAIN_INCLUDEDIR="${TOOLCHAIN_PREFIX}/include"
119 #****d* toolchain.cygclass/TOOLCHAIN_LIBDIR
120 #  DESCRIPTION
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.
124 #****
125 TOOLCHAIN_LIBDIR="${TOOLCHAIN_PREFIX}/lib"
127 #****d* toolchain.cygclass/TOOLCHAIN_DATADIR
128 #  DESCRIPTION
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.
132 #****
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)
143 then
144         error "This package requires ${CTARGET} binutils and gcc"
147 #****C* toolchain.cygclass/toolchain_compile
148 #  SYNOPSIS
149 #  toolchain_compile [CONFIGURE_ARGS]
150 #  DESCRIPTION
151 #  Configures the toolchain package with the necessary options for the given
152 #  TOOLCHAIN_TARGET, then runs cygmake to build.
153 #****
154 toolchain_compile() {
155         local sysroot
157         if test ${CTARGET} != ${CHOST} && ! __target_is_embedded
158         then
159                 sysroot="--with-sysroot=${TOOLCHAIN_SYSROOT} --with-build-sysroot=${TOOLCHAIN_SYSROOT}"
160         fi
162         cygconf ${sysroot} ${@}
163         cygmake
166 #****o* toolchain.cygclass/src_compile (toolchain)
167 #  NOTE
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.
171 #  DEFINITION
172 src_compile() {
173         cd ${B}
174         toolchain_compile
176 #****
178 readonly -f toolchain_compile