summaryrefslogtreecommitdiff
path: root/disfluid/build/bootstrap.scm
blob: b4ee375e6fb2a6e1a13c045ca08416b94192bc34 (plain)
1
2
3
4
5
6
7
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
(define-module (disfluid build bootstrap)
  #:use-module (disfluid i18n)
  #:use-module (ice-9 popen)
  #:use-module (ice-9 receive)
  #:use-module (ice-9 rdelim)
  #:use-module (ice-9 match)
  #:use-module (ice-9 ftw)
  #:use-module (ice-9 optargs)
  #:declarative? #t
  #:export (main))

(define* (main #:key
               (emacs "emacs")
               (hall "hall")
               (git "git")
               (mkdir "mkdir")
               (which "which")
               (autoreconf "autoreconf"))
  (let ((config (false-if-exception
                 (resolve-interface '(disfluid config)))))
    ;; The build system is internationalized, but a prior version of it
    ;; is necessary to get the localedir. Otherwise, gettext cannot be
    ;; set up.
    (when config
      (bindtextdomain "disfluid" (module-ref config 'localedir))
      (textdomain "disfluid")))
  (let ((disfluid-version
         (with-exception-handler
             (lambda (exn)
               ;; .tarball-version is not present, use git
               (receive (from to pids)
                   (pipeline
                    `((,git "describe" "--tags" "--dirty" "--broken")))
                 (match (read-line from)
                   ((? eof-object? _)
                    "SNAPSHOT")
                   (version version))))
           (lambda ()
             ;; Try to read from .tarball-version
             (call-with-input-file ".tarball-version"
               read-line))
           #:unwind? #t)))
    (call-with-output-file "hall.scm"
      (lambda (port)
        (write
         `(hall-description
           (name "disfluid")
           (prefix "")
           (version ,disfluid-version)
           (author "Vivien Kraus")
           (copyright (2022))
           (synopsis "Solid stack implementation")
           (description "This package provides a Solid implementation, client and server.")
           (home-page "https://disfluid.planete-kraus.eu")
           (license gpl3+)
           (dependencies `())
           (files (libraries
                   ((scheme-file "disfluid")
                    (directory "disfluid" ())))
                  (tests ((directory "tests" ())))
                  (programs ((directory "scripts" ())))
                  (documentation
                   ((org-file "README")
                    (symlink "README" "README.org")
                    (text-file "HACKING")
                    (text-file "COPYING")
                    (directory "doc" ((texi-file "disfluid")))))
                  (infrastructure
                   ((scheme-file "hall")))))
         port)))
    ;; Before the scan, add a dummy disfluid/config.scm so that it is
    ;; seen by the scan
    (begin
      (call-with-output-file "disfluid/config.scm"
        (lambda (port)
          (write
           `(define-module (disfluid config)) port)))
      (system* hall "scan" "-x")
      (delete-file "disfluid/config.scm"))
    (system* hall "distribute" "-x")
    ;; Add (disfluid config)
    (system* emacs "--batch"
             "--file" "configure.ac"
             "--eval"
             (format #f "~s"
                     `(progn
                       (search-forward "AC_OUTPUT")
                       (beginning-of-line)
                       (insert "AX_RECURSIVE_EVAL([$localedir], EXPANDED_LOCALEDIR)")
                       (newline)
                       (insert "AC_SUBST([EXPANDED_LOCALEDIR])")
                       (newline)
                       (insert "AC_CONFIG_FILES([disfluid/config.scm])")
                       (newline)
                       (save-buffer)))
             "--file" "Makefile.am"
             "--eval"
             (format #f "~s"
                     `(progn
                       (end-of-buffer)
                       (insert "dist-hook:")
                       (newline)
                       (insert-tab)
                       (insert "rm -f $(distdir)/disfluid/config.scm")
                       (newline)
                       (save-buffer))))
    (call-with-output-file "disfluid/config.scm.in"
      (lambda (port)
        (write
         `(define-module (disfluid config)
            #:export (localedir))
         port)
        (newline port)
        (write
         `(define localedir "@EXPANDED_LOCALEDIR@")
         port)))
    ;; Use gettext
    (system* emacs "--batch"
             "--file" "configure.ac"
             "--eval"
             (format #f "~s"
                     `(progn
                       (beginning-of-buffer)
                       (search-forward "AC_OUTPUT")
                       (beginning-of-line)
                       (insert "AM_GNU_GETTEXT([external])")
                       (newline)
                       (insert "AM_GNU_GETTEXT_VERSION([0.21])")
                       (newline)
                       (beginning-of-buffer)
                       (search-forward "AC_CONFIG_FILES([Makefile")
                       (insert " po/Makefile.in")
                       (save-buffer))))
    (system* emacs "--batch"
             "--file" "Makefile.am"
             "--eval"
             (format #f "~s"
                     `(progn
                       (beginning-of-buffer)
                       (insert "SUBDIRS = po")
                       (newline)
                       (search-forward "EXTRA_DIST =")
                       (insert " guix.scm ")
                       (save-buffer))))
    (system* mkdir "-p" "po")
    (call-with-output-file "po/Makevars"
      (lambda (port)
        (format port "\
DOMAIN = $(PACKAGE)
subdir = po
top_builddir = ..
XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ --keyword=G_
COPYRIGHT_HOLDER = Viven Kraus
PACKAGE_GNU =
MSGID_BUGS_ADDRESS = vivien@planete-kraus.eu
EXTRA_LOCALE_CATEGORIES =
USE_MSGCTXT = no
MSGMERGE_OPTIONS =
MSGINIT_OPTIONS =
PO_DEPENDS_ON_POT = yes
DIST_DEPENDS_ON_UPDATE_PO = yes
")))
    (call-with-output-file "po/POTFILES.in"
      (lambda (port)
        (define (enter? name stat result)
          (not (member (basename name) '(".git" ".svn" "CVS" ".last-commit"))))
        (define (leaf name stat result)
          (if (or (string-suffix? ".scm" name)
                  (string-suffix? ".scm.in" name))
              (match result
                ((directory . files)
                 `(,directory . (,name . ,files))))
              result))
        (define (down name stat result)
          (match result
            ((() . files)
             `((,name) . ,files))
            ((directory . files)
             `((,name
                ,@directory)
               . ,files))))
        (define (up name stat result)
          (match result
            (((_ . directory) . files)
             `(,directory . ,files))))
        (define (skip name stat result)
          result)
        (define (error name stat errno result)
          (format (current-error-port) (G_ "Warning: ~a: ~a~%")
                  name (strerror errno))
          result)
        (match
            (file-system-fold enter? leaf down up skip error
                              '(() . ())
                              ".")
          ((() . files)
           (for-each
            (lambda (file)
              (display file port)
              (newline port))
            (sort files string<?))))))
    ;; Install the post-commit hook
    (system* mkdir "-p" ".git/hooks")
    (call-with-output-file ".git/hooks/post-commit-"
      (lambda (port)
        (format port
                "#!~a -s
!#

(add-to-load-path ~s)

(use-modules (disfluid build post-commit-hook))

(main)
"
                (receive (from to pids)
                    (pipeline
                     `((,which "guile")))
                  (match `(,pids ,(read-line from))
                    ((((= waitpid
                          (_ . (= status:exit-val 0))))
                      (? string? guile))
                     guile)
                    (else
                     (format (current-error-port)
                             (G_ "Cannot find guile, using /usr/local/bin/guile."))
                     "/usr/local/bin/guile")))
                (dirname (dirname (dirname (current-filename)))))))
    (chmod ".git/hooks/post-commit-" #o755)
    (rename-file ".git/hooks/post-commit-" ".git/hooks/post-commit")
    ;; Also distribute the channels.scm file, so that it can be
    ;; internationalized
    (system* emacs "--batch"
             "--file" "Makefile.am"
             "--eval"
             (format #f "~s"
                     `(progn
                       (search-forward "EXTRA_DIST =")
                       (insert " channels.scm ")
                       (save-buffer))))
    (system* autoreconf "-vif")))