recipes: Rename 'pkghashtag' variable to 'pkgcategory'
[dragora.git] / recipes / devel / gcc / recipe
blob27e6b68d060c7e93ddb18b8f61496a84a41bbb77
1 # Build recipe for GCC.
3 # Copyright (c) 2015-2020 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 program=gcc
18 version=9.3.0
19 release=2
21 # Define a category for the output of the package name
22 pkgcategory=devel
24 tarname=${program}-${version}.tar.gz
26 # Remote source(s)
27 fetch=http://www.netgull.com/gcc/releases/gcc-${version}/$tarname
28 #fetch="
29 #  http://www.netgull.com/gcc/snapshots/${version}/$tarname
30 #  http://gnu.c3sl.ufpr.br/ftp/gcc/gcc-${version}/$tarname
31 #  ftp://gcc.gnu.org/pub/gcc/snapshots/${version}/$tarname
34 homepage=http://www.gnu.org/software/gcc
35 license="GPLv2+, GPLv3+, LGPLv2.1, LGPLv3 + GCC runtime library exception"
37 description="
38 The GNU C Compiler Collection.
40 The GNU Compiler Collection (GCC) is a compiler system produced by the
41 GNU Project supporting various programming languages.  GCC is a key
42 component of the GNU toolchain.  The Free Software Foundation (FSF)
43 distributes GCC under the GNU General Public License (GNU GPL).
45 For more information about GCC, visit:  $homepage
48 # Source documentation
49 docs="COPYING* README"
50 docsdir="${docdir}/${program}-${version}"
52 # System-dependent
53 MACHTYPE="$(cc -dumpmachine)"
55 build()
57     set -e
59     unpack "${tardir}/$tarname"
61     cd "$srcdir"
63     # Set sane permissions
64     chmod -R u+w,go-w,a+rX-s .
66     # Apply specific patches for the support in musl.
67     # http://port70.net/~nsz/musl/gcc-9.1.0/
69     patch -Np1 -i "${worktree}/patches/gcc/230-musl_libssp.patch"
70     patch -Np1 -i "${worktree}/patches/gcc/0002-posix_memalign.patch"
71     patch -Np1 -i "${worktree}/patches/gcc/0003-libatomic-test-fix.patch"
72     patch -Np1 -i "${worktree}/patches/gcc/0004-libgomp-test-fix.patch"
73     patch -Np1 -i "${worktree}/patches/gcc/0005-libitm-test-fix.patch"
74     patch -Np1 -i "${worktree}/patches/gcc/0006-libvtv-test-fix.patch"
75     patch -Np1 -i "${worktree}/patches/gcc/0007-j2.patch"
76     patch -Np1 -i "${worktree}/patches/gcc/0008-s390x-muslldso.patch"
77     patch -Np1 -i "${worktree}/patches/gcc/0009-microblaze-pr65649.patch"
78     patch -Np1 -i "${worktree}/patches/gcc/0010-ldbl128-config.patch"
79     patch -Np1 -i "${worktree}/patches/gcc/0011-m68k.patch"
80     patch -Np1 -i "${worktree}/patches/gcc/0012-static-pie.patch"
81     patch -Np1 -i "${worktree}/patches/gcc/0013-invalid-tls-model.patch"
82     patch -Np1 -i "${worktree}/patches/gcc/turn-on-relro-bydefault.patch"
84     # Create a separate build directory
85     rm -rf ../gcc-build
86     mkdir ../gcc-build
87     cd ../gcc-build
89     ../${program}-${version}/configure SED=sed \
90     CFLAGS="$QICFLAGS" CXXFLAGS="$QICXXFLAGS" LDFLAGS="$QILDFLAGS" \
91      $configure_args \
92      --libdir=/usr/lib${libSuffix} \
93      --mandir=$mandir \
94      --infodir=$infodir \
95      --enable-bootstrap \
96      --enable-languages=c,c++,fortran,objc,obj-c++ \
97      --enable-clocale=generic \
98      --enable-threads=posix \
99      --enable-cet=auto \
100      --enable-tls \
101      --enable-nls \
102      --enable-lto \
103      --enable-objc-gc \
104      --enable-libstdcxx-time \
105      --enable-checking=release \
106      --enable-fully-dynamic-string \
107      --enable-default-ssp \
108      --enable-default-pie \
109      --enable-libssp \
110      --disable-symvers \
111      --disable-libitm \
112      --disable-gnu-indirect-function \
113      --disable-libstdcxx-pch \
114      --disable-libmudflap \
115      --disable-libsanitizer \
116      --disable-libcilkrts \
117      --with-system-zlib \
118      --build=$MACHTYPE \
119      --host=$MACHTYPE \
120      --target=$MACHTYPE \
121      $multilib_options \
122      $gcc_options
124     make -j${jobs} V=1 \
125      BOOT_LDFLAGS="$QILDFLAGS" \
126      BOOT_CFLAGS="$QICFLAGS" \
127      BOOT_CXXFLAGS="$QICXXFLAGS"
129     make -j${jobs} V=1 DESTDIR="$destdir" install
131     # Delete non-shared version of libssp (provided on the musl package)
132     rm -f "${destdir}/usr/lib${libSuffix}"/libssp_nonshared.a
134     # Strip ELF executables only excluding shared objects
135     find "$destdir" -type f | xargs file | awk '/ELF/ && /executable/' | \
136      cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
138     # Strip static libraries in order to reduce the package size
139     find "$destdir" -type f | xargs file | awk '/current ar archive/' | \
140      cut -f 1 -d : | xargs strip --strip-debug 2> /dev/null || true
142     # Back to source dir
143     cd .. && cd "$srcdir"
145     # Move misplaced file(s) for GDB
146     mkdir -p "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
147     mv "${destdir}/usr/lib${libSuffix}"/*-gdb.py \
148        "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
150     # Provide compatibility and make soft links for package size
151     (
152         cd "${destdir}/usr/bin" || exit 1
153         mv gcc gcc-${version}
154         ln -sf gcc-${version} gcc
155         ln -sf gcc cc
156         ln -sf gcc-${version} ${MACHTYPE}-gcc
157         ln -sf gcc-${version} ${MACHTYPE}-gcc-${version}
159         mv g++ g++-gcc-${version}
160         ln -sf g++-gcc-${version} g++
161         ln -sf g++ c++
162         ln -sf g++-gcc-${version} ${MACHTYPE}-g++
163         ln -sf g++-gcc-${version} ${MACHTYPE}-c++
165         mv gfortran gfortran-${version}
166         ln -sf gfortran-${version} gfortran
167         ln -sf gfortran-${version} ${MACHTYPE}-gfortran
168         # Extra symlinks for fortran
169         ln -sf gfortran g77
170         ln -sf g77 f77
171         ln -sf gfortran g95
172         ln -sf g95 f95
174         mv gcc-ar gcc-ar-${version}
175         ln -sf gcc-ar-${version} gcc-ar
176         ln -sf gcc-ar-${version} ${MACHTYPE}-gcc-ar
178         mv gcc-nm gcc-nm-${version}
179         ln -sf gcc-nm-${version} gcc-nm
180         ln -sf gcc-nm-${version} ${MACHTYPE}-gcc-nm
182         mv gcc-ranlib gcc-ranlib-${version}
183         ln -sf gcc-ranlib-${version} gcc-ranlib
184         ln -sf gcc-ranlib-${version} ${MACHTYPE}-gcc-ranlib
185     )
186     (
187         mkdir -p "${destdir}/lib" && \
188         cd "${destdir}/lib" && ln -sf ../usr/bin/cpp .
189     )
191     # Compress info documents deleting index file for the package
192     if test -d "${destdir}/$infodir"
193     then
194         rm -f "${destdir}/${infodir}/dir"
195         lzip -9 "${destdir}/${infodir}"/* || true
196     fi
198     # Compress and link man pages (if needed)
199     if test -d "${destdir}/$mandir"
200     then
201         (
202             cd "${destdir}/$mandir"
203             find . -type f -exec lzip -9 '{}' +
204             find . -type l | while read -r file
205             do
206                 ln -sf "$(readlink -- "$file").lz" "${file}.lz"
207                 rm -- "$file"
208             done
209         )
210     fi
212     # Copy documentation
213     mkdir -p "${destdir}${docsdir}"
214     cp -p $docs "${destdir}${docsdir}/"
216     # Delete temporary build directory
217     cd -- "$TMPDIR"
218     if test -d ./gcc-build
219     then
220         rm -rf ./gcc-build
221     fi