guild.in 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh
  2. # -*- scheme -*-
  3. exec ${GUILE:-@installed_guile@} $GUILE_FLAGS -e '(@@ (guild) main)' -s "$0" "$@"
  4. !#
  5. ;;;; guild --- running scripts bundled with Guile
  6. ;;;; Andy Wingo <wingo@pobox.com> --- April 2009
  7. ;;;;
  8. ;;;; Copyright (C) 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc.
  9. ;;;;
  10. ;;;; This library is free software; you can redistribute it and/or
  11. ;;;; modify it under the terms of the GNU Lesser General Public
  12. ;;;; License as published by the Free Software Foundation; either
  13. ;;;; version 3 of the License, or (at your option) any later version.
  14. ;;;;
  15. ;;;; This library is distributed in the hope that it will be useful,
  16. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. ;;;; Lesser General Public License for more details.
  19. ;;;;
  20. ;;;; You should have received a copy of the GNU Lesser General Public
  21. ;;;; License along with this library; if not, write to the Free
  22. ;;;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  23. ;;;; Boston, MA 02110-1301 USA
  24. (define-module (guild)
  25. #:use-module (ice-9 getopt-long)
  26. #:use-module (ice-9 command-line)
  27. #:autoload (ice-9 format) (format))
  28. ;; Hack to provide scripts with the bug-report address.
  29. (module-define! the-scm-module
  30. '%guile-bug-report-address
  31. "@PACKAGE_BUGREPORT@")
  32. (define *option-grammar*
  33. '((help (single-char #\h))
  34. (version (single-char #\v))))
  35. (define (display-version)
  36. (version-etc "@PACKAGE_NAME@"
  37. (version)
  38. #:command-name "guild"
  39. #:license *LGPLv3+*))
  40. (define (find-script s)
  41. (resolve-module (list 'scripts (string->symbol s)) #:ensure #f))
  42. (define (main args)
  43. (if (defined? 'setlocale)
  44. (catch 'system-error
  45. (lambda ()
  46. (setlocale LC_ALL ""))
  47. (lambda args
  48. (format (current-error-port)
  49. "warning: failed to install locale: ~a~%"
  50. (strerror (system-error-errno args))))))
  51. (let* ((options (getopt-long args *option-grammar*
  52. #:stop-at-first-non-option #t))
  53. (args (option-ref options '() '())))
  54. (cond
  55. ((option-ref options 'help #f)
  56. (apply (module-ref (resolve-module '(scripts help)) 'main) args)
  57. (exit 0))
  58. ((option-ref options 'version #f)
  59. (display-version)
  60. (exit 0))
  61. ((find-script (if (null? args) "help" (car args)))
  62. => (lambda (mod)
  63. (exit (apply (module-ref mod 'main) (if (null? args)
  64. '()
  65. (cdr args))))))
  66. (else
  67. (format (current-error-port)
  68. "guild: unknown script ~s~%" (car args))
  69. (format (current-error-port)
  70. "Try `guild help' for more information.~%")
  71. (exit 1)))))