This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Generate a valid config.h even if stdarg.h and varargs.h are both missing.
[metaconfig.git] / U / modified / i_varhdr.U
CommitLineData
9b04e79a 1?RCS: $Id: i_varhdr.U 1 2006-08-24 12:32:52Z rmanfredi $
0f00356b 2?RCS:
9b04e79a 3?RCS: Copyright (c) 1991-1997, 2004-2006, Raphael Manfredi
41322e17 4?RCS:
0f00356b
JH
5?RCS: You may redistribute only under the terms of the Artistic Licence,
6?RCS: as specified in the README file that comes with the distribution.
7?RCS: You may reuse parts of this distribution only within the terms of
8?RCS: that same Artistic Licence; a copy of which may be found at the root
9b04e79a 9?RCS: of the source tree for dist 4.0.
0f00356b
JH
10?RCS:
11?RCS: $Log: i_varhdr.U,v $
12?RCS: Revision 3.0.1.3 1997/02/28 15:54:42 ram
13?RCS: patch61: varargs script now starts with leading "startsh"
14?RCS:
15?RCS: Revision 3.0.1.2 1994/10/29 16:21:02 ram
16?RCS: patch36: added ?F: line for metalint file checking
17?RCS:
18?RCS: Revision 3.0.1.1 1994/05/13 15:26:05 ram
19?RCS: patch27: this unit now supersedes old i_stdarg.U and i_varargs.U
20?RCS: patch27: modified to avoid spurious Whoa warnings (ADO)
21?RCS:
22?RCS: Revision 3.0 1993/08/18 12:08:49 ram
23?RCS: Baseline for dist 3.0 netwide release.
24?RCS:
25?MAKE:i_stdarg i_varargs i_varhdr: cat +cc +ccflags rm test Setvar \
9b04e79a 26 Findhdr startsh _o
0f00356b
JH
27?MAKE: -pick add $@ %<
28?S:i_stdarg:
29?S: This variable conditionally defines the I_STDARG symbol, which
30?S: indicates to the C program that <stdarg.h> exists and should
31?S: be included.
32?S:.
33?S:i_varargs:
34?S: This variable conditionally defines I_VARARGS, which indicates
35?S: to the C program that it should include <varargs.h>.
36?S:.
37?S:i_varhdr:
38?S: Contains the name of the header to be included to get va_dcl definition.
39?S: Typically one of varargs.h or stdarg.h.
40?S:.
41?C:I_STDARG:
42?C: This symbol, if defined, indicates that <stdarg.h> exists and should
43?C: be included.
44?C:.
45?C:I_VARARGS:
46?C: This symbol, if defined, indicates to the C program that it should
47?C: include <varargs.h>.
48?C:.
49?H:#$i_stdarg I_STDARG /**/
50?H:#$i_varargs I_VARARGS /**/
51?H:.
52?W:%<:va_dcl
0f00356b 53?F:!varargs
9b04e79a 54?T:valstd
0f00356b
JH
55?LINT:set i_stdarg i_varargs
56?X:
57?X: Don't use setvar because the varags test below might override these.
58?X: Actually, the messages here are just informative. We don't wish to set
59?X: i_varargs or i_stdarg to their final value before knowing which of the
60?X: two we'll include.
61?X:
62: see if stdarg is available
63echo " "
64if $test `./findhdr stdarg.h`; then
65 echo "<stdarg.h> found." >&4
66 valstd="$define"
67else
68 echo "<stdarg.h> NOT found." >&4
69 valstd="$undef"
70fi
71
72: see if varags is available
73echo " "
74if $test `./findhdr varargs.h`; then
75 echo "<varargs.h> found." >&4
76else
77 echo "<varargs.h> NOT found, but that's ok (I hope)." >&4
78fi
79
80?X:
81?X: if you have stdarg.h, you need to support prototypes to actually use it;
82?X: but if stdarg.h exists and the compiler doesn't support prototypes (for some
83?X: bizarre reason), we'll fall back to varargs.h anyway so it's not so bad.
84?X:
85: set up the varargs testing programs
86$cat > varargs.c <<EOP
87#ifdef I_STDARG
88#include <stdarg.h>
89#endif
90#ifdef I_VARARGS
91#include <varargs.h>
92#endif
93
94#ifdef I_STDARG
95int f(char *p, ...)
96#else
97int f(va_alist)
98va_dcl
99#endif
100{
101 va_list ap;
102#ifndef I_STDARG
103 char *p;
104#endif
105#ifdef I_STDARG
106 va_start(ap,p);
107#else
108 va_start(ap);
109 p = va_arg(ap, char *);
110#endif
111 va_end(ap);
47f8a159 112 return 0;
0f00356b
JH
113}
114EOP
115$cat > varargs <<EOP
116$startsh
117if $cc -c $ccflags -D\$1 varargs.c >/dev/null 2>&1; then
118 echo "true"
119else
120 echo "false"
121fi
122$rm -f varargs$_o
123EOP
124chmod +x varargs
125
126: now check which varargs header should be included
127echo " "
128i_varhdr=''
7fd9ec4d 129val=''
0f00356b
JH
130case "$valstd" in
131"$define")
132 if `./varargs I_STDARG`; then
133 val='stdarg.h'
134 elif `./varargs I_VARARGS`; then
135 val='varargs.h'
136 fi
137 ;;
138*)
139 if `./varargs I_VARARGS`; then
140 val='varargs.h'
141 fi
142 ;;
143esac
144case "$val" in
145'')
146echo "I could not find the definition for va_dcl... You have problems..." >&4
147 val="$undef"; set i_stdarg; eval $setvar
148 val="$undef"; set i_varargs; eval $setvar
149 ;;
41322e17 150*)
0f00356b
JH
151 set i_varhdr
152 eval $setvar
153 case "$i_varhdr" in
154 stdarg.h)
155 val="$define"; set i_stdarg; eval $setvar
156 val="$undef"; set i_varargs; eval $setvar
157 ;;
158 varargs.h)
159 val="$undef"; set i_stdarg; eval $setvar
160 val="$define"; set i_varargs; eval $setvar
161 ;;
162 esac
163 echo "We'll include <$i_varhdr> to get va_dcl definition." >&4;;
164esac
165$rm -f varargs*
166