1e9ce3842Safresh1#!/bin/sh 2e9ce3842Safresh1 3e5157e49Safresh1# Generate the cflags script, which is used to determine what cflags 4b8851fccSafresh1# to pass to the compiler for compiling the core perl. 5b8851fccSafresh1# 6b8851fccSafresh1# This does NOT affect the XS compilation (ext, dist, cpan) 7b8851fccSafresh1# since that uses %Config values directly. 8b8851fccSafresh1# 9b8851fccSafresh1# For example, since -Wall adds -Wunused-*, a bare -Wall (without 10b8851fccSafresh1# amending that with -Wno-unused-..., or with the PERL_UNUSED_...) 11b8851fccSafresh1# would be too much for XS code because there are too many generated 12b8851fccSafresh1# but often unused things. 13b8851fccSafresh1# 14b8851fccSafresh1# We create a temporary test C program and repeatedly compile it with 15e5157e49Safresh1# various candidate flags, and from the compiler output, determine what 16e5157e49Safresh1# flags are supported. 17b8851fccSafresh1# 18e5157e49Safresh1# From this we initialise the following variables in the cflags script: 19e5157e49Safresh1# 20b8851fccSafresh1# $myccflags (possibly edited version of $Config{ccflags}) 21e5157e49Safresh1# $warn 22e5157e49Safresh1# $stdflags 23e5157e49Safresh1# $extra 24e5157e49Safresh1# $_exe 25e5157e49Safresh1 2679cd0b9aSmillertcase $PERL_CONFIG_SH in 274a4f25f9Sdownsj'') 284a4f25f9Sdownsj if test -f config.sh; then TOP=.; 294a4f25f9Sdownsj elif test -f ../config.sh; then TOP=..; 304a4f25f9Sdownsj elif test -f ../../config.sh; then TOP=../..; 314a4f25f9Sdownsj elif test -f ../../../config.sh; then TOP=../../..; 324a4f25f9Sdownsj elif test -f ../../../../config.sh; then TOP=../../../..; 334a4f25f9Sdownsj else 344a4f25f9Sdownsj echo "Can't find config.sh."; exit 1 354a4f25f9Sdownsj fi 364a4f25f9Sdownsj . $TOP/config.sh 374a4f25f9Sdownsj ;; 384a4f25f9Sdownsjesac 39e5157e49Safresh1# This forces SH files to create target in same directory as SH file. 40e5157e49Safresh1# This is so that make depend always knows where to find SH derivatives. 414a4f25f9Sdownsjcase "$0" in 424a4f25f9Sdownsj*/*) cd `expr X$0 : 'X\(.*\)/'` ;; 434a4f25f9Sdownsjesac 447bfa9f44Smillert 457bfa9f44Smillertif test -f config_h.SH -a ! -f config.h; then 467bfa9f44Smillert . ./config_h.SH 477bfa9f44Smillert CONFIG_H=already-done 487bfa9f44Smillertfi 497bfa9f44Smillert 507bfa9f44Smillertwarn='' 517bfa9f44Smillert 527bfa9f44Smillert# Add -Wall for the core modules iff gcc and not already -Wall 537bfa9f44Smillertcase "$gccversion" in 547bfa9f44Smillert'') ;; 557bfa9f44SmillertIntel*) ;; # The Intel C++ plays gcc on TV but is not really it. 567bfa9f44Smillert*) case "$ccflags" in 577bfa9f44Smillert *-Wall*) ;; 587bfa9f44Smillert *) warn="$warn -Wall" ;; 597bfa9f44Smillert esac 607bfa9f44Smillert ;; 617bfa9f44Smillertesac 627bfa9f44Smillert 637bfa9f44Smillert# Create a test source file for testing what options can be fed to 647bfa9f44Smillert# gcc in this system; include a selection of most common and commonly 657bfa9f44Smillert# hairy include files. 667bfa9f44Smillert 677bfa9f44Smillertcat >_cflags.c <<__EOT__ 687bfa9f44Smillert#include "EXTERN.h" 697bfa9f44Smillert#include "perl.h" 707bfa9f44Smillert/* The stdio.h, errno.h, and setjmp.h should be there in any ANSI C89. */ 717bfa9f44Smillert#include <stdio.h> 727bfa9f44Smillert#include <errno.h> 737bfa9f44Smillert#include <setjmp.h> 747bfa9f44Smillert/* Just in case the inclusion of perl.h did not 757bfa9f44Smillert * pull in enough system headers, let's try again. */ 767bfa9f44Smillert#include <stdlib.h> 777bfa9f44Smillert#include <stddef.h> 787bfa9f44Smillert#include <stdarg.h> 797bfa9f44Smillert#include <limits.h> 807bfa9f44Smillert#ifdef I_DIRENT 817bfa9f44Smillert#include <dirent.h> 827bfa9f44Smillert#endif 837bfa9f44Smillert#ifdef I_UNISTD 847bfa9f44Smillert#include <unistd.h> 857bfa9f44Smillert#endif 867bfa9f44Smillert#ifdef I_SYS_TYPES 877bfa9f44Smillert#include <sys/types.h> 887bfa9f44Smillert#endif 897bfa9f44Smillert#ifdef I_SYS_PARAM 907bfa9f44Smillert#include <sys/param.h> 917bfa9f44Smillert#endif 927bfa9f44Smillert#ifdef I_SYS_RESOURCE 937bfa9f44Smillert#include <sys/resource.h> 947bfa9f44Smillert#endif 957bfa9f44Smillert#ifdef I_SYS_SELECT 967bfa9f44Smillert#include <sys/select.h> 977bfa9f44Smillert#endif 987bfa9f44Smillert#if defined(HAS_SOCKET) && !defined(VMS) && !defined(WIN32) /* See perl.h. */ 997bfa9f44Smillert#include <sys/socket.h> 1007bfa9f44Smillert#endif 1017bfa9f44Smillert#ifdef I_SYS_STAT 1027bfa9f44Smillert#include <sys/stat.h> 1037bfa9f44Smillert#endif 1047bfa9f44Smillert#ifdef I_SYS_TIME 1057bfa9f44Smillert#include <sys/time.h> 1067bfa9f44Smillert#endif 1077bfa9f44Smillert#ifdef I_SYS_TIMES 1087bfa9f44Smillert#include <sys/times.h> 1097bfa9f44Smillert#endif 1107bfa9f44Smillert#ifdef I_SYS_WAIT 1117bfa9f44Smillert#include <sys/wait.h> 1127bfa9f44Smillert#endif 1137bfa9f44Smillert/* The gcc -ansi can cause a lot of noise in Solaris because of: 1147bfa9f44Smillert /usr/include/sys/resource.h:148: warning: 'struct rlimit64' declared inside parameter list 1157bfa9f44Smillert */ 1167bfa9f44Smillertint main(int argc, char *argv[]) { 1177bfa9f44Smillert 1187bfa9f44Smillert/* Add here test code found to be problematic in some gcc platform. */ 1197bfa9f44Smillert 1207bfa9f44Smillert/* Off_t/off_t is a struct in Solaris with largefiles, and with gcc -ansi 1217bfa9f44Smillert * that struct cannot be compared in some gcc releases with a flat 1227bfa9f44Smillert * integer, such as a STRLEN. */ 1237bfa9f44Smillert 1247bfa9f44Smillert IV iv; 1257bfa9f44Smillert Off_t t0a = 2; 1267bfa9f44Smillert STRLEN t0b = 3; 127b8851fccSafresh1 int t0c = (STRLEN)t0a == t0b; 128b8851fccSafresh1 129b8851fccSafresh1 printf("%s: %d\n", argv[0], argc); 1307bfa9f44Smillert 1317bfa9f44Smillert/* In FreeBSD 6.2 (and probably other releases too), with -Duse64bitint, 1327bfa9f44Smillert perl will use atoll(3). However, that declaration is hidden in <stdlib.h> 1337bfa9f44Smillert if we force the compiler to use -std=c89 mode. 1347bfa9f44Smillert*/ 1357bfa9f44Smillert iv = Atol("42"); 1367bfa9f44Smillert 1377bfa9f44Smillert return (!t0c && (iv == 42)) ? 0 : -1; /* Try to avoid 'unused' warnings. */ 1387bfa9f44Smillert} 1397bfa9f44Smillert__EOT__ 1407bfa9f44Smillert 1417bfa9f44Smillertstdflags='' 1427bfa9f44Smillert 1437bfa9f44Smillert# Further gcc warning options. Build up a list of options that work. 1447bfa9f44Smillert# Note that some problems may only show up with combinations of options, 1457bfa9f44Smillert# e.g. a warning might show up only with -Wall -ansi, not with either 1467bfa9f44Smillert# one individually. 1477bfa9f44Smillert# TODO: Ponder whether to migrate this back to Configure so hints files can 1487bfa9f44Smillert# tweak it. Also, be paranoid about whether results we've deduced in Configure 149eac174f2Safresh1# will still be valid if we now add flags like -std=c99. 1507bfa9f44Smillert 151b8851fccSafresh1pedantic='' 152b8851fccSafresh1case "$gccansipedantic" in 153b8851fccSafresh1define) pedantic='-pedantic' ;; 154b8851fccSafresh1esac 155b8851fccSafresh1 1567bfa9f44Smillertcase "$gccversion" in 1577bfa9f44Smillert'') ;; 15898dafc01Safresh1[12].*) ;; # gcc versions 1 (gasp!) and 2 are not good for this. 1597bfa9f44SmillertIntel*) ;; # # Is that you, Intel C++? 160b8851fccSafresh1# 161eac174f2Safresh1# These comments are adapted from the originals, which were for -std=c89. 162eac174f2Safresh1# I believe that my updates close to correct, and better than throwing the 163eac174f2Safresh1# entire comments away, but please check for discrepencies. 164eac174f2Safresh1# 165eac174f2Safresh1# NOTE 1: the -std=c99 without -pedantic is a bit pointless. 166eac174f2Safresh1# Just -std=c99 means "if there is room for interpretation, 167eac174f2Safresh1# interpret the C99 way." It does NOT mean "strict C99" on its own. 168b8851fccSafresh1# You need to add the -pedantic for that. To do this with Configure, 169eac174f2Safresh1# do -Dgccansipedantic (note that this is named from the time when we also 170eac174f2Safresh1# added the -ansi option. That forces -std=c89, so we no longer use it.) 171eac174f2Safresh1# *Because* we aren't adding -std=c99 if we don't have to, but will add -W, 172eac174f2Safresh1# some versions of gcc will accept C99 code but warn about not-C89 features. 173eac174f2Safresh1# (If we added -std=c99 then the warnings enabled by -W would be consistent) 174eac174f2Safresh1# Hence we add -Wno-long-long and -Wno-declaration-after-statement to cover 175eac174f2Safresh1# these cases. 176b8851fccSafresh1# 177b8851fccSafresh1# NOTE 2: -pedantic necessitates adding a couple of flags: 178b8851fccSafresh1# * -PERL_GCC_PEDANTIC so that the perl code can adapt: there's nothing 179b8851fccSafresh1# added by gcc itself to indicate pedanticness. 180b8851fccSafresh1# * -Wno-overlength-strings under -DDEBUGGING because quite many of 181b8851fccSafresh1# the LEAVE_with_name() and assert() calls generate string literals 182eac174f2Safresh1# longer then the ANSI C99 minimum of 4095 bytes. 183b8851fccSafresh1# 184b8851fccSafresh1# NOTE 3: the relative order of these options matters: 185b8851fccSafresh1# -Wextra before -W 186eac174f2Safresh1# -W before -Wno-long-long -Wno-declaration-after-statement 187b8851fccSafresh1# 188eac174f2Safresh1*) warns="$pedantic \ 1899f11ffb7Safresh1 -Werror=pointer-arith \ 190eac174f2Safresh1 -Werror=vla \ 191b8851fccSafresh1 -Wextra -W \ 192eac174f2Safresh1 -Wno-long-long -Wno-declaration-after-statement \ 19356d68f1eSafresh1 -Wc++-compat -Wwrite-strings" 194eac174f2Safresh1 case " $ccflags " in 195eac174f2Safresh1 *" -std="*) ;; # Already have -std=... 196eac174f2Safresh1 *) warns="-std=c99 $warns" ;; 19756d68f1eSafresh1 esac 19856d68f1eSafresh1 for opt in $warns 1997bfa9f44Smillert do 2007bfa9f44Smillert case " $ccflags " in 2017bfa9f44Smillert *" $opt "*) ;; # Skip if already there. 2027bfa9f44Smillert *) rm -f _cflags$_exe 203b8851fccSafresh1 flags="-DPERL_NO_INLINE_FUNCTIONS $ccflags $warn $stdflags $opt" 204b8851fccSafresh1 case "$opt" in 205b8851fccSafresh1 *-pedantic*) flags="$flags -DPERL_GCC_PEDANTIC" ;; 206b8851fccSafresh1 esac 207b8851fccSafresh1 # echo "opt = $opt, flags = $flags" 208b8851fccSafresh1 cmd="$cc $flags _cflags.c -o _cflags$_exe" 209b8851fccSafresh1 out="`$cmd 2>&1`" 210b8851fccSafresh1 # echo "$cmd --> $out" 211b8851fccSafresh1 case "$out" in 2127bfa9f44Smillert *"unrecognized"*) ;; 213b8851fccSafresh1 *"unknown"*) ;; 2147bfa9f44Smillert *"implicit declaration"*) ;; # Was something useful hidden? 2157bfa9f44Smillert *"Invalid"*) ;; 2167bfa9f44Smillert *"is valid for C"*) ;; 2177bfa9f44Smillert *) if test -x _cflags$_exe 2187bfa9f44Smillert then 2197bfa9f44Smillert case "$opt" in 220b8851fccSafresh1 -std*) 221b8851fccSafresh1 echo "cflags.SH: Adding $opt." 222b8851fccSafresh1 stdflags="$stdflags $opt" 223b8851fccSafresh1 ;; 224b8851fccSafresh1 -W) 225b8851fccSafresh1 # -Wextra is the modern form of -W, so add 226b8851fccSafresh1 # -W only if -Wextra is not there already. 227b8851fccSafresh1 case " $warn " in 228b8851fccSafresh1 *-Wextra*) ;; 229b8851fccSafresh1 *) 230b8851fccSafresh1 echo "cflags.SH: Adding $opt." 231b8851fccSafresh1 warn="$warn $opt" 232b8851fccSafresh1 ;; 233b8851fccSafresh1 esac 234b8851fccSafresh1 ;; 2359f11ffb7Safresh1 -Werror=pointer-arith) 2369f11ffb7Safresh1 # -pedantic* covers -Werror=p-a 2379f11ffb7Safresh1 case "$warn" in 2389f11ffb7Safresh1 *-pedantic*) ;; 239b8851fccSafresh1 *) 240b8851fccSafresh1 echo "cflags.SH: Adding $opt." 241b8851fccSafresh1 warn="$warn $opt" 242b8851fccSafresh1 ;; 243b8851fccSafresh1 esac 2449f11ffb7Safresh1 ;; 2459f11ffb7Safresh1 *) 2469f11ffb7Safresh1 echo "cflags.SH: Adding $opt." 2479f11ffb7Safresh1 warn="$warn $opt" 2489f11ffb7Safresh1 ;; 2497bfa9f44Smillert esac 2507bfa9f44Smillert fi 2517bfa9f44Smillert ;; 2527bfa9f44Smillert esac 2537bfa9f44Smillert ;; 2547bfa9f44Smillert esac 255b8851fccSafresh1 case "$ccflags$warn" in 256b8851fccSafresh1 *-pedantic*) 257b8851fccSafresh1 overlength='' 258b8851fccSafresh1 case "$ccflags$optimize" in 259b8851fccSafresh1 *-DDEBUGGING*) overlength='-Wno-overlength-strings' ;; 260b8851fccSafresh1 esac 261b8851fccSafresh1 for opt2 in -DPERL_GCC_PEDANTIC $overlength 262b8851fccSafresh1 do 263b8851fccSafresh1 case "$ccflags$warn" in 264b8851fccSafresh1 *"$opt2"*) ;; 265b8851fccSafresh1 *) echo "cflags.SH: Adding $opt2 because of -pedantic." 266b8851fccSafresh1 warn="$warn $opt2" ;; 267b8851fccSafresh1 esac 268b8851fccSafresh1 done 269b8851fccSafresh1 ;; 270b8851fccSafresh1 esac 2717bfa9f44Smillert done 2727bfa9f44Smillert ;; 2737bfa9f44Smillertesac 2747bfa9f44Smillertrm -f _cflags.c _cflags$_exe 2757bfa9f44Smillert 2767bfa9f44Smillertcase "$gccversion" in 2777bfa9f44Smillert'') ;; 2787bfa9f44Smillert*) 279b8851fccSafresh1 case "$warn$ccflags" in 280b8851fccSafresh1 *-pedantic*) 281eac174f2Safresh1 # For -std=c99 -pedantic, only the %Ld format seems to be warn-worthy. 282eac174f2Safresh1 # 'long long' and '%lld' are now kosher. 283b8851fccSafresh1 # 284b8851fccSafresh1 # usedtrace (DTrace) uses unportable features (dollars in identifiers, 285b8851fccSafresh1 # and gcc statement expressions), it is just easier to turn off pedantic. 286b8851fccSafresh1 remove='' 287b8851fccSafresh1 case "$quadtype:$ivtype:$sPRId64:$usedtrace" in 288eac174f2Safresh1 **Ld*) remove='Ld' ;; 289b8851fccSafresh1 *) case "$usedtrace" in 290b8851fccSafresh1 define) remove='usedtrace' ;; 291b8851fccSafresh1 esac 292b8851fccSafresh1 ;; 293b8851fccSafresh1 esac 294b8851fccSafresh1 case "$remove" in 295b8851fccSafresh1 '') ;; 296eac174f2Safresh1 *) echo "cflags.SH: Removing -pedantic* -ansi because of $remove." 297eac174f2Safresh1 ccflags=`echo $ccflags|sed -e 's/-pedantic-errors/ /' -e 's/-pedantic/ /'` 298eac174f2Safresh1 warn=`echo $warn|sed -e 's/-pedantic-errors/ /' -e 's/-pedantic/ /'` 2997bfa9f44Smillert ;; 3007bfa9f44Smillert esac 301b8851fccSafresh1 ;; 3027bfa9f44Smillert esac 3037bfa9f44Smillert ;; 3047bfa9f44Smillertesac 3057bfa9f44Smillert 306b8851fccSafresh1# Older clang releases are not wise enough for -Wunused-value. 307b8851fccSafresh1case "$gccversion" in 308b8851fccSafresh1*"Apple LLVM "[34]*|*"Apple LLVM version "[34]*) 309b8851fccSafresh1 for f in -Wno-unused-value 310b8851fccSafresh1 do 311b8851fccSafresh1 echo "cflags.SH: Adding $f because clang version '$gccversion'" 312b8851fccSafresh1 warn="$warn $f" 313b8851fccSafresh1 done 314b8851fccSafresh1 ;; 315b8851fccSafresh1esac 316b8851fccSafresh1 317b8851fccSafresh1# The quadmath Q format specifier will cause -Wformat to whine. 318b8851fccSafresh1case "$gccversion" in 319b8851fccSafresh1'') ;; 320b8851fccSafresh1*) case "$usequadmath" in 321b8851fccSafresh1 define) 322b8851fccSafresh1 for f in -Wno-format 323b8851fccSafresh1 do 324b8851fccSafresh1 echo "cflags.SH: Adding $f because of usequadmath." 325b8851fccSafresh1 warn="$warn $f" 326b8851fccSafresh1 done 327b8851fccSafresh1 ;; 328b8851fccSafresh1 esac 329b8851fccSafresh1 ;; 330b8851fccSafresh1esac 331b8851fccSafresh1 332b8851fccSafresh1case "$cc" in 333b8851fccSafresh1*g++*) 334b8851fccSafresh1 # Extra paranoia in case people have bad canned ccflags: 335b8851fccSafresh1 # bad in the sense that the flags are accepted by g++, 336b8851fccSafresh1 # but then whined about. 337eac174f2Safresh1 for f in -Wc++-compat -std=c99 338b8851fccSafresh1 do 339b8851fccSafresh1 case "$ccflags$warn" in 340b8851fccSafresh1 *"$f"*) 341b8851fccSafresh1 echo "cflags.SH: Removing $f because of g++." 342b8851fccSafresh1 ccflags=`echo $ccflags|sed 's/$f/ /'` 343b8851fccSafresh1 warn=`echo $warn|sed 's/$f/ /'` 344b8851fccSafresh1 ;; 345b8851fccSafresh1 esac 346b8851fccSafresh1 done 347b8851fccSafresh1 ;; 348b8851fccSafresh1esac 349b8851fccSafresh1 350eac174f2Safresh1for f in -Wpointer-arith -Werror=pointer-arith 351b8851fccSafresh1do 352b8851fccSafresh1 case "$cppflags" in 353b8851fccSafresh1 *"$f"*) 354b8851fccSafresh1 echo "cflags.SH: Removing $f from cppflags." 355b8851fccSafresh1 cppflags=`echo $cppflags|sed 's/$f/ /'` ;; 356b8851fccSafresh1 esac 357b8851fccSafresh1done 358b8851fccSafresh1 359b8851fccSafresh1# If usethreads and clang, add -Wthread-safety for clang 3.6 or later. 360b8851fccSafresh1# gccversion is defined also for clang, because compat, use that for matching. 361b8851fccSafresh1# Apple overwrites clang version with XCode version, see hints/darwin.sh 362b8851fccSafresh1# for the gory details. Aggressively forward-proofing. 363b8851fccSafresh1case "$usethreads" in 364b8851fccSafresh1define) 365b8851fccSafresh1case "$gccversion" in 366b8851fccSafresh1*" Clang 3."[56789]*|*" Clang "[456]*|*"Apple LLVM 6.1"*|*"Apple LLVM "[789]*) 367b8851fccSafresh1 for f in -Wthread-safety 368b8851fccSafresh1 do 369b8851fccSafresh1 case " $warn " in 370b8851fccSafresh1 *" $f "*) ;; # Skip if already there. 371b8851fccSafresh1 *) 372b8851fccSafresh1 echo "cflags.SH: Adding $f because usethreads and clang and gccversion '$gccversion'" 373b8851fccSafresh1 warn="$warn $f" 374b8851fccSafresh1 ;; 375b8851fccSafresh1 esac 376b8851fccSafresh1 done 377b8851fccSafresh1;; 378b8851fccSafresh1esac 379b8851fccSafresh1;; 380b8851fccSafresh1esac 381b8851fccSafresh1 382*e0680481Safresh1# gcc version 12 and 13 are overly aggressive with use-after-free warnings 383*e0680481Safresh1# and have false positives on code that shouldn't warn, and they haven't 384*e0680481Safresh1# sorted it out yet. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108115 385*e0680481Safresh1case "$gccversion" in 386*e0680481Safresh1"1"[23]*) 387*e0680481Safresh1 for f in -Wno-use-after-free 388*e0680481Safresh1 do 389*e0680481Safresh1 echo "cflags.SH: Adding $f because of false positives in gccversion '$gccversion'" 390*e0680481Safresh1 warn="$warn $f" 391*e0680481Safresh1 done 392*e0680481Safresh1;; 393*e0680481Safresh1esac 394*e0680481Safresh1 395b8851fccSafresh1echo "cflags.SH: cc = $cc" 396b8851fccSafresh1echo "cflags.SH: ccflags = $ccflags" 397b8851fccSafresh1echo "cflags.SH: stdflags = $stdflags" 398b8851fccSafresh1echo "cflags.SH: optimize = $optimize" 399b8851fccSafresh1echo "cflags.SH: warn = $warn" 400b8851fccSafresh1 4017bfa9f44Smillert# Code to set any extra flags here. 4027bfa9f44Smillertextra='' 4037bfa9f44Smillert 404b8851fccSafresh1# Protect double or single quotes for better restoring of ccflags. 405b8851fccSafresh1myccflags=`echo $ccflags | sed -e 's/"/\\\"/g' -e "s/'/\\\'/g"` 406b8851fccSafresh1 4074a4f25f9Sdownsjecho "Extracting cflags (with variable substitutions)" 408e5157e49Safresh1# This section of the file will have variable substitutions done on it. 409e5157e49Safresh1# Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!. 410e5157e49Safresh1# Protect any dollar signs and backticks that you do not want interpreted 411e5157e49Safresh1# by putting a backslash in front. You may delete these comments. 412ba47ec9dSmillertrm -f cflags 4134a4f25f9Sdownsj$spitshell >cflags <<!GROK!THIS! 4144a4f25f9Sdownsj$startsh 4157bfa9f44Smillert 416e5157e49Safresh1# !!!!!!! DO NOT EDIT THIS FILE !!!!!!! 417e5157e49Safresh1 418e5157e49Safresh1# This file is generated by cflags.SH 419e5157e49Safresh1 420b8851fccSafresh1# Used to restore possible edits by cflags.SH. 421b8851fccSafresh1myccflags="$myccflags" 422e5157e49Safresh1 4237bfa9f44Smillert# Extra warnings, used e.g. for gcc. 4247bfa9f44Smillertwarn="$warn" 4257bfa9f44Smillert# Extra standardness. 4267bfa9f44Smillertstdflags="$stdflags" 4277bfa9f44Smillert# Extra extra. 4287bfa9f44Smillertextra="$extra" 429df042708Smillert# what do executables look like? 430df042708Smillert_exe="$_exe" 4317bfa9f44Smillert 4324a4f25f9Sdownsj!GROK!THIS! 4334a4f25f9Sdownsj 434e5157e49Safresh1# In the following dollars and backticks do not need the extra backslash. 4354a4f25f9Sdownsj$spitshell >>cflags <<'!NO!SUBS!' 43679cd0b9aSmillertcase $PERL_CONFIG_SH in 4374a4f25f9Sdownsj'') 4384a4f25f9Sdownsj if test -f config.sh; then TOP=.; 4394a4f25f9Sdownsj elif test -f ../config.sh; then TOP=..; 4404a4f25f9Sdownsj elif test -f ../../config.sh; then TOP=../..; 4414a4f25f9Sdownsj elif test -f ../../../config.sh; then TOP=../../..; 4424a4f25f9Sdownsj elif test -f ../../../../config.sh; then TOP=../../../..; 4434a4f25f9Sdownsj else 4444a4f25f9Sdownsj echo "Can't find config.sh."; exit 1 4454a4f25f9Sdownsj fi 4464a4f25f9Sdownsj . $TOP/config.sh 447b8851fccSafresh1 ccflags="$myccflags" # Restore possible edits by cflags.SH. 4484a4f25f9Sdownsj ;; 4494a4f25f9Sdownsjesac 4504a4f25f9Sdownsj 451e5157e49Safresh1# syntax: cflags [optimize=XXX] [file[.suffix]] ... 452e5157e49Safresh1# displays the proposed compiler command line for each 'file' 453e5157e49Safresh1# 454e5157e49Safresh1# with no file, dispalys it for all *.c files. 455e5157e49Safresh1# The optimise=XXX arg (if present) is evalled, setting the default 456e5157e49Safresh1# value of the $optimise variable, which is output on the command line 457e5157e49Safresh1# (but which may be overridden for specific files below) 45879cd0b9aSmillert 45979cd0b9aSmillertcase "X$1" in 46079cd0b9aSmillertXoptimize=*|X"optimize=*") 46179cd0b9aSmillert eval "$1" 46279cd0b9aSmillert shift 46379cd0b9aSmillert ;; 4644a4f25f9Sdownsjesac 4654a4f25f9Sdownsj 4664a4f25f9Sdownsjcase $# in 4674a4f25f9Sdownsj0) set *.c; echo "The current C flags are:" ;; 4684a4f25f9Sdownsjesac 4694a4f25f9Sdownsj 470e2e5c5d3Smillertset `echo "$* " | sed -e 's/\.[oc] / /g' -e 's/\.obj / /g' -e "s/\\$obj_ext / /g"` 4714a4f25f9Sdownsj 4724a4f25f9Sdownsjfor file do 4734a4f25f9Sdownsj 4744a4f25f9Sdownsj case "$#" in 4754a4f25f9Sdownsj 1) ;; 4764a4f25f9Sdownsj *) echo $n " $file.c $c" ;; 4774a4f25f9Sdownsj esac 4784a4f25f9Sdownsj 479e5157e49Safresh1 # allow variables like toke_cflags to be evaluated 4804a4f25f9Sdownsj 4819f11ffb7Safresh1 case "$file" in 4829f11ffb7Safresh1 */*) ;; 4839f11ffb7Safresh1 *) eval 'eval ${'"${file}_cflags"'-""}' ;; 4849f11ffb7Safresh1 esac 4854a4f25f9Sdownsj 486e5157e49Safresh1 # or customize here 4874a4f25f9Sdownsj 4884a4f25f9Sdownsj case "$file" in 489b8851fccSafresh1 regcomp) : work around http://bugs.debian.org/754054 490b8851fccSafresh1 case $archname in 491b8851fccSafresh1 mips-*|mipsel-*) 492b8851fccSafresh1 optimize="$optimize -fno-tree-vrp";; 493b8851fccSafresh1 esac;; 4944a4f25f9Sdownsj *) ;; 495e9ce3842Safresh1 496b8851fccSafresh1 # Customization examples follow. 497b8851fccSafresh1 # 498b8851fccSafresh1 # The examples are intentionally unreachable as the '*)' case above always 499e5157e49Safresh1 # matches. To use them, move before the '*)' and edit as appropriate. 500e5157e49Safresh1 # It is not a good idea to set ccflags to an absolute value here, as it 501e5157e49Safresh1 # often contains general -D defines which are needed for correct 502e5157e49Safresh1 # compilation. It is better to edit ccflags as shown, using interpolation 503e5157e49Safresh1 # to add flags, or sed to remove flags. 504e9ce3842Safresh1 505b8851fccSafresh1 av) ccflags=`echo $ccflags | sed -e s/-pipe//` ;; 506b8851fccSafresh1 deb) ccflags="$ccflags -fno-jump-tables" ;; 507b8851fccSafresh1 hv) warn=`echo $warn | sed -e s/-Wextra//` ;; 508b8851fccSafresh1 toke) optimize=-O0 ;; 5097bfa9f44Smillert esac 5107bfa9f44Smillert 5117bfa9f44Smillert echo "$cc -c -DPERL_CORE $ccflags $stdflags $optimize $warn $extra" 5124a4f25f9Sdownsj 5134a4f25f9Sdownsj . $TOP/config.sh 5144a4f25f9Sdownsj 515df042708Smillert # end per file behaviour 5164a4f25f9Sdownsjdone 5174a4f25f9Sdownsj!NO!SUBS! 5184a4f25f9Sdownsjchmod 755 cflags 5194a4f25f9Sdownsj$eunicefix cflags 520