1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/gcc/parse-config
3 # Copyright (C) 2004 - 2024 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_SSP" = 1 ]; then
16 if ! hasflag NO-SSP; then
17 var_append GCC_WRAPPER_INSERT ' ' '-fstack-protector-strong'
19 echo_warning 'Stack-Smashing Protector disabled for this package'
23 [ "$SDECFG_AUTO_VAR_INIT" = 1 ] && case $pkg in
24 gcc) : ;; # TODO: fine grained and bootloaders, too?
26 var_append GCC_WRAPPER_INSERT ' ' '-ftrivial-auto-var-init=zero' ;;
29 # It's usually better to not change the kernel optimization too drastically.
33 export KCC="${archprefix}kcc"
34 var_insert KCC_WRAPPER_REMOVE " " "-O -O[0-9sgz]"
36 # set CC, CXX and F77 environment variables
38 for x in CC CXX F77 ; do
39 eval "y=\$SDECFG_DEFAULT_$x"
40 if [[ $y = gcc* || $pkg = glibc* || $pkg = gcc || $pkg = memtest86 || $pkg = grub2 ]]; then
41 case "$x-$stagelevel" in
43 z="${archprefix}gcc ${archprefix}gcc" ;;
45 z="${archprefix}g++ ${archprefix}g++" ;;
47 z="${archprefix}g77 ${archprefix}gfortran" ;;
49 export $x=${x}_not_available_in_stage_${stagelevel}
53 [ "`type -p $y`" ] && export $x=$y
58 # Add the usual gcc optimazation options
59 # Strip or add debug information
61 debug_flags='-g -ggdb -g[0-9] -gdwarf*'
63 if [ "$SDECFG_DEBUG" = 0 ]; then
64 var_append GCC_WRAPPER_APPEND " " "-c?:-s"
65 var_insert GCC_WRAPPER_REMOVE " " "$debug_flags"
66 var_append SYSGCC_WRAPPER_APPEND " " "-c?:-s"
67 var_insert SYSGCC_WRAPPER_REMOVE " " "$debug_flags"
69 var_append GCC_WRAPPER_APPEND " " "-ggdb"
70 var_insert GCC_WRAPPER_REMOVE " " "-s $debug_flags"
71 var_append SYSGCC_WRAPPER_APPEND " " "-ggdb"
72 var_insert SYSGCC_WRAPPER_REMOVE " " "-s $debug_flags"
75 # Remove the optimization options, since we pass generic ones ... In ROCK
76 # history this has been -m*, but this caused -msse and -maltivec style options
77 # to get removed. So we better only remove a known set of -m options ...
78 var_insert GCC_WRAPPER_REMOVE " " "-O -O[0-9sgz] -mtune* -march* -mcpu* -Werror -Wextra"
79 var_insert KCC_WRAPPER_REMOVE " " "-Werror"
80 var_insert SYSGCC_WRAPPER_REMOVE " " "-O -O[0-9sgz] -mtune* -march* -mcpu* -Werror"
82 # Disable some new compiler warnings to avoid patching thousands of packages.
86 # libstdc++ breaks w/ -Wno-error?
89 var_append GCC_WRAPPER_INSERT ' ' "-Wno-error=implicit-int -Wno-error=incompatible-pointer-types"
90 var_append GCC_WRAPPER_INSERT ' ' "-Wno-error=implicit-function-declaration"
96 f="$confdir/$pkg.prof"
97 # hack mostly for glibc32, could be made more generic
98 [ -f "$f" ] || f="$confdir/../${pkg%%[0-9]*}/${pkg%%[0-9]*}.prof"
99 # TODO: or fix awk script for non existing file?
100 [ -f "$f" ] || f="/dev/null"
103 [ "$arch_sizeof_char_p" = 4 ] && basec="-Os" || basec="-O1"
104 [ "$arch_sizeof_char_p" = 4 ] && basecxx="-O1" || basecxx="-O2"
106 [ "$SDECFG_OPT" = "smartly" ] && basecxx="$basec"
107 [ "$SDECFG_OPT" = "smarter" ] && opt="-O3"
109 [ "$SDECFG_OPT" = "smartest" ] && opt="-Ofast" && kopt="-O3"
111 var_insert CC_WRAPPER_INSERT " " "$basec"
112 var_insert CXX_WRAPPER_INSERT " " "$basecxx"
113 var_insert GCC_WRAPPER_INSERT " " "-HOT$opt"
114 var_insert GCC_WRAPPER_FILTER "|" "gawk -f $base/misc/tools-source/smart_wrapper.awk $f -"
115 var_insert KCC_WRAPPER_INSERT " " "$basek -HOT$kopt"
116 var_insert KCC_WRAPPER_FILTER "|" "gawk -f $base/misc/tools-source/smart_wrapper.awk $f -"
117 var_insert SYSCC_WRAPPER_INSERT " " "$basec"
118 var_insert SYSCXX_WRAPPER_INSERT " " "$basecxx"
119 var_insert SYSGCC_WRAPPER_INSERT " " "-HOT$opt"
120 var_insert SYSGCC_WRAPPER_FILTER "|" "gawk -f $base/misc/tools-source/smart_wrapper.awk $f -"
121 unset basec basecxx basek opt kopt
124 var_insert GCC_WRAPPER_INSERT " " "-O2"
125 var_insert KCC_WRAPPER_INSERT " " "-O2"
126 var_insert SYSGCC_WRAPPER_INSERT " " "-O2"
129 var_insert GCC_WRAPPER_INSERT " " "-O3"
130 var_insert KCC_WRAPPER_INSERT " " "-O3"
131 var_insert SYSGCC_WRAPPER_INSERT " " "-O3"
134 var_insert GCC_WRAPPER_INSERT " " "-Ofast"
135 var_insert KCC_WRAPPER_INSERT " " "-Ofast"
136 var_insert SYSGCC_WRAPPER_INSERT " " "-Ofast"
139 var_insert GCC_WRAPPER_INSERT " " "-Os"
140 var_insert KCC_WRAPPER_INSERT " " "-Os"
141 var_insert SYSGCC_WRAPPER_INSERT " " "-Os"
144 var_insert GCC_WRAPPER_INSERT " " "-O1"
145 var_insert KCC_WRAPPER_INSERT " " "-O1"
146 var_insert SYSGCC_WRAPPER_INSERT " " "-O1"
149 var_insert GCC_WRAPPER_INSERT " " "-Og"
150 var_insert KCC_WRAPPER_INSERT " " "-Og"
151 var_insert SYSGCC_WRAPPER_INSERT " " "-Og"
154 var_insert GCC_WRAPPER_INSERT " " "-O0"
155 var_insert KCC_WRAPPER_INSERT " " "-O0"
156 var_insert SYSGCC_WRAPPER_INSERT " " "-O0"
160 # Add the architecture gcc optimisation options
162 if [ -f architecture/$arch/gcc-options.in ]; then
163 . architecture/$arch/gcc-options.in
166 # gcc-4.1.0 hangs with -v --help -pipe, thus we do not add it in that case
167 var_insert GCC_WRAPPER_INSERT ' ' '--help?:-pipe'
168 var_insert SYSGCC_WRAPPER_INSERT ' ' '--help?:-pipe'
170 [ "$SDECFG_LD_AS_NEEDED" != 0 ] &&
171 var_append GCC_WRAPPER_INSERT " " "-c?:-Wl,--as-needed"
174 if hasflag NO-PIE; then
175 [ "$SDECFG_PIE" == 1 ] &&
176 echo_warning 'Position-Independent Executables disabled for this package'
177 elif [ "$SDECFG_PIE" == 1 ]; then
178 case $SDECFG_STATIC in
179 0) var_append GCC_WRAPPER_INSERT " " "-fPIE -c?:-pie"
180 var_append GCC_WRAPPER_APPEND " " "-fPIC" ;;
181 1) var_append GCC_WRAPPER_INSERT " " "-fPIE -c?:-static-pie" ;;
185 var_append GCC_WRAPPER_APPEND " " "$SDECFG_C_FLAGS"
186 var_append KCC_WRAPPER_APPEND " " "$SDECFG_C_FLAGS"
188 # Compile (i.e. link) all bins statically
190 if [ "$SDECFG_STATIC" = 1 ]; then
191 var_insert GCC_WRAPPER_INSERT " " "-static"
194 # Compile with no exceptions or rtti, gcc itself must support both
196 if [ "$SDECFG_LIMITCXX" = 1 ] && [[ $pkg != gcc* ]]; then
197 var_append CXX_WRAPPER_APPEND " " "-fno-exceptions -fno-rtti"
200 # Passing -I/usr{/local/}include creates a warning in gcc3 which is confusing
201 # some of the configure scripts and Makefiles.
203 var_insert GCC_WRAPPER_REMOVE " " "-I/usr/include -I/usr/local/include"
205 # pkg-config and other output or hardcoded configure assumption
206 # do not include the "DESTDIR" we need to adapt the pathes accordingly
207 function gcc_sysroot_filter() {
208 # merge multiple path separators
209 var_append GCC_WRAPPER_FILTER '|' "sed -e 's,//*,/,g'"
211 # translate all non-$sysroot with trailing /lib and correct to $libdir
212 var_append GCC_WRAPPER_FILTER '|' \
213 "sed -e 's@^\(-[L]\|-Wl.*-rpath-link,\)*\(/\|/usr/\|/usr/[^/]*/\|/opt/[^/]*/\)\(lib\)\$@\1$root\2${libdir##*/}@'"
215 # keep any other non-$sysdir /lib* as it
216 var_append GCC_WRAPPER_FILTER '|' \
217 "sed -e 's@^\(-[L]\|-Wl.*-rpath-link,\)*\(/\|/usr/\|/usr/[^/]*/\|/opt/[^/]*/\)\(lib\)@\1$root\2\3@'"
219 # and tranlate includes, too, and yes, we need "lib" for for lib/glib/include/glibconfig.h
220 var_append GCC_WRAPPER_FILTER '|' \
221 "sed -e 's@^\(-[I]\)*\(/\|/usr/\|/usr/[^/]*/\|/opt/[^/]*/\)\(include\|lib\)@\1$root\2\3@'"
222 var_append CPP_WRAPPER_FILTER '|' \
223 "sed -e 's@^\(-[I]\)*\(/\|/usr/\|/usr/[^/]*/\|/opt/[^/]*/\)\(include\|lib\)@\1$root\2\3@'"
225 hook_add prepare 5 gcc_sysroot_filter
227 # Inject -fPIC if the package is marked to need a quirk ...
229 hasflag FPIC && var_append GCC_WRAPPER_APPEND ' ' '-fPIC'
231 # Build with LTO, if not disabled for this package
233 if [ "$SDECFG_LTO" != 1 ]; then
234 var_append GCC_WRAPPER_REMOVE " " "-flto*"
236 hasflag CUSTOM-LTO || var_append GCC_WRAPPER_REMOVE " " "-flto*"
237 if hasflag NO-LTO; then
238 echo_warning 'Link Time Optimization disabled for this package'
239 SDECFG_LTO=0 # hide from pkgs, might be conditionally disabled for $arch or $cc
240 elif ! hasflag CUSTOM-LTO; then
241 if [ "$SDECFG_DEFAULT_CC" = clang ]; then
242 var_append GCC_WRAPPER_INSERT " " "conftest*.*?:-flto=thin"
244 var_append GCC_WRAPPER_INSERT " " "conftest*.*?:-flto=${SDECFG_PARALLEL:-auto}"
245 var_append GCC_WRAPPER_INSERT " " "conftest*.*?:-shared?:-fwhole-program"
246 hasflag FAT-LTO && var_append GCC_WRAPPER_INSERT " " "-ffat-lto-objects"
251 # -fcommon backward compatibility
252 hasflag FCOMMON && var_append GCC_WRAPPER_INSERT " " "-fcommon"
254 # usually 64-bit -latomic for some architectures
255 hasflag LATOMIC && [ $arch != avr32 ] && var_append GCC_WRAPPER_INSERT ' ' '-c?:-latomic -Wl,--as-needed'
257 # Remove -Wl,--as-needed, some packages break with it...
259 if hasflag NO-AS-NEEDED; then
260 var_remove_regex GCC_WRAPPER_INSERT ' ' ".*-Wl,--as-needed"
261 var_append GCC_WRAPPER_REMOVE ' ' "-Wl,--as-needed"