summaryrefslogtreecommitdiff
path: root/APACHE_1_3_42/src/helpers/TestCompile
blob: ff8a4bc53170e9b011f3a21d152193f0429c8e2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/bin/sh
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
exstat=1
trap 'rm -f Makefile dummy ../dummy.o dummy.exe testfunc.c testfunc ../testfunc.o testfunc.exe; exit $exstat' 0 1 2 3 15
#
# Yet another Apache Configure helper script.
# This script tests certain aspects of the compilation
# process. Right now, it can perform 5 tests:
#
# ./helpers/TestCompile lib <libname>
#    Which checks to see if <libname> exists on this system
#
# ./helpers/TestCompile lib <libname> <func>
#    Which checks to see if <libname> exists on this system and
#    contains func.
#
# ./helpers/TestCompile func <function>
#    Which checks to see if <function> exists
#
# ./helpers/TestCompile header <header>
#    Which checks to see if header file <header> exists
#
# ./helpers/TestCompile sanity
#    Which does a simple sanity check/test compile
#
# ./helpers/TestCompile sizeof <type>
#    Which prints out the sizeof <type> (sure would be nice
#    if sizeof could be use in preprocessor if's)
#
# ./helpers/TestCompile byteorder
#    Which prints out the byte order of the machine
#    (12: little endian, 21: big endian)
#
# It does these by creating a small mini-makefile, based on
# ../Makefile.config and trying to compile a small dummy
# program. If the compilation succeeds, we assume the test
# was successful as well.
#
# This must be run as './helpers/TestCompile' from
# the ./src directory (same directory that Configure is
# located) if you want to test it out. Configure must
# also call it as './helpers/TestCompile'
#
#
# INVOCATION SWITCHES:
# TestCompile evaluates the following switches
# (currently, it accepts only *ONE* of them!):
#
#  -v (enable verbose operation)
#   Enables VERBOSE=yes, see below.
#
#  -s (enforce silent operation)
#   Override a VERBOSE=yes, force it to VERBOSE=no.
#
#  -r (run generated test program)
#   Enables TCRUNIT=yes, see below
#
#  
# ENVIRONMENT VARIABLES:
# The following environment variables have influence on
# TestCompile's operation:
#
#  $VERBOSE (yes|no; default=no)
#    If set to "yes", will print compiler messages to stderr
#    Otherwise, stderr of all invoked programs is sent to /dev/null
#
#  $TCRUNIT (yes|no; default=no)
#    (This variable is obsoleted by the "-r" switch)
#    If set to "yes", will invoke the test program which was
#    generated by TestCompile. Useful for "TestCompile sizeof"
#    and "TestCompile byteorder" tests.
#    Otherwise, TestCompile only tests for the presence of a
#    generated program when deciding whether the compilation was
#    successful.
#
#  $TCADDINCL (#include <> stmt list; default=empty)
#    If set to an "#include <file>" preprocessor directive
#    (optionally several #include's separated by newlines), these
#    directives will be added to the generated test sources.
#    That allows, e.g., the "TestCompile sizeof" test to check for
#    types which are not defined in the standard locations.
#
#  $TLIB (additional libraries; default=empty)
#    If set to a list of additional libraries, these libs will be used
#    in addition to the one tested by the "TestCompile lib" call.
#    For the other TestCompile tests, it is ignored.
#
#
# Initially written by Jim Jagielski for the Apache configuration mechanism
#
# This script falls under the Apache License.
# See http://www.apache.org/docs/LICENSE


cd ./helpers

#
# Handle "verbose", "silent" and "runit" flags. Allow for them
# to be set via the environment
#
if [ "x$VERBOSE" = "x" ]; then
    VERBOSE="no"
fi
if [ "x$TCRUNIT" = "x" ]; then
    TCRUNIT="no";
fi
case "$1" in
    "-v")
        VERBOSE="yes"
	shift
	;;
    "-s")
        VERBOSE="no"
	shift
	;;
    "-r")
        TCRUNIT="yes"
	shift
	;;
esac

#
# Make sure we have the right arguments
#

case "$1" in
    "lib")
	if [ "x$2" = "x" ]; then
	    exit
	fi
	TLIB="-l$2 $TLIB"
	if [ "x$VERBOSE" = "xyes" ]; then
	    ERRDIR=""
	else
	    ERRDIR='2>/dev/null'
	fi
	if [ "x$3" = "x" ]; then
	    TARGET='dummy'
	else
	    TARGET='testfunc'
	    echo "int main(void) { $3(); return(0); }" > testfunc.c
	fi
	;;
    "sizeof")
	if [ "x$2" = "x" ]; then
	    exit
	fi
	TLIB=""
	if [ "x$VERBOSE" = "xyes" ]; then
	    ERRDIR=""
	else
	    ERRDIR='2>/dev/null'
	fi
	TARGET='testfunc'
	cat <<EOF >testfunc.c
#include <stdio.h>
#include <sys/types.h>
$TCADDINCL
int main(void) {
    printf("%d\n", sizeof($2));
    return(0);
}
EOF
	;;
    "byteorder")
	TLIB=""
	if [ "x$VERBOSE" = "xyes" ]; then
	    ERRDIR=""
	else
	    ERRDIR='2>/dev/null'
	fi
	TARGET='testfunc'
	cat <<EOF >testfunc.c
#include <stdio.h>
#include <sys/types.h>
$TCADDINCL
int main(void) {
    /* Are we little or big endian? From Harbison & Steele */
    union {
        long l;
        char c[sizeof(long)];
    } u;
    u.l = 1;
    printf("%s\n", u.c[sizeof(long)-1] == 1 ? "21" : "12");
    return(0);
}
EOF
	;;
    "sanity")
	TLIB=""
	if [ "x$VERBOSE" = "xno" ]; then
	    ERRDIR='2>/dev/null'
	else
	    ERRDIR=""
	fi
	TARGET='dummy'
	;;
    "func")
	if [ "x$2" = "x" ]; then
	    exit
	fi
	TLIB=""
	if [ "x$VERBOSE" = "xyes" ]; then
	    ERRDIR=""
	else
	    ERRDIR='2>/dev/null'
	fi
	TARGET='testfunc'
	cat <<EOF >testfunc.c
$TCADDINCL
int main(void) {
    $2();
    return(0);
}
EOF
	;;
    "header")
	if [ "x$2" = "x" ]; then
	    exit
	fi
	TLIB=""
	if [ "x$VERBOSE" = "xyes" ]; then
	    ERRDIR=""
	else
	    ERRDIR='2>/dev/null'
	fi
	TARGET='testfunc'
	cat <<EOF >testfunc.c
$TCADDINCL
#include <$2>
int main(void) {
    return(0);
}
EOF
	;;
    *)
    	exit
	;;
esac

#
# Get makefile settings and build a basic Makefile
#
rm -f dummy ../dummy.o testfunc ../testfunc.o

cat ../Makefile.config > Makefile
cat <<EOF >> Makefile
CFLAGS=\$(OPTIM) \$(CFLAGS1) \$(EXTRA_CFLAGS)
LIBS=\$(EXTRA_LIBS) \$(LIBS1)
INCLUDES=\$(INCLUDES1) \$(EXTRA_INCLUDES)
LDFLAGS=\$(LDFLAGS1) \$(EXTRA_LDFLAGS)

dummy:
	cd ..; \$(CC) \$(CFLAGS) \$(INCLUDES) \$(LDFLAGS) -o helpers/dummy helpers/dummy.c $TLIB \$(LIBS)

testfunc:
	cd ..; \$(CC) \$(CFLAGS) \$(INCLUDES) \$(LDFLAGS) -o helpers/testfunc helpers/testfunc.c $TLIB \$(LIBS)
EOF

# Now run that Makefile
eval "${MAKE-make} ${TARGET} $ERRDIR >&2"

# And see if dummy exists and is executable, if so, then we
# assume the condition we are testing for is good
#
# Use our PrintPath helper script using the "-p" option to
# have PrintPath just search this directory.

if ./PrintPath -s -p`pwd` $TARGET ; then
    if [ "x$OS" = "xMPE/iX" ]; then
	# clever hack to check for unresolved externals without actually
	# executing the test program 
	if eval "callci run `pwd`/$TARGET\;stdin=\*notfound 2>&1 | /bin/grep ^UNRESOLVED $ERRDIR >&2"; then
	    exit 1 # there were unresolved externals
	fi
    fi
    if [ "x$TCRUNIT" = "xyes" ]; then
	`pwd`/$TARGET
    fi
    exstat=0
fi