summaryrefslogtreecommitdiff
path: root/nacl/okcompilers/do
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/okcompilers/do')
-rwxr-xr-xnacl/okcompilers/do196
1 files changed, 196 insertions, 0 deletions
diff --git a/nacl/okcompilers/do b/nacl/okcompilers/do
new file mode 100755
index 00000000..372b7e00
--- /dev/null
+++ b/nacl/okcompilers/do
@@ -0,0 +1,196 @@
1#!/bin/sh -e
2
3mkdir oldbin
4mkdir bin
5
6for language in c cpp
7do
8 exec <$language
9 exec 9>${language}-works
10
11 while read c options
12 do
13 echo "=== `date` === checking $c $options" >&2
14 rm -f test*
15 (
16 echo "#!/bin/sh"
17 echo 'PATH="'"$PATH"'"'
18 echo 'export PATH'
19 echo "$c" "$options" '"$@"'
20 ) > test-okc
21 chmod 755 test-okc
22 cat lib.c main.c > test.$language || continue
23 ./test-okc -o test test.$language || continue
24 ./test || continue
25 cp main.c test1.$language || continue
26 cp lib.c test2.$language || continue
27 ./test-okc -c test1.$language || continue
28 ./test-okc -c test2.$language || continue
29 ./test-okc -o test1 test1.o test2.o || continue
30 ./test1 || continue
31 echo "=== `date` === success: $c $options is ok"
32 echo "$c $options" >&9
33 done
34
35 mv ${language}-works $language
36done
37
38exec <c
39
40exec 7>oldbin/okabi
41chmod 755 oldbin/okabi
42echo "#!/bin/sh" >&7
43
44while :
45do
46 exec <c
47 read c options || break
48
49 for language in c cpp
50 do
51 exec 8>${language}-compatible
52 exec 9>${language}-incompatible
53 echo "=== `date` === checking compatibility with $c $options" >&2
54 exec <$language
55 while read c2 options2
56 do
57 echo "=== `date` === checking $c2 $options2" >&2
58 works=1
59 rm -f test*
60 (
61 echo "#!/bin/sh"
62 echo 'PATH="'"$PATH"'"'
63 echo 'export PATH'
64 echo "$c" "$options" '"$@"'
65 ) > test-okc
66 chmod 755 test-okc
67 (
68 echo "#!/bin/sh"
69 echo 'PATH="'"$PATH"'"'
70 echo 'export PATH'
71 echo "$c2" "$options2" '"$@"'
72 ) > test-okc2
73 chmod 755 test-okc2
74 if cp main.c test5.c \
75 && cp main.cpp test5.cpp \
76 && cp lib.c test6.c \
77 && ./test-okc2 -c test5.$language \
78 && ./test-okc -c test6.c \
79 && ./test-okc2 -o test5 test5.o test6.o \
80 && ./test5
81 then
82 echo "=== `date` === success: $c2 $options2 is compatible" >&2
83 echo "$c2 $options2" >&8
84 else
85 echo "$c2 $options2" >&9
86 fi
87 done
88 done
89
90 abi=`awk '{print length($0),$0}' < c-compatible \
91 | sort -n | head -1 | sed 's/ *$//' | sed 's/^[^ ]* //' | tr ' /' '__'`
92
93 echo "echo '"$abi"'" >&7
94
95 syslibs=""
96 for i in -lm -lnsl -lsocket -lrt
97 do
98 echo "=== `date` === checking $i" >&2
99 (
100 echo "#!/bin/sh"
101 echo 'PATH="'"$PATH"'"'
102 echo 'export PATH'
103 echo "$c" "$options" '"$@"' "$i" "$syslibs"
104 ) > test-okclink
105 chmod 755 test-okclink
106 cat lib.c main.c > test.c || continue
107 ./test-okclink -o test test.c $i $syslibs || continue
108 ./test || continue
109 syslibs="$i $syslibs"
110 (
111 echo '#!/bin/sh'
112 echo 'echo "'"$syslibs"'"'
113 ) > "oldbin/oklibs-$abi"
114 chmod 755 "oldbin/oklibs-$abi"
115 done
116
117 foundokar=0
118 exec <archivers
119 while read a
120 do
121 echo "=== `date` === checking archiver $a" >&2
122 (
123 echo "#!/bin/sh"
124 echo 'PATH="'"$PATH"'"'
125 echo 'export PATH'
126 echo "$a" '"$@"'
127 ) > test-okar
128 chmod 755 test-okar
129 cp main.c test9.c || continue
130 cp lib.c test10.c || continue
131 ./test-okc -c test10.c || continue
132 ./test-okar cr test10.a test10.o || continue
133 ranlib test10.a || echo "=== `date` === no ranlib; continuing anyway" >&2
134 ./test-okc -o test9 test9.c test10.a || continue
135 ./test9 || continue
136 cp -p test-okar "oldbin/okar-$abi"
137 echo "=== `date` === success: archiver $a is ok" >&2
138 foundokar=1
139 break
140 done
141
142 case $foundokar in
143 0)
144 echo "=== `date` === giving up; no archivers work" >&2
145 exit 111
146 ;;
147 esac
148
149 for language in c cpp
150 do
151 mv ${language}-incompatible ${language}
152 exec <${language}-compatible
153 exec 9>"oldbin/ok${language}-$abi"
154 chmod 755 "oldbin/ok${language}-$abi"
155
156 echo "#!/bin/sh" >&9
157 while read c2 options2
158 do
159 echo "echo '"$c2 $options2"'" >&9
160 done
161 done
162done
163
164exec 7>/dev/null
165
166oldbin/okabi \
167| while read abi
168do
169 oldbin/okc-$abi \
170 | head -1 \
171 | while read c
172 do
173 $c -o abiname abiname.c \
174 && ./abiname "$abi"
175 done
176done > abinames
177
178numabinames=`awk '{print $2}' < abinames | sort -u | wc -l`
179numabis=`oldbin/okabi | wc -l`
180if [ "$numabis" = "$numabinames" ]
181then
182 exec <abinames
183 exec 7>bin/okabi
184 chmod 755 bin/okabi
185 echo '#!/bin/sh' >&7
186 while read oldabi newabi
187 do
188 mv "oldbin/okc-$oldabi" "bin/okc-$newabi"
189 mv "oldbin/okcpp-$oldabi" "bin/okcpp-$newabi"
190 mv "oldbin/okar-$oldabi" "bin/okar-$newabi"
191 mv "oldbin/oklibs-$oldabi" "bin/oklibs-$newabi"
192 echo "echo $newabi" >&7
193 done
194else
195 cp -p oldbin/* bin
196fi