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