bootstrap.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #!/bin/sh
  2. # Run this to generate all the initial makefiles, etc.
  3. DIE=0
  4. SRCDIR=`dirname $0`
  5. BUILDDIR=`pwd`
  6. srcfile=src/mssh.c
  7. debug ()
  8. # print out a debug message if DEBUG is a defined variable
  9. {
  10. if [ ! -z "$DEBUG" ]; then
  11. echo "DEBUG: $1"
  12. fi
  13. }
  14. version_check ()
  15. # check the version of a package
  16. # first argument : complain ('1') or not ('0')
  17. # second argument : package name (executable)
  18. # third argument : source download url
  19. # rest of arguments : major, minor, micro version
  20. {
  21. COMPLAIN=$1
  22. PACKAGE=$2
  23. URL=$3
  24. MAJOR=$4
  25. MINOR=$5
  26. MICRO=$6
  27. WRONG=
  28. debug "major $MAJOR minor $MINOR micro $MICRO"
  29. VERSION=$MAJOR
  30. if [ ! -z "$MINOR" ]; then VERSION=$VERSION.$MINOR; else MINOR=0; fi
  31. if [ ! -z "$MICRO" ]; then VERSION=$VERSION.$MICRO; else MICRO=0; fi
  32. debug "version $VERSION"
  33. echo "+ checking for $PACKAGE >= $VERSION ... " | tr -d '\n'
  34. ($PACKAGE --version) < /dev/null > /dev/null 2>&1 ||
  35. {
  36. echo
  37. echo "You must have $PACKAGE installed to compile $package."
  38. echo "Download the appropriate package for your distribution,"
  39. echo "or get the source tarball at $URL"
  40. return 1
  41. }
  42. # the following line is carefully crafted sed magic
  43. pkg_version=`$PACKAGE --version|head -n 1|sed 's/([^)]*)//g;s/^[a-zA-Z\.\ \-\/]*//;s/ .*$//'`
  44. debug "pkg_version $pkg_version"
  45. pkg_major=`echo $pkg_version | cut -d. -f1`
  46. pkg_minor=`echo $pkg_version | sed s/[-,a-z,A-Z].*// | cut -d. -f2`
  47. pkg_micro=`echo $pkg_version | sed s/[-,a-z,A-Z].*// | cut -d. -f3`
  48. [ -z "$pkg_minor" ] && pkg_minor=0
  49. [ -z "$pkg_micro" ] && pkg_micro=0
  50. debug "found major $pkg_major minor $pkg_minor micro $pkg_micro"
  51. #start checking the version
  52. if [ "$pkg_major" -lt "$MAJOR" ]; then
  53. WRONG=1
  54. elif [ "$pkg_major" -eq "$MAJOR" ]; then
  55. if [ "$pkg_minor" -lt "$MINOR" ]; then
  56. WRONG=1
  57. elif [ "$pkg_minor" -eq "$MINOR" -a "$pkg_micro" -lt "$MICRO" ]; then
  58. WRONG=1
  59. fi
  60. fi
  61. if [ ! -z "$WRONG" ]; then
  62. echo "found $pkg_version, not ok !"
  63. if [ "$COMPLAIN" -eq "1" ]; then
  64. echo
  65. echo "You must have $PACKAGE $VERSION or greater to compile $package."
  66. echo "Get the latest version from <$URL>."
  67. echo
  68. fi
  69. return 1
  70. else
  71. echo "found $pkg_version, ok."
  72. fi
  73. }
  74. version_check 1 "pkg-config" "http://pkgconfig.freedesktop.org/" 0 9 || DIE=1
  75. version_check 1 "autoconf" "ftp://ftp.gnu.org/pub/gnu/autoconf/" 2 56 || DIE=1
  76. version_check 1 "automake" "ftp://ftp.gnu.org/pub/gnu/automake/" 1 9 || DIE=1
  77. if [ "$DIE" -eq 1 ]; then
  78. exit 1
  79. fi
  80. # Chdir to the srcdir, then run auto* tools.
  81. cd $SRCDIR
  82. [ -f $srcfile ] || {
  83. echo "Are you sure $SRCDIR is a valid source directory?"
  84. exit 1
  85. }
  86. echo "+ running aclocal ..."
  87. aclocal || {
  88. echo
  89. echo "aclocal failed - check that all needed development files are present on system"
  90. exit 1
  91. }
  92. echo "+ running autoconf ... "
  93. autoconf || {
  94. echo
  95. echo "autoconf failed"
  96. exit 1
  97. }
  98. echo "+ running autoheader ... "
  99. autoheader || {
  100. echo
  101. echo "autoheader failed"
  102. exit 1
  103. }
  104. echo "+ running automake ... "
  105. automake -a -c || {
  106. echo
  107. echo "automake failed"
  108. exit 1
  109. }
  110. # Chdir back to the builddir before the configure step.
  111. cd $BUILDDIR
  112. # now remove the cache, because it can be considered dangerous in this case
  113. echo "+ Tidying up ... "
  114. rm -fr autom4te.cache config.h.in\~
  115. echo
  116. echo "Done."
  117. exit 0