check-signatures.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. #! /bin/sh
  2. #
  3. # This is a companion to the script for rebuilding a CSL-based Reduce system.
  4. # It just displays some file signatures.
  5. #
  6. build_directory=`pwd`
  7. # Find the directory that this script was called from.
  8. # I expect that $0 to this script will give me the name of the current script.
  9. # This will be interpreted in the way bash (and perhaps other shells) find
  10. # commands:
  11. # If the name does not contain a "/" it is expected that $PATH contains
  12. # a directory with an executable file of that name in it;
  13. # If the name starts with a "/" it is an absolute path;
  14. # In remaining cases it is relative to the current working directory.
  15. #
  16. # Given the above rules I can convert the name to give me an absolute
  17. # path... I do a minor tidy-up involving commands called "./something"
  18. # in that I remove the "./" when it is unnecessary.
  19. # I will use single-letter shall variable names for temporary work-space and
  20. # longer clearer names when I end up with something worth keeping.
  21. a=$0
  22. c=unknown
  23. case $a in
  24. /* )
  25. c=$a
  26. ;;
  27. */* )
  28. case $a in
  29. ./* )
  30. a=`echo $a | sed -e 's/\.\///'`
  31. ;;
  32. esac
  33. c=`pwd`/$a
  34. ;;
  35. * )
  36. for d in $PATH
  37. do
  38. if test -x $d/$a
  39. then
  40. c=$d/$a
  41. fi
  42. done
  43. ;;
  44. esac
  45. # The error case here ought never to arise...
  46. case $c in
  47. unknown )
  48. echo "Unable to find full path for script. Please re-try"
  49. echo "launching it using a fully rooted path."
  50. exit 1
  51. ;;
  52. esac
  53. echo Full path of script is $c
  54. # Now I want the directory that this script is in. So I remove the
  55. # tail of its full name, from the final "/" to the end of the string.
  56. # Now if I do that and the path has an internal part of the form
  57. # path1/../path2
  58. # then the ".." really messes things up for me. I could deal with that
  59. # one way by getting the parent directories bt sticking "/.." on the end
  60. # of what I have, but I think I will try to tidy things up another
  61. # way first. Specifically I will try to find any sub-strings in the
  62. # path that are of the form "/xxx/../ and remove them. Well as I think of
  63. # that I ought to remove any instances of "/./" as well!
  64. c=`echo $c | sed -e 's/\/\.\//\//'`
  65. c=`echo $c | sed -e 's/\/\.\//\//'`
  66. c=`echo $c | sed -e 's/\/[^/.][^/]*\/\.\.\//\//'`
  67. c=`echo $c | sed -e 's/\/[^/.][^/]*\/\.\.\//\//'`
  68. c=`echo $c | sed -e 's/\/[^/.][^/]*\/\.\.\//\//'`
  69. util_directory=`echo $c | sed -e 's/\/[^/]*$//'`
  70. csl_directory=`echo $util_directory | sed -e 's/\/[^/]*$//'`
  71. lisp_directory=`echo $csl_directory | sed -e 's/\/[^/]*$//'`
  72. reduce_directory=`echo $lisp_directory | sed -e 's/\/[^/]*$//'`
  73. cslbase_directory=$csl_directory/cslbase
  74. echo util_directory = $util_directory
  75. echo csl_directory = $csl_directory
  76. echo lisp_directory = $lisp_directory
  77. echo reduce_directory = $reduce_directory
  78. echo cslbase_directory = $cslbase_directory
  79. # I test for just a few files that I expect to be in the "cslbase"
  80. # place. If any are missing then I am in a mess. At present I do not
  81. # check that the rest of what should be there is in a good state - I hope
  82. # that "make" and the C/C++ compilers will reject anything that is
  83. # messed up.
  84. if test ! -f $cslbase_directory/configure.ac || \
  85. test ! -f $cslbase_directory/Makefile.am || \
  86. test ! -f $cslbase_directory/Makefile.in || \
  87. test ! -f $cslbase_directory/aclocal.m4 || \
  88. test ! -f $cslbase_directory/config.h.in || \
  89. test ! -f $cslbase_directory/configure || \
  90. test ! -f $cslbase_directory/csl.c
  91. then
  92. echo "Some autoconfig-related files are not present in the CSL"
  93. echo "source directory. Please update it and try again."
  94. exit 1
  95. fi
  96. echo reduce_directory = $reduce_directory
  97. # In the release system the support packages directory lives in $csl_directory
  98. # while the development tree keeps it in $reduce_directory. Sort
  99. # out which to use. Complain if both versions seem to exist since that
  100. # represents a confusing situation
  101. if test -d $reduce_directory/support-packages
  102. then
  103. if test -d $csl_directory/support-packages
  104. then
  105. echo "Two copies of the support-packages directory found."
  106. echo "Please remove one of them to avoid confusion."
  107. exit 1
  108. else
  109. support_directory="$reduce_directory/support-packages"
  110. fi
  111. elif test -d $csl_directory/support-packages
  112. then
  113. support_directory="$csl_directory/support-packages"
  114. else
  115. # If the support directory is not available then FOX and the GUI parts
  116. # of the system can not be built, but the rest can.
  117. echo "support-directory not found in $csl_directory or"
  118. echo "$reduce_directory. GUI will not be built."
  119. support_directory=""
  120. fi
  121. # The "config.guess" script finds a GNU-style triple to identify the
  122. # machine being used. Eg "i686-pc-cygwin". The script us inder the GNU
  123. # license but with a special excepotion that if it is distributed along
  124. # with a program that contains a configuration script generated by
  125. # Autoconf it can be distributed under the terms that apply to that
  126. # program. In this instance the program concerned is CSL.
  127. # It may be that I could just use a built-in shell variable $MACHTYPE
  128. # here. But if that was generally possible why whould autoconf supply
  129. # config.guess?
  130. machine=`/bin/sh $csl_directory/cslbase/config.guess`
  131. echo machine=$machine
  132. # There will be a number of arguments that I can pass to this script that
  133. # fine-tune the build that it done. They are
  134. #
  135. # --enable-debug build for debugging
  136. # --with-xp64 experimental cross-build for 64-bit windows
  137. # --with-cygwin use Cygwin X11 build and rely on cygwin1.dll
  138. # --with-m32 if compiling with gcc force 32-bit usage
  139. # --with-m64 if compiling with gcc force 64-bit usage
  140. #
  141. # --without-fox disable building the GUI
  142. #
  143. # These particular flags are also detected and interpeted in the same way
  144. # by the various other scripts that I have.
  145. xmachine="$machine"
  146. for x in $*
  147. do
  148. case $x in
  149. --enable-debug)
  150. enable_debug="--enable-debug"
  151. ;;
  152. --with-xp64)
  153. with_xp64="--with-xp64"
  154. ;;
  155. --with-cygwin)
  156. with_cygwin="--with-cygwin"
  157. ;;
  158. --with-m32)
  159. with_m32="--with-m32"
  160. ;;
  161. --with-m64)
  162. with_m64="--with-m64"
  163. ;;
  164. --without-fox)
  165. without_fox="yes"
  166. ;;
  167. esac
  168. done
  169. # As well as setting simple flags for each option I create an adjusted
  170. # "machine type" that reflects the options selected. This is used as a
  171. # directory name to hold a compiled version of FOX suitable for the
  172. # configuration concerned.
  173. if test "x$with_xp64" != "x"
  174. then
  175. xmachine="x64-pc-windows64"
  176. fi
  177. if test "x$with_cygwin" = "x"
  178. then
  179. xmachine=`echo $xmachine | sed -e 's/cygwin/mingw/'`
  180. fi
  181. if test "x$with_m32" != "x"
  182. then
  183. xmachine="$xmachine-m32"
  184. elif test "x$with_m64" != "x"
  185. then
  186. xmachine="$xmachine-m64"
  187. fi
  188. if test "x$with_debug" != "x"
  189. then
  190. xmachine="$xmachine-debug"
  191. fi
  192. echo "xmachine = $xmachine"
  193. # This script decides what to compile based on a collection of
  194. # signatures generated using "md5". It keeps its set of signatures
  195. # in a file "signature.sh" in the build directory. When first used
  196. # this file will not exist, and that will cause a complete rebuild
  197. # to be performed. Subsequently things will only be re-build if
  198. # relevant base files have changed.
  199. unset fox_signature
  200. unset fox_md5
  201. if test -x $build_directory/signature.sh
  202. then
  203. . $build_directory/signature.sh
  204. fi
  205. # At least while developing this I will display the values that I might
  206. # extract from the signature file.
  207. echo fox_signature=$fox_signature
  208. echo fox_md5=$fox_md5
  209. # If the file $support_directory/build-all.sh does not exist then
  210. # it is clear that the FOX sources and build scripts have not been
  211. # downloaded, so there is not point in trying to fuss about
  212. # whether it needs building or rebuilding
  213. if test "x$without_fox" != "xyes" &&
  214. test "x$support_directory" != "x" &&
  215. test -f $support_directory/build-all.sh
  216. then
  217. if test -d $reduce_directory/fox
  218. then
  219. fox_directory="$reduce_directory/fox/$xmachine"
  220. elif test -d $csl_directory
  221. then
  222. fox_directory="$csl_directory/fox/$xmachine"
  223. else
  224. fox_directory="$csl_directory/fox/$xmachine"
  225. echo "Need to create FOX directory: using $fox_directory"
  226. fi
  227. if ! test -d $fox_directory
  228. then
  229. mkdir -p $fox_directory
  230. fi
  231. with_fox="--with-fox=$fox_directory"
  232. # I want to get signatures for the FOX source and binary files. If either
  233. # have changed since I last ran this script I will rebuild FOX.
  234. #
  235. # I do the check in two stages to try to reduce cost. First I check
  236. # the output from "ls -l" on the relevant files. If that has not changed at
  237. # all I will assume that the files have not been altered. Note that this is
  238. # not a 100% secure judgement in either direction! If the "ls -l" information
  239. # has changed (note eg that it will on the day that a file becomes over 6
  240. # months old, even though the file has not changed: "ls" changes its display
  241. # format about then!) I will re-compute MD5 checksums.
  242. fox_files="$support_directory/fox*.gz $support_directory/*.patches"
  243. fox_files="$fox_files $support_directory/build-all.sh"
  244. fox_files="$fox_files $support_directory/build-fox*.sh"
  245. fox_files="$fox_files $fox_directory/include/fox-1.6/*.h"
  246. fox_files="$fox_files $fox_directory/lib/*.*"
  247. ls -l $fox_files > fox_files.log
  248. current_fox_signature=`ls -l $fox_files | md5sum | sed -e 's/ .*$//'`
  249. echo "current fox_signature = $current_fox_signature"
  250. # If the checksum on "ls" output agrees with the value (if any) that I had
  251. # stored than I will assume that the files have not changed, and I reflect
  252. # that by assuming that their MD5 sum is as it was last time. If the
  253. # "ls" checksum disagrees I will re-compute the MD5 checksum. This may
  254. # in fact still match and reveal that there has not been a change. There
  255. # are two particularly notable cases when this could arise:
  256. # (a) a file has been "touched" and its date-stamp has altered, but the
  257. # contents have not changed;
  258. # (b) the output from "ls -l" has changed, because of a file's age, from
  259. # the layout that gives the hour and minute of update to the version
  260. # that gives just date and year. Eg observe the two forms in this
  261. # 2-line extract created in mid-August 2006:
  262. # -rwxr-xr-x+ 1 acn1 None 159744 Feb 18 2002 unzip.exe
  263. # -rwxr-xr-x+ 1 acn1 None 4876 Aug 9 21:46 xport.chk
  264. if test "x$fox_signature" = "x$current_fox_signature" &&
  265. test "x$fox_md5" != "x"
  266. then
  267. current_fox_md5="$fox_md5"
  268. else
  269. current_fox_md5=`md5sum $fox_files | md5sum | sed -e 's/ .*$//'`
  270. fi
  271. echo "current fox_md5 = $current_fox_md5"
  272. # I need to build FOX if EITHER the sources for FOX have been updated or
  273. # if this is the first time and it is not in place.
  274. if test "x$current_fox_md5" = "x$fox_md5"
  275. then
  276. echo FOX appears to be up-to-date.
  277. echo The header and libraries are in $fox_directory
  278. else
  279. # In case any of the script files are not marked as executable I will
  280. # force things. File transfer might have lost permissions.
  281. echo "+++ would need to recompile FOX"
  282. fi
  283. #
  284. #
  285. # End of section that ensures that an up-to-date FOX build in in place
  286. #
  287. fi
  288. exit 0
  289. # end of check-signatures.sh