Imported from ../bash-1.14.7.tar.gz.
[platform/upstream/bash.git] / portbash / libc.sh
1 #! /bin/sh
2
3 CC=cc
4 export CC
5
6 cat > x.c <<EOF
7 extern char *alloca();
8
9 main()
10 {
11         char *s;
12         s = alloca(20);
13 }
14 EOF
15
16 if ${CC} x.c > /dev/null 2>&1; then
17         :
18 else
19         echo '#undef HAVE_ALLOCA'
20 fi
21 rm -f x.c x.o a.out
22
23 cat > x.c << EOF
24 #include <sys/types.h>
25 #include <sys/param.h>
26 extern char *getwd();
27 main()
28 {
29         getwd();
30 }
31 EOF
32
33 if ${CC} x.c > /dev/null 2>&1; then
34         echo '#define HAVE_GETWD'
35 else
36         echo '#undef HAVE_GETWD'
37         rm -f x.c x.o a.out
38
39         cat > x.c << EOF
40 extern char *getcwd();
41
42 main()
43 {
44         getcwd();
45 }
46 EOF
47
48         if ${CC} x.c >/dev/null 2>&1; then
49                 echo '#define HAVE_GETCWD'
50         fi
51 fi
52 rm -f a.out x.c x.o
53
54 cat > x.c << EOF
55 /*
56  * exit 0 if we have bcopy in libc and it works as in BSD
57  */
58
59 extern int bcopy();
60
61 char x[] = "12345";
62 char y[] = "67890";
63
64 main()
65 {
66         bcopy(x, y, 5);
67         exit(strcmp(x, y));
68 }
69 EOF
70
71 if ${CC} x.c > /dev/null 2>&1 && ./a.out ; then
72         BC='-DHAVE_BCOPY'
73 fi
74
75 rm -f x.c x.o a.out
76
77 cat > x.c << EOF
78 /*
79  * If this compiles, the system has uid_t and gid_t
80  */
81
82 #include <sys/types.h>
83
84 uid_t   u;
85 gid_t   g;
86
87 main()
88 {
89         exit(0);
90 }
91 EOF
92
93 if ${CC} x.c > /dev/null 2>&1; then
94         UIDT='-DHAVE_UID_T'
95 fi
96
97 rm -f x.c x.o a.out
98
99 cat > x.c <<EOF
100 #include <signal.h>
101
102 extern char *sys_siglist[];
103
104 main()
105 {
106         char *x;
107
108         x = sys_siglist[3];
109         write(2, x, strlen(x));
110         exit(0);
111 }
112 EOF
113
114 if ${CC} ./x.c >/dev/null 2>&1; then
115         echo '#define HAVE_SYS_SIGLIST'
116 else
117
118         cat > x.c <<EOF
119 #include <signal.h>
120
121 extern char *_sys_siglist[];
122
123 main()
124 {
125         exit(0);
126 }
127 EOF
128
129         if ${CC} ./x.c >/dev/null 2>&1; then
130                 echo '#define HAVE_SYS_SIGLIST'
131                 SL='-Dsys_siglist=_sys_siglist'
132         fi
133 fi
134
135 PG=
136 if ${CC} pgrp.c >/dev/null 2>&1; then
137         PG=`./a.out`
138 fi
139
140 if [ -f /unix ] && [ -f /usr/ccs/lib/libc.so ]; then
141         R4="-DUSGr4"
142 fi
143
144 touch not_a_directory
145 if [ -f /usr/include/dirent.h ]; then
146         d='<dirent.h>'
147 else
148         d='<sys/dir.h>'
149 fi
150
151 cat > x.c << EOF
152 /*
153  * exit 0 if opendir does not check whether its argument is a directory
154  */
155
156 #include $d
157 DIR *dir;
158
159 main()
160 {
161         dir = opendir("not_a_directory");
162         exit (dir == 0);
163 }
164 EOF
165
166 if ${CC} x.c > /dev/null 2>&1 && ./a.out ; then
167         OD='-DOPENDIR_NOT_ROBUST'
168 fi
169
170 rm -f x.c x.o a.out pgrp.o not_a_directory
171 echo "#define SYSDEP_CFLAGS $BC $UIDT $SL $PG $R4 $OD"
172 exit 0