2
0

configure 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # -*- mode: sh -*-
  3. # Minimal configure script which writes out a Makefile.inc
  4. # Copyright 2010, 2011 Colin Walters <walters@verbum.org>
  5. # Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
  6. prefix=/usr
  7. # Little helper function for reading args from the commandline.
  8. # it automatically handles -a b and -a=b variants, and returns 1 if
  9. # we need to shift $3.
  10. read_arg() {
  11. # $1 = arg name
  12. # $2 = arg value
  13. # $3 = arg parameter
  14. local rematch='^[^=]*=(.*)$'
  15. if [[ $2 =~ $rematch ]]; then
  16. read "$1" <<< "${BASH_REMATCH[1]}"
  17. else
  18. read "$1" <<< "$3"
  19. # There is no way to shift our callers args, so
  20. # return 1 to indicate they should do it instead.
  21. return 1
  22. fi
  23. }
  24. while (($# > 0)); do
  25. case "${1%%=*}" in
  26. --prefix) read_arg prefix "$@" || shift;;
  27. --bindir) read_arg bindir "$@" || shift;;
  28. --sbindir) read_arg sbindir "$@" || shift;;
  29. --libexecdir) read_arg libexecdir "$@" || shift;;
  30. --datarootdir) read_arg datarootdir "$@" || shift;;
  31. --datadir) read_arg datadir "$@" || shift;;
  32. --sysconfdir) read_arg sysconfdir "$@" || shift;;
  33. --libdir) read_arg libdir "$@" || shift;;
  34. --mandir) read_arg mandir "$@" || shift;;
  35. *) echo "Ignoring unknown option '$1'";;
  36. esac
  37. shift
  38. done
  39. # Handle srcdir != builddir
  40. srcdir=$(dirname $0)
  41. if ! test -f Makefile; then
  42. ln -s ${srcdir}/Makefile Makefile
  43. fi
  44. cat > Makefile.inc.tmp <<EOF
  45. srcdir = ${srcdir}
  46. prefix ?= ${prefix}
  47. bindir ?= ${bindir:-${prefix}/bin}
  48. sbindir ?= ${sbindir:-${prefix}/sbin}
  49. libexecdir ?= ${libexecdir:-${prefix}/libexec}
  50. datarootdir ?= ${datarootdir:-${prefix}/share}
  51. datadir ?= ${datadir:-${datarootdir}}
  52. sysconfdir ?= ${sysconfdir:-${prefix}/etc}
  53. libdir ?= ${libdir:-${prefix}/lib}
  54. mandir ?= ${mandir:-${prefix}/share/man}
  55. EOF
  56. mv Makefile.inc.tmp Makefile.inc