recipes: devel/gcc: strip ELF executables only excluding shared objects. GCC is...
[dragora.git] / recipes / devel / gcc / recipe
blob167fd89be48da46ca247e569c331140f81b20375
1 # Build recipe for GCC.
3 # Copyright (c) 2015-2019 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=8-20181221
19 release=2
21 # Set 'outdir' for a nice and well-organized output directory
22 outdir="${outdir}/${arch}/devel"
24 tarname=${program}-${version}.tar.xz
26 # Remote source(s)
27 #fetch=http://gnu.c3sl.ufpr.br/ftp/gcc/gcc-${version}/$tarname
28 fetch=ftp://gcc.gnu.org/pub/gcc/snapshots/${version}/$tarname
30 homepage=http://www.gnu.org/software/gcc
31 license="GPLv2+, GPLv3+, LGPLv2.1, LGPLv3 + GCC runtime library exception"
33 description="
34 The GNU C Compiler Collection.
36 The GNU Compiler Collection (GCC) is a compiler system produced by the
37 GNU Project supporting various programming languages.  GCC is a key
38 component of the GNU toolchain.  The Free Software Foundation (FSF)
39 distributes GCC under the GNU General Public License (GNU GPL).
41 For more information about GCC, visit:  $homepage
44 # Source documentation
45 docs="COPYING* README"
46 docsdir="${docdir}/${program}-${version}"
48 # System-dependent
49 MACHTYPE="$(cc -dumpmachine)"
51 build()
53     set -e
55     unpack "${tardir}/$tarname"
57     cd "$srcdir"
59     # Set sane permissions
60     chmod -R u+w,go-w,a+rX-s .
62     # Apply specific patches for the support in musl.
63     # http://port70.net/~nsz/musl/gcc-8.2.0
65     #patch -Np1 -i "${worktree}/patches/gcc/0001-ssp_nonshared.patch"
66     patch -Np1 -i "${worktree}/patches/gcc/musl-libssp.diff"
67     patch -Np1 -i "${worktree}/patches/gcc/0002-posix_memalign.patch"
68     patch -Np1 -i "${worktree}/patches/gcc/0003-libatomic-test-fix.patch"
69     patch -Np1 -i "${worktree}/patches/gcc/0004-libgomp-test-fix.patch"
70     patch -Np1 -i "${worktree}/patches/gcc/0005-libitm-test-fix.patch"
71     patch -Np1 -i "${worktree}/patches/gcc/0006-libvtv-test-fix.patch"
72     patch -Np1 -i "${worktree}/patches/gcc/0007-j2.patch"
73     patch -Np1 -i "${worktree}/patches/gcc/0008-s390x-muslldso.patch"
74     patch -Np1 -i "${worktree}/patches/gcc/0009-microblaze-pr65649.patch"
75     patch -Np1 -i "${worktree}/patches/gcc/0010-ldbl128-config.patch"
76     patch -Np1 -i "${worktree}/patches/gcc/0011-m68k.patch"
77     patch -Np1 -i "${worktree}/patches/gcc/0012-static-pie.patch"
79     # Create a separate build directory
80     rm -rf ../gcc-build
81     mkdir ../gcc-build
82     cd ../gcc-build
84     ../${program}-${version}/configure SED=sed \
85      $configure_args \
86      $multilib_options \
87      $gcc_options \
88      --libdir=/usr/lib${libSuffix} \
89      --mandir=$mandir \
90      --infodir=$infodir \
91      --enable-bootstrap \
92      --enable-languages=c,c++,objc,obj-c++,fortran \
93      --enable-clocale=generic \
94      --enable-threads=posix \
95      --enable-tls \
96      --enable-nls \
97      --enable-lto \
98      --enable-libstdcxx-time \
99      --enable-checking=release \
100      --enable-fully-dynamic-string \
101      --enable-default-ssp \
102      --enable-default-pie \
103      --disable-libssp \
104      --disable-symvers \
105      --disable-libitm \
106      --disable-gnu-indirect-function \
107      --disable-libstdcxx-pch \
108      --disable-libmudflap \
109      --disable-libsanitizer \
110      --disable-libmpx \
111      --disable-libcilkrts \
112      --with-system-zlib \
113      --build=$MACHTYPE \
114      --host=$MACHTYPE \
115      --target=$MACHTYPE
117     make -j${jobs} V=1
118     make -j${jobs} V=1 DESTDIR="$destdir" install-strip
120     # Strip ELF executables only excluding shared objects
121     find "$destdir" -type f | xargs file | awk '/ELF/ && /executable/' | \
122      cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
124     # Back to source dir
125     cd .. && cd "$srcdir"
127     # Provide minimal libssp_nonshared.a so we don't need libssp from GCC
129     cc $QICFLAGS -c "${worktree}/archive/gcc/__stack_chk_fail_local.c" \
130                  -o __stack_chk_fail_local.o
131     ar r libssp_nonshared.a __stack_chk_fail_local.o
133     cp -p libssp_nonshared.a "${destdir}/usr/lib${libSuffix}"
134     strip -g "${destdir}/usr/lib${libSuffix}/libssp_nonshared.a"
136     # Move misplaced file(s) for GDB
137     mkdir -p "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
138     mv "${destdir}/usr/lib${libSuffix}"/*-gdb.py \
139        "${destdir}/usr/share/gdb/auto-load/usr/lib${libSuffix}"
141     # Provide compatibility and make soft links for package size
142     (
143         cd "${destdir}/usr/bin" || exit 1
144         mv gcc gcc-${version}
145         ln -sf gcc-${version} gcc
146         ln -sf gcc cc
147         ln -sf gcc-${version} ${MACHTYPE}-gcc
148         ln -sf gcc-${version} ${MACHTYPE}-gcc-${version}
150         mv g++ g++-gcc-${version}
151         ln -sf g++-gcc-${version} g++
152         ln -sf g++ c++
153         ln -sf g++-gcc-${version} ${MACHTYPE}-g++
154         ln -sf g++-gcc-${version} ${MACHTYPE}-c++
156         mv gfortran gfortran-${version}
157         ln -sf gfortran-${version} gfortran
158         ln -sf gfortran-${version} ${MACHTYPE}-gfortran
159         # Extra symlinks for fortran
160         ln -sf gfortran g77
161         ln -sf g77 f77
162         ln -sf gfortran g95
163         ln -sf g95 f95
165         mv gcc-ar gcc-ar-${version}
166         ln -sf gcc-ar-${version} gcc-ar
167         ln -sf gcc-ar-${version} ${MACHTYPE}-gcc-ar
169         mv gcc-nm gcc-nm-${version}
170         ln -sf gcc-nm-${version} gcc-nm
171         ln -sf gcc-nm-${version} ${MACHTYPE}-gcc-nm
173         mv gcc-ranlib gcc-ranlib-${version}
174         ln -sf gcc-ranlib-${version} gcc-ranlib
175         ln -sf gcc-ranlib-${version} ${MACHTYPE}-gcc-ranlib
176     )
177     (
178         mkdir -p "${destdir}/lib" && \
179         cd "${destdir}/lib" && ln -sf ../usr/bin/cpp .
180     )
182     # Compress info documents deleting index file for the package
183     if test -d "${destdir}/$infodir"
184     then
185         rm -f "${destdir}/${infodir}/dir"
186         lzip -9 "${destdir}/${infodir}"/* || true
187     fi
189     # Compress and link man pages (if needed)
190     if test -d "${destdir}/$mandir"
191     then
192         (
193             cd "${destdir}/$mandir"
194             find . -type f -exec lzip -9 '{}' +
195             find . -type l | while read -r file
196             do
197                 ln -sf "$(readlink -- "$file").lz" "${file}.lz"
198                 rm -- "$file"
199             done
200         )
201     fi
203     # Copy documentation
204     mkdir -p "${destdir}${docsdir}"
205     cp -p $docs "${destdir}${docsdir}/"
207     # Delete temporary build directory
208     cd -- "$TMPDIR"
209     if test -d ./gcc-build
210     then
211         rm -rf ./gcc-build
212     fi