etc: Enable a tty for a serial port by default.
[dragora.git] / recipes / devel / gcc / recipe
blobb34de36a0d27349541151101e2607b85253ac28e
1 # Build recipe for GCC.
3 # Copyright (c) 2015-2023 Matias Fonzo, <selk@dragora.org>.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 #    http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Exit immediately on any error
18 set -e
20 program=gcc
21 version=11-20230310
22 release=1
24 # Define a category for the output of the package name
25 pkgcategory=devel
27 tarname=${program}-${version}.tar.xz
29 # Remote source(s)
30 fetch="
31   https://gcc.gnu.org/pub/gcc/snapshots/${version}/$tarname
32   https://mirrors.concertpass.com/gcc/snapshots/${version}/$tarname
33   https://mirror.marwan.ma/gcc/snapshots/${version}/$tarname
36 homepage=https://www.gnu.org/software/gcc
37 license="GPLv2+, GPLv3+, LGPLv2.1, LGPLv3 + GCC runtime library exception"
39 description="
40 The GNU C Compiler Collection.
42 The GNU Compiler Collection (GCC) is a compiler system produced by the
43 GNU Project supporting various programming languages.  GCC is a key
44 component of the GNU toolchain.  The Free Software Foundation (FSF)
45 distributes GCC under the GNU General Public License (GNU GPL).
47 For more information about GCC, visit:  $homepage
50 # Source documentation
51 docs="COPYING* README"
52 docsdir="${docdir}/${program}-${version}"
54 build()
56     unpack "${tardir}/$tarname"
58     cd "$srcdir"
60     # Set sane permissions
61     chmod -R u+w,go-w,a+rX-s .
63     # Apply specific patches for the support in musl.
64     # https://port70.net/~nsz/musl/gcc-11.1.0/
66     patch -Np1 -i "${worktree}/patches/gcc/11/0002-posix_memalign.patch"
67     patch -Np1 -i "${worktree}/patches/gcc/11/0003-j2.patch"
68     patch -Np1 -i "${worktree}/patches/gcc/11/0004-static-pie.patch"
69     patch -Np1 -i "${worktree}/patches/gcc/11/0005-m68k-sqrt.patch"
70     patch -Np1 -i "${worktree}/patches/gcc/11/extra-musl_libssp.patch"
71     patch -Np1 -i "${worktree}/patches/gcc/11/extra-relro-in-dragora.patch"
73     # Apply patches from "Alpine Linux" in order to improve the security (Thanks!)
74     patch -Np1 -i "${worktree}/patches/gcc/0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch"
75     patch -Np1 -i "${worktree}/patches/gcc/0005-On-linux-targets-pass-as-needed-by-default-to-the-li.patch"
76     patch -Np1 -i "${worktree}/patches/gcc/0006-Enable-Wformat-and-Wformat-security-by-default.patch"
77     patch -Np1 -i "${worktree}/patches/gcc/0007-Enable-Wtrampolines-by-default.patch"
78     patch -Np1 -i "${worktree}/patches/gcc/0008-Disable-ssp-on-nostdlib-nodefaultlibs-and-ffreestand.patch"
79     patch -Np1 -i "${worktree}/patches/gcc/0014-nopie.patch"
80     patch -Np1 -i "${worktree}/patches/gcc/0021-add-fortify-headers-paths.patch"
82     # Create a separate build directory
83     rm -rf BUILD
84     mkdir BUILD
85     cd BUILD
87     # System-dependent
88     MACHINE="$(gcc -dumpmachine)"
90     ../configure SED=sed \
91     CPPFLAGS="$QICPPFLAGS" CFLAGS="$QICFLAGS" CXXFLAGS="$QICXXFLAGS" LDFLAGS="$QILDFLAGS" \
92      $configure_args \
93      --libdir=/usr/lib${libSuffix} \
94      --mandir=$mandir \
95      --infodir=$infodir \
96      --enable-bootstrap \
97      --enable-languages=c,c++,fortran,objc,obj-c++ \
98      --enable-clocale=generic \
99      --enable-threads=posix \
100      --enable-cet=auto \
101      --enable-initfini-array \
102      --enable-tls \
103      --enable-nls \
104      --enable-lto \
105      --enable-plugin \
106      --enable-objc-gc \
107      --enable-libstdcxx-time \
108      --enable-checking=release \
109      --enable-fully-dynamic-string \
110      --enable-default-ssp \
111      --enable-default-pie \
112      --enable-libssp \
113      --enable-initfini-array \
114      --disable-symvers \
115      --disable-libitm \
116      --disable-gnu-indirect-function \
117      --disable-libstdcxx-pch \
118      --disable-libsanitizer \
119      --disable-libcilkrts \
120      --disable-install-libiberty \
121      --with-system-zlib \
122      --with-linker-hash-style=gnu \
123      --build=$MACHINE \
124      --host=$MACHINE \
125      --target=$MACHINE \
126      $multilib_options \
127      $gcc_options
129     make -j${jobs} V=1 \
130      BOOT_CFLAGS="$QICFLAGS" \
131      BOOT_CXXFLAGS="$QICXXFLAGS" \
132      BOOT_LDFLAGS="$QILDFLAGS" \
133      BOOT_CPPFLAGS="$QICPPFLAGS"
135     make -j${jobs} V=1 DESTDIR="$destdir" install
137     # Delete non-shared version of libssp (provided on the musl package)
138     rm -f "${destdir}/usr/lib${libSuffix}"/libssp_nonshared.a
140     # Strip ELF executables only excluding shared objects
141     find "$destdir" -type f | xargs file | awk '/ELF/ && /executable/' | \
142      cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
144     # Strip static libraries in order to reduce the package size
145     find "$destdir" -type f | xargs file | awk '/current ar archive/' | \
146      cut -f 1 -d : | xargs strip --strip-debug 2> /dev/null || true
148     cd ../
150     # Move misplaced file(s) for GDB
151     mkdir -p "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
152     mv "${destdir}/usr/lib${libSuffix}"/*-gdb.py \
153        "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
155     # Provide compatibility and make soft links for package size
156     (
157         cd "${destdir}/usr/bin" || exit 1
159         mv gcc gcc-${version}
160         ln -sf gcc-${version} gcc
161         ln -sf gcc cc
162         ln -sf gcc-${version} ${MACHINE}-gcc
163         ln -sf gcc-${version} ${MACHINE}-gcc-${version}
165         mv g++ g++-gcc-${version}
166         ln -sf g++-gcc-${version} g++
167         ln -sf g++ c++
168         ln -sf g++-gcc-${version} ${MACHINE}-g++
169         ln -sf g++-gcc-${version} ${MACHINE}-c++
171         mv gfortran gfortran-${version}
172         ln -sf gfortran-${version} gfortran
173         ln -sf gfortran-${version} ${MACHINE}-gfortran
174         # Extra symlinks for fortran
175         ln -sf gfortran g77
176         ln -sf g77 f77
177         ln -sf gfortran g95
178         ln -sf g95 f95
180         mv gcc-ar gcc-ar-${version}
181         ln -sf gcc-ar-${version} gcc-ar
182         ln -sf gcc-ar-${version} ${MACHINE}-gcc-ar
184         mv gcc-nm gcc-nm-${version}
185         ln -sf gcc-nm-${version} gcc-nm
186         ln -sf gcc-nm-${version} ${MACHINE}-gcc-nm
188         mv gcc-ranlib gcc-ranlib-${version}
189         ln -sf gcc-ranlib-${version} gcc-ranlib
190         ln -sf gcc-ranlib-${version} ${MACHINE}-gcc-ranlib
191     )
192     (
193         cd "${destdir}/usr/lib${libSuffix}" && ln -sf ../bin/cpp .
194     )
196     unset -v MACHINE
198     # Insert wrapper scripts for handling C89 and C99 invocations
199     cat "${worktree}/archive/gcc/c89" > "${destdir}/usr/bin/c89"
200     cat "${worktree}/archive/gcc/c99" > "${destdir}/usr/bin/c99"
201     chmod 755 "${destdir}"/usr/bin/c?9
203     # Compress info documents deleting index file for the package
204     if test -d "${destdir}/$infodir"
205     then
206         rm -f "${destdir}/${infodir}/dir"
207         lzip -9 "${destdir}/${infodir}"/* || true
208     fi
210     # Compress and link man pages (if needed)
211     if test -d "${destdir}/$mandir"
212     then
213         (
214             cd "${destdir}/$mandir"
215             find . -type f -exec lzip -9 {} +
216             find . -type l | while read -r file
217             do
218                 ln -sf "$(readlink -- "$file").lz" "${file}.lz"
219                 rm -- "$file"
220             done
221         )
222     fi
224     # Copy documentation
225     mkdir -p "${destdir}/$docsdir"
226     cp -p $docs "${destdir}/$docsdir"