guild.in 2.6 KB

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