1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/gcc/parse-config
3 # Copyright (C) 2004 - 2022 The T2 SDE Project
4 # Copyright (C) 1998 - 2003 ROCK Linux Project
6 # This Copyright note is generated by scripts/Create-CopyPatch,
7 # more information can be found in the files COPYING and README.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License version 2.
11 # --- T2-COPYRIGHT-NOTE-END ---
13 # Use the stack protector patch, if not disabled for the pkg
15 if [ "${SDECFG_DEFAULT_CC:0:3}" = "gcc" -a "$SDECFG_PKG_GCC_STACKPRO" = 1 ]; then
16 if ! hasflag NO-SSP; then
17 var_append GCC_WRAPPER_INSERT ' ' '-fstack-protector'
19 echo_warning 'Package incompatible with GCC stack-protector: disabled'
23 # It's usually better to not change the kernel optimization too drastically.
25 if [[ $SDECFG_DEFAULT_KCC = gcc* ]] ; then
26 export KCC="${archprefix}kcc"
27 var_insert KCC_WRAPPER_REMOVE " " "-O -O[0-9sgz]"
30 # set CC, CXX and F77 environment variables
32 for x in CC CXX F77 ; do
33 eval "y=\$SDECFG_DEFAULT_$x"
34 if [[ $y = gcc* ]] ; then
35 case "$x-$stagelevel" in
37 z="${archprefix}gcc ${archprefix}gcc" ;;
39 z="${archprefix}g++ ${archprefix}g++" ;;
41 z="${archprefix}g77 ${archprefix}gfortran" ;;
43 export $x=${x}_not_available_in_stage_${stagelevel}
47 [ "`type -p $y`" ] && export $x=$y
52 # Add the usual gcc optimazation options
53 # Strip or add debug information
55 debug_flags='-g -ggdb -g[0-9] -gdwarf*'
57 if [ "$SDECFG_DEBUG" = 0 ] ; then
58 var_append GCC_WRAPPER_APPEND " " "-s"
59 var_insert GCC_WRAPPER_REMOVE " " "$debug_flags"
60 var_append SYSGCC_WRAPPER_APPEND " " "-s"
61 var_insert SYSGCC_WRAPPER_REMOVE " " "$debug_flags"
63 var_append GCC_WRAPPER_APPEND " " "-ggdb"
64 var_insert GCC_WRAPPER_REMOVE " " "-s $debug_flags"
65 var_append SYSGCC_WRAPPER_APPEND " " "-ggdb"
66 var_insert SYSGCC_WRAPPER_REMOVE " " "-s $debug_flags"
69 # avoid undefined references to __sync_fetch_and_add_4
70 [[ "$HOSTTYPE" = i?86 ]] && var_append SYSGCC_WRAPPER_APPEND ' ' "-march=$HOSTTYPE"
72 # Remove the optimization options, since we pass generic ones ... In ROCK
73 # history this has been -m*, but this caused -msse and -maltivec style options
74 # to get lost. So we better explicitly only remove some -m options ... -ReneR
75 var_insert GCC_WRAPPER_REMOVE " " "-O -O[0-9sgz] -mtune* -march* -mcpu* -Werror -Wextra"
76 var_insert KCC_WRAPPER_REMOVE " " "-Werror"
77 var_insert SYSGCC_WRAPPER_REMOVE " " "-O -O[0-9sgz] -mtune* -march* -mcpu* -Werror"
81 f="$confdir/$pkg.prof"
82 # hack mostly for glibc32, could be made more generic
83 [ -f "$f" ] || f="$confdir/../${pkg%%[0-9]*}/${pkg%%[0-9]*}.prof"
84 # TODO: or fix awk script for non existing file?
85 [ -f "$f" ] || f="/dev/null"
87 basec="-Os"; basecxx="-O2"; opt="-O2"
88 [ "$SDECFG_OPT" = "smarter" ] && opt="-O3"
89 [ "$SDECFG_OPT" = "smartly" ] && basecxx="$basec"
91 var_insert CC_WRAPPER_INSERT " " "$basec"
92 var_insert CXX_WRAPPER_INSERT " " "$basecxx"
93 var_insert GCC_WRAPPER_INSERT " " "-HOT$opt"
94 var_insert GCC_WRAPPER_FILTER "|" "gawk -f $base/misc/tools-source/smart_wrapper.awk $f -"
95 var_insert KCC_WRAPPER_INSERT " " "-Os -HOT$opt"
96 var_insert KCC_WRAPPER_FILTER "|" "gawk -f $base/misc/tools-source/smart_wrapper.awk $f -"
97 var_insert SYSCC_WRAPPER_INSERT " " "$basec"
98 var_insert SYSCXX_WRAPPER_INSERT " " "$basecxx"
99 var_insert SYSGCC_WRAPPER_INSERT " " "-HOT$opt"
100 var_insert SYSGCC_WRAPPER_FILTER "|" "gawk -f $base/misc/tools-source/smart_wrapper.awk $f -"
103 var_insert GCC_WRAPPER_INSERT " " "-O2"
104 var_insert KCC_WRAPPER_INSERT " " "-O2"
105 var_insert SYSGCC_WRAPPER_INSERT " " "-O2"
108 var_insert GCC_WRAPPER_INSERT " " "-O2 -ftree-vectorize"
109 var_insert KCC_WRAPPER_INSERT " " "-O2"
110 var_insert SYSGCC_WRAPPER_INSERT " " "-O2 -ftree-vectorize"
113 var_insert GCC_WRAPPER_INSERT " " "-O3"
114 var_insert KCC_WRAPPER_INSERT " " "-O3"
115 var_insert SYSGCC_WRAPPER_INSERT " " "-O3"
118 var_insert GCC_WRAPPER_INSERT " " "-Os"
119 var_insert KCC_WRAPPER_INSERT " " "-Os"
120 var_insert SYSGCC_WRAPPER_INSERT " " "-Os"
123 var_insert GCC_WRAPPER_INSERT " " "-Os -ftree-vectorize"
124 var_insert KCC_WRAPPER_INSERT " " "-Os"
125 var_insert SYSGCC_WRAPPER_INSERT " " "-Os -ftree-vectorize"
128 var_insert GCC_WRAPPER_INSERT " " "-O1"
129 var_insert KCC_WRAPPER_INSERT " " "-O1"
130 var_insert SYSGCC_WRAPPER_INSERT " " "-O1"
133 var_insert GCC_WRAPPER_INSERT " " "-Og"
134 var_insert KCC_WRAPPER_INSERT " " "-Og"
135 var_insert SYSGCC_WRAPPER_INSERT " " "-Og"
138 var_insert GCC_WRAPPER_INSERT " " "-O0"
139 var_insert KCC_WRAPPER_INSERT " " "-O0"
140 var_insert SYSGCC_WRAPPER_INSERT " " "-O0"
144 # Add the architecture gcc optimisation options
146 if [ -f architecture/$arch/gcc-options.in ]; then
147 . architecture/$arch/gcc-options.in
150 # gcc-4.1.0 hangs with -v --help -pipe, thus we do not add it in that case
151 var_insert GCC_WRAPPER_INSERT ' ' '--help?:-pipe'
152 var_insert SYSGCC_WRAPPER_INSERT ' ' '--help?:-pipe'
154 [ "$SDECFG_LD_AS_NEEDED" != 0 ] &&
155 var_append GCC_WRAPPER_INSERT " " "-c?:-Wl,--as-needed"
157 [ "$SDECFG_PIE" != 0 ] &&
158 var_append GCC_WRAPPER_INSERT " " "-c?-fPIE:-pie"
160 var_append GCC_WRAPPER_APPEND " " "$SDECFG_C_FLAGS"
161 var_append KCC_WRAPPER_APPEND " " "$SDECFG_C_FLAGS"
163 # Compile (i.e. link) all bins statically
165 if [ "$SDECFG_STATIC" = 1 ]; then
166 var_insert GCC_WRAPPER_INSERT " " "-static"
169 # Compile with no exceptions or rtti, gcc itself must support both
171 if [ "$SDECFG_LIMITCXX" = 1 ] && [[ $pkg != gcc* ]] ; then
172 var_append CXX_WRAPPER_APPEND " " "-fno-exceptions -fno-rtti"
175 # Passing -I/usr{/local/}include creates a warning in gcc3 which is confusing
176 # some of the configure scripts and Makefiles.
178 var_insert GCC_WRAPPER_REMOVE " " "-I/usr/include -I/usr/local/include"
180 # pkg-config and other output or hardcoded configure assumption
181 # do not include the "DESTDIR" we need to adapt the pathes accordingly
182 function gcc_sysroot_filter() {
183 # merge multiple path separators
184 var_append GCC_WRAPPER_FILTER '|' "sed -e 's,//*,/,g'"
186 # translate all non-$sysroot with trailing /lib and correct to $libdir
187 var_append GCC_WRAPPER_FILTER '|' \
188 "sed -e 's@^\(-[L]\|-Wl.*-rpath-link,\)*\(/\|/usr/\|/usr/[^/]*/\|/opt/[^/]*/\)\(lib\)\$@\1$root\2${libdir##*/}@'"
190 # keep any other non-$sysdir /lib* as it
191 var_append GCC_WRAPPER_FILTER '|' \
192 "sed -e 's@^\(-[L]\|-Wl.*-rpath-link,\)*\(/\|/usr/\|/usr/[^/]*/\|/opt/[^/]*/\)\(lib\)@\1$root\2\3@'"
194 # and tranlate includes, too, and yes, we need "lib" for for lib/glib/include/glibconfig.h
195 var_append GCC_WRAPPER_FILTER '|' \
196 "sed -e 's@^\(-[I]\)*\(/\|/usr/\|/usr/[^/]*/\|/opt/[^/]*/\)\(include\|lib\)@\1$root\2\3@'"
197 var_append CPP_WRAPPER_FILTER '|' \
198 "sed -e 's@^\(-[I]\)*\(/\|/usr/\|/usr/[^/]*/\|/opt/[^/]*/\)\(include\|lib\)@\1$root\2\3@'"
200 hook_add prepare 5 gcc_sysroot_filter
202 # Inject -fPIC if the package is marked to need a quirk ...
204 hasflag FPIC-QUIRK && var_append GCC_WRAPPER_APPEND ' ' '-fPIC'
206 # Build with LTO, if not disabled for this package
208 if [ "$SDECFG_LTO" == 1 ]; then
210 var_append GCC_WRAPPER_INSERT " " "conftest.*?:-flto=${SDECFG_PARALLEL_MAX:-auto}" ||
211 echo_warning 'LTO disabled for this package'
214 # -fcommon backward compatibility
215 hasflag FCOMMON && var_append GCC_WRAPPER_INSERT " " "-fcommon"
217 # Remove -W,l,--as-needed, some packages throw up with it...
219 if hasflag NO-AS-NEEDED; then
220 var_remove_regex GCC_WRAPPER_INSERT ' ' ".*-Wl,--as-needed"
221 var_append GCC_WRAPPER_REMOVE ' ' "-Wl,--as-needed"