parbuild.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #! /bin/bash
  2. # This script is here to bring all currently configured copies of the
  3. # CSL versuion of Reduce up to date using parallel builds that try to
  4. # exploit all available CPU cores. It works by creating a temporary
  5. # Makefile in /tmp/makeall and using it with "-j N" where N is the number
  6. # of available processor cores. One step in a rebuild can involve remaking
  7. # bootstrapreduce and using it to compile selected parts of the main Reduce
  8. # source into C++ code in cslbuild/generated-c/u*.cpp. This should be
  9. # done on just one architecture before others try to use the results. The
  10. # selected architecture for this will be the one in the alphabetically first
  11. # build directory within cslbuild. Under windows this will typically be
  12. # cslbuild/x86_64-pc-cygwin which is a reasonable choice.
  13. #
  14. # If configuration or building in any directory failed or fails here then
  15. # this parallel attempt may lead to diagnostics interleaved with other
  16. # more successful output, so trying again with "make" in a failed directory
  17. # may be a good plan.
  18. printf "SUBDIRS = \\" > /tmp/makeall
  19. printf "\n" >> /tmp/makeall
  20. first=""
  21. for x in `ls -d cslbuild/*/csl`
  22. do
  23. if test "$first" = ""
  24. then
  25. echo setting first = $x
  26. first=$x
  27. fi
  28. printf "\t$x \\" >> /tmp/makeall
  29. printf "\n" >> /tmp/makeall
  30. # rm -f $x/reduce.img $x/reduce-u01.o
  31. done
  32. printf "\n\n" >> /tmp/makeall
  33. printf "default:\tall\n\n" >> /tmp/makeall
  34. printf "\$(SUBDIRS)::\n\t\$(MAKE) -C \$@ \$(MAKECMDGOALS)\n\n" >> /tmp/makeall
  35. printf "all clean :\t\$(SUBDIRS)\n" >> /tmp/makeall
  36. echo first = $first
  37. if test "$first" = ""
  38. then
  39. printf "\n+++ You need to run ./configure --with-csl .. before this\n"
  40. exit 1
  41. fi
  42. if test "`uname -s`" = "Darwin"
  43. then
  44. GNU_MAKE=gmake
  45. RED=reduce.app/Contents/MacOS/reduce.img
  46. BOOT=bootstrapreduce.app/Contents/MacOS/bootstrapreduce.img
  47. else
  48. GNU_MAKE=make
  49. RED=reduce.img
  50. BOOT=bootstrapreduce.img
  51. fi
  52. if test "`which nproc`" != "" && test "$?" = "0"
  53. then
  54. N=`nproc`
  55. else
  56. if test "`which sysctl`" != "" && test "$?" = "0"
  57. then
  58. N=`sysctl -n hw.ncpu`
  59. else
  60. N=2
  61. fi
  62. fi
  63. # This initial use of "make" is to ensure that the generated C++ code
  64. # in cslbuild/generated-c is up to date.
  65. time $GNU_MAKE -j $N -C $first reduce-u01.o
  66. if test $? != 0
  67. then
  68. printf "Rebuilding generated-c seems to have failed\n"
  69. exit 1
  70. fi
  71. time $GNU_MAKE -j $N -f /tmp/makeall
  72. # As a small check for success I will look for a "reduce.img" in each
  73. # directory considered
  74. err=0
  75. for x in `ls -d cslbuild/*/csl`
  76. do
  77. y=${x#cslbuild/}
  78. y=${y%/csl}
  79. s=`stat -c%s $x/reduce.img 2>/dev/null`
  80. if test $? != 0 || test "$s" = ""
  81. then
  82. printf "$y failed\n"
  83. err=1
  84. else
  85. d=`stat -c%y $x/reduce.img`
  86. d=${d%.*}
  87. printf "$y size=$s date=$d\n"
  88. fi
  89. done
  90. exit $err