1
0

do 4.5 KB

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