automagic 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. log() {
  3. echo "[automagic] " $@
  4. }
  5. die() {
  6. log "Fatal: "$@
  7. exit 1
  8. }
  9. if [[ ! -d platform/unix ]]; then
  10. log "Can't find the 'plaform/unix' folder, make sure you run this from the root of the repository."
  11. exit 1
  12. fi
  13. AUTOHEADER=${AUTOHEADER:-$(which autoheader)}
  14. AUTOCONF=${AUTOCONF:-$(which autoconf)}
  15. LIBTOOLIZE=${LIBTOOLIZE:-$(which libtoolize)}
  16. ACLOCAL=${ACLOCAL:-$(which aclocal)}
  17. AUTOMAKE=${AUTOMAKE:-$(which automake)}
  18. [[ -x ${AUTOHEADER} ]] || die "Could not find autoheader. Install autoconf."
  19. [[ -x ${AUTOCONF} ]] || die "Could not find autoconf."
  20. [[ -x ${LIBTOOLIZE} ]] || die "Could not find libtoolize. Install libtool."
  21. [[ -x ${ACLOCAL} ]] || die "Could not find aclocal. Install automake."
  22. [[ -x ${AUTOMAKE} ]] || die "Could not find automake."
  23. print_errors() {
  24. local output
  25. output="$("$@" 2>&1)" && return 0
  26. printf "%s\n" "$output"
  27. return 1
  28. }
  29. automagic() {
  30. log "Copying files..."
  31. cp platform/unix/configure.ac .
  32. cp platform/unix/Makefile.am .
  33. log "Running genmodules..."
  34. if ! print_errors bash platform/unix/genmodules "$1"; then
  35. echo "You should be doing this from the root directory of the project."
  36. exit 1
  37. fi
  38. log "Running autoheader..."
  39. print_errors ${AUTOHEADER} || return 1 # Gimmie config.h.in
  40. log "Running libtoolize..."
  41. print_errors ${LIBTOOLIZE} --force || return 1
  42. log "Running aclocal..."
  43. print_errors ${ACLOCAL} || return 1
  44. log "Running autoconf..."
  45. print_errors ${AUTOCONF} || return 1
  46. log "Running automake..."
  47. print_errors ${AUTOMAKE} -a || return 1
  48. }
  49. automagic "$@"
  50. if [[ $? -eq 1 ]]; then
  51. log "Failed, sadface."
  52. log "This is generally a configuration error (I'm looking at you aclocal)"
  53. exit 1
  54. else
  55. log "Success, carry on configuring."
  56. fi