Band-aid for segfault in ext/threads/t/blocks.t on SMP machines
[p5sagit/p5-mst-13.2.git] / cflags.SH
1 case $PERL_CONFIG_SH in
2 '')
3         if test -f config.sh; then TOP=.;
4         elif test -f ../config.sh; then TOP=..;
5         elif test -f ../../config.sh; then TOP=../..;
6         elif test -f ../../../config.sh; then TOP=../../..;
7         elif test -f ../../../../config.sh; then TOP=../../../..;
8         else
9                 echo "Can't find config.sh."; exit 1
10         fi
11         . $TOP/config.sh
12         ;;
13 esac
14 : This forces SH files to create target in same directory as SH file.
15 : This is so that make depend always knows where to find SH derivatives.
16 case "$0" in
17 */*) cd `expr X$0 : 'X\(.*\)/'` ;;
18 esac
19
20 warn=''
21
22 # Add -Wall for the core modules iff gcc and not already -Wall
23 case "$gccversion" in
24 '') ;;
25 Intel*) ;; # The Intel C++ plays gcc on TV but is not really it.
26 *)  case "$ccflags" in
27     *-Wall*) ;;
28     *) warn="$warn -Wall" ;;
29     esac
30     ;;
31 esac
32
33 # The gcc -ansi -pedantic require their own dance, too.
34 case "$gccversion" in
35 '') ;;
36 Intel*) ;; # Is that you, Intel C++?
37 *)  case "$gccansipedantic" in
38     define)
39         case "$gccversion" in
40         [12]*) ;; # gcc versions 1 (gasp!) and 2 are not good for this.
41         *)  case "$osname" in
42             # Add -ansi -pedantic only for known platforms.
43             aix|dec_osf|freebsd|hpux|irix|linux)
44                 ansipedantic="-ansi -pedantic" ;;
45             solaris)
46 # Can't add -ansi for Solaris.
47 # Off_t/off_t is a struct in Solaris with largefiles, and with -ansi
48 # that struct cannot be compared with a flat integer, such as a STRLEN.
49 # The -ansi will also cause a lot of noise in Solaris because of:
50 # /usr/include/sys/resource.h:148: warning: `struct rlimit64' declared inside parameter list
51                 ansipedantic="-pedantic" ;;
52             esac
53             for i in $ansipedantic
54             do
55                 case "$ccflags" in
56                 *$i*) ;;
57                 *) warn="$warn $i" ;;
58                 esac
59             done
60             case "$warn$ccflags" in
61             *-pedantic*) warn="$warn -DPERL_GCC_PEDANTIC" ;;
62             esac
63             ;;
64         esac
65         ;;
66     esac
67     ;;
68 esac
69
70 # Further gcc warning options.
71 case "$gccversion" in
72 '') ;;
73 [12]*) ;;
74 Intel*) ;; # Haven't we been through this already?
75 *)  for opt in '' extra declaration-after-statement endif-labels
76     do
77        case " $ccflags " in
78        *"-W$opt "*) ;;
79        *) case "`echo >_cflags.c | $cc -W$opt -c _cflags.c -o _cflags.o 2>&1`" in
80           *"unrecognized"*) ;;
81           *"Invalid"*) ;;
82           *) warn="$warn -W$opt" ;;
83           esac
84           ;;
85        esac
86        rm -f _cflags.c cflags.o
87     done
88     ;;
89 esac
90
91
92 stdflags=''
93
94 echo "Extracting cflags (with variable substitutions)"
95 : This section of the file will have variable substitutions done on it.
96 : Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
97 : Protect any dollar signs and backticks that you do not want interpreted
98 : by putting a backslash in front.  You may delete these comments.
99 rm -f cflags
100 $spitshell >cflags <<!GROK!THIS!
101 $startsh
102
103 # Extra warnings, used e.g. for gcc.
104 warn="$warn"
105 # Extra standardness.
106 stdflags="$stdflags"
107
108 !GROK!THIS!
109
110 : In the following dollars and backticks do not need the extra backslash.
111 $spitshell >>cflags <<'!NO!SUBS!'
112 case $PERL_CONFIG_SH in
113 '')
114         if test -f config.sh; then TOP=.;
115         elif test -f ../config.sh; then TOP=..;
116         elif test -f ../../config.sh; then TOP=../..;
117         elif test -f ../../../config.sh; then TOP=../../..;
118         elif test -f ../../../../config.sh; then TOP=../../../..;
119         else
120                 echo "Can't find config.sh."; exit 1
121         fi
122         . $TOP/config.sh
123         ;;
124 esac
125
126 : syntax: cflags [optimize=XXX] [file[.suffix]]
127 : displays the compiler command line for file
128
129 case "X$1" in
130 Xoptimize=*|X"optimize=*")
131         eval "$1"
132         shift
133         ;;
134 esac
135
136 also=': '
137 case $# in
138 1) also='echo 1>&2 "      CCCMD = "'
139 esac
140
141 case $# in
142 0) set *.c; echo "The current C flags are:" ;;
143 esac
144
145 set `echo "$* " | sed -e 's/\.[oc] / /g' -e 's/\.obj / /g' -e "s/\\$obj_ext / /g"`
146
147 for file do
148
149     case "$#" in
150     1) ;;
151     *) echo $n "    $file.c     $c" ;;
152     esac
153
154     : allow variables like toke_cflags to be evaluated
155
156     if echo $file | grep -v / >/dev/null
157     then
158       eval 'eval ${'"${file}_cflags"'-""}'
159     fi
160
161     : or customize here
162
163     case "$file" in
164     DB_File) ;;
165     GDBM_File) ;;
166     NDBM_File) ;;
167     ODBM_File) ;;
168     POSIX) ;;
169     SDBM_File) ;;
170     av) ;;
171     byterun) ;;
172     deb) ;;
173     dl) ;;
174     doio) ;;
175     doop) ;;
176     dump) ;;
177     globals) ;;
178     gv) ;;
179     hv) ;;
180     locale) ;;
181     madly) ;;
182     main) ;;
183     malloc) ;;
184     mg) ;;
185     miniperlmain) ;;
186     numeric) ;;
187     op) ;;
188     opmini) ;;
189     pad) ;;
190     perl) ;;
191     perlapi) ;;
192     perlmain) ;;
193     perly) ;;
194     pp) ;;
195     pp_ctl) ;;
196     pp_hot) ;;
197     pp_pack) ;;
198     pp_sort) ;;
199     pp_sys) ;;
200     regcomp) ;;
201     regexec) ;;
202     run) ;;
203     scope) ;;
204     sv) ;;
205     taint) ;;
206     toke) ;;
207     universal) ;;
208     usersub) ;;
209     utf8) ;;
210     util) ;;
211     xsutils) ;;
212     *) ;;
213     esac
214
215 if test -f .patch; then
216   ccflags="-DPERL_PATCHNUM=`cat .patch` $ccflags"
217 fi
218
219     : Can we perhaps use $ansi2knr here
220     echo "$cc -c -DPERL_CORE $ccflags $stdflags $optimize $warn"
221     eval "$also "'"$cc -DPERL_CORE -c $ccflags $stdflags $optimize $warn"'
222
223     . $TOP/config.sh
224
225 done
226 !NO!SUBS!
227 chmod 755 cflags
228 $eunicefix cflags