build-all.sh 13 KB

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