| 1 | #! /bin/sh
|
| 2 | # -*-scheme-*-
|
| 3 | build_aux=$(dirname $0)
|
| 4 | srcdir=$build_aux/..
|
| 5 | export LC_ALL=en_US.UTF-8
|
| 6 | export TZ=UTC0
|
| 7 | exec guile --no-auto-compile -L $srcdir -C $srcdir -e main -s "$0" "$@"
|
| 8 | !#
|
| 9 |
|
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 |
|
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 |
|
| 37 | (use-modules (srfi srfi-1)
|
| 38 | (srfi srfi-26)
|
| 39 | (ice-9 curried-definitions)
|
| 40 | (ice-9 match)
|
| 41 | (ice-9 popen)
|
| 42 | (ice-9 rdelim)
|
| 43 | (guix build utils))
|
| 44 |
|
| 45 | (define ((option? name) option)
|
| 46 | (string-prefix? name option))
|
| 47 |
|
| 48 | (define (get-option args name)
|
| 49 | (let ((option (find (option? name) args)))
|
| 50 | (and option
|
| 51 | (substring option (string-length name)))))
|
| 52 |
|
| 53 | (define (pipe-command command)
|
| 54 | (let* ((port (apply open-pipe* OPEN_READ command))
|
| 55 | (output (read-string port)))
|
| 56 | (close-port port)
|
| 57 | output))
|
| 58 |
|
| 59 |
|
| 60 | |
| 61 | |
| 62 | |
| 63 | (define (main args)
|
| 64 | (fluid-set! %default-port-encoding #f)
|
| 65 | (let* ((files-from (get-option args "--files-from="))
|
| 66 | (default-domain (get-option args "--default-domain="))
|
| 67 | (directory (or (get-option args "--directory=") "."))
|
| 68 | (xgettext (or (get-option args "--xgettext=") "xgettext"))
|
| 69 | (xgettext-args (filter (negate (option? "--xgettext=")) args))
|
| 70 | (command (match xgettext-args
|
| 71 | ((xgettext.scm args ...)
|
| 72 | `(,xgettext ,@args))))
|
| 73 | (result (apply system* command))
|
| 74 | (status (/ result 256)))
|
| 75 | (if (or (not (zero? status))
|
| 76 | (not files-from))
|
| 77 | (exit status)
|
| 78 | (let* ((text (with-input-from-file files-from read-string))
|
| 79 | (lines (string-split text #\newline))
|
| 80 | (files (filter (negate (cute string-prefix? "#" <>)) lines))
|
| 81 | (files (map (cute string-append directory "/" <>) files))
|
| 82 | (git-command `("git" "log" "--pretty=format:%ci" "-n1" ,@files))
|
| 83 | (timestamp (pipe-command git-command))
|
| 84 | (source-date-epoch (or (getenv "SOURCE_DATE_EPOCH") "1"))
|
| 85 | (timestamp (if (string-null? timestamp) source-date-epoch
|
| 86 | timestamp))
|
| 87 | (po-file (string-append default-domain ".po")))
|
| 88 | (substitute* po-file
|
| 89 | (("(\"POT-Creation-Date: )[^\\]*" all header)
|
| 90 | (string-append header timestamp)))))))
|