This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Populate metaconfig branch.
[metaconfig.git] / U / typedefs / Typedef.U
1 ?RCS: $Id: Typedef.U,v 3.0.1.3 1995/07/25 13:42:07 ram Exp $
2 ?RCS:
3 ?RCS: Copyright (c) 1991-1993, Raphael Manfredi
4 ?RCS: 
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
9 ?RCS: of the source tree for dist 3.0.
10 ?RCS:
11 ?RCS: $Log: Typedef.U,v $
12 ?RCS: Revision 3.0.1.3  1995/07/25  13:42:07  ram
13 ?RCS: patch56: added backslash escapes within evals to prevent space problems
14 ?RCS:
15 ?RCS: Revision 3.0.1.2  1994/10/29  16:01:16  ram
16 ?RCS: patch36: don't clobber visible 'val' variable, use 'varval' instead
17 ?RCS:
18 ?RCS: Revision 3.0.1.1  1994/08/29  16:05:14  ram
19 ?RCS: patch32: created
20 ?RCS:
21 ?X:
22 ?X: This unit checks for the definition of a given typedef.
23 ?X:
24 ?X: To use it, say:
25 ?X: set typedef val_t default [includes]
26 ?X: eval $typedef
27 ?X:
28 ?MAKE:Typedef: cppstdin cppminus cppflags rm sed contains Oldconfig Myread
29 ?MAKE:  -pick add $@ %<
30 ?LINT:define typedef
31 ?LINT:define typedef_ask
32 ?V:typedef typedef_ask
33 ?S:typedef:
34 ?S:     This shell variable is used internally by Configure to check
35 ?S:     whether a given typedef is defined or not. A typical use is:
36 ?S:             set typedef val_t default [includes]
37 ?S:             eval $typedef
38 ?S:     That will return val_t set to default if the typedef was not found,
39 ?S:     to typedef otherwise. If no includes are specified, look in sys/types.h.
40 ?S:.
41 ?S:typedef_ask:
42 ?S:     This shell variable is used internally by Configure to check
43 ?S:     whether a given typedef is defined or not.  If it is not defined,
44 ?S:     this will call the ./myread script to prompt for an answer.
45 ?S:     It is intended to be used to avoid unnecessary prompts.
46 ?S:     A typical use is
47 ?S:             rp="What is the type for file position used by fsetpos()?"
48 ?S:             set fpos_t fpostype long stdio.h sys/types.h
49 ?S:             eval $typedef_ask
50 ?S:     This will set fpostype=fpos_t, if fpos_t is available.  Otherwise
51 ?S:     it will call myread with a default of 'long', and a prompt of $rp.
52 ?S:.
53 ?T:type var def inclist varval inc
54 : define an is-a-typedef? function
55 typedef='type=$1; var=$2; def=$3; shift; shift; shift; inclist=$@;
56 case "$inclist" in
57 "") inclist="sys/types.h";;
58 esac;
59 eval "varval=\$$var";
60 case "$varval" in
61 "")
62         $rm -f temp.c;
63         for inc in $inclist; do
64                 echo "#include <$inc>" >>temp.c;
65         done;
66 ?X:     Maybe it's a #define instead of a typedef.
67         echo "#ifdef $type" >> temp.c;
68         echo "printf(\"We have $type\");" >> temp.c;
69         echo "#endif" >> temp.c;
70         $cppstdin $cppflags $cppminus < temp.c >temp.E 2>/dev/null;
71         if $contains $type temp.E >/dev/null 2>&1; then
72                 eval "$var=\$type";
73         else
74                 eval "$var=\$def";
75         fi;
76         $rm -f temp.?;;
77 *) eval "$var=\$varval";;
78 esac'
79
80 ?X:     Originally, I eval'd $typedef and then checked the results against
81 ?X:     $type.  Unfortunately, it then became complicated to check
82 ?X:     whether you are re-using an old config.sh value, and the logic got
83 ?X:     so convoluted it became easier to just copy the function above
84 ?X:     and alter it slightly.  A.D.  3/1998
85 : define an is-a-typedef? function that prompts if the type is not available.
86 typedef_ask='type=$1; var=$2; def=$3; shift; shift; shift; inclist=$@;
87 case "$inclist" in
88 "") inclist="sys/types.h";;
89 esac;
90 eval "varval=\$$var";
91 case "$varval" in
92 "")
93         $rm -f temp.c;
94         for inc in $inclist; do
95                 echo "#include <$inc>" >>temp.c;
96         done;
97 ?X:     Maybe it's a #define instead of a typedef.
98         echo "#ifdef $type" >> temp.c;
99         echo "printf(\"We have $type\");" >> temp.c;
100         echo "#endif" >> temp.c;
101         $cppstdin $cppflags $cppminus < temp.c >temp.E 2>/dev/null;
102         echo " " ;
103         echo "$rp" | $sed -e "s/What is/Looking for/" -e "s/?/./";
104         if $contains $type temp.E >/dev/null 2>&1; then
105                 echo "$type found." >&4;
106                 eval "$var=\$type";
107         else
108                 echo "$type NOT found." >&4;
109                 dflt="$def";
110                 . ./myread ;
111                 eval "$var=\$ans";
112         fi;
113         $rm -f temp.?;;
114 *) eval "$var=\$varval";;
115 esac'
116