summaryrefslogtreecommitdiff
path: root/disfluid/maintainer/new-phases.scm
blob: 7e143aec5d41a38e6aecb345b3f19c08f25cddc1 (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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
;; disfluid, implementation of the Solid specification
;; Copyright (C) 2022  Vivien Kraus

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU Affero General Public License for more details.

;; You should have received a copy of the GNU Affero General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

(define-module (disfluid maintainer new-phases)
  #:use-module (guix gexp)
  #:use-module (gnu packages base)
  #:use-module (gnu packages guile-xyz)
  #:declarative? #t
  #:export (new-phases))

;; new-phases should be the content of the #:phase argument of the
;; disfluid package. It adds phases to set up the build system,
;; generate the complete source code distribution and more.

(define kwote (string->symbol "quote"))

(define (new-phases scan)
  (let ((version (assq-ref scan 'version)))
    `(modify-phases %standard-phases
       (add-after 'unpack 'fix-mtime
         (lambda _
           (let ((disfluid-mtimes (,kwote ,(assq-ref scan 'mtimes))))
             (for-each
              ((@ (ice-9 match) match-lambda)
                ((file . mtime)
                 (utime file mtime mtime)))
              disfluid-mtimes))))
       (add-before 'bootstrap 'fix-hall.scm
         (lambda _
           (let ((disfluid-version ,version))
             (substitute* "hall.scm"
               (("SNAPSHOT") disfluid-version)))))
       (add-after 'fix-hall.scm 'hall-scan
         (lambda _
           (setenv "HOME" (getcwd))
           ;; hall scan needs to know there will be a module (disfluid
           ;; config), but disfluid/config.scm has not been generated
           ;; yet.
           (call-with-output-file "disfluid/config.scm"
             (lambda (port)
               (write
                `(define-module (disfluid config))
                port)))
           (invoke "hall" "scan" "-x")
           (delete-file "disfluid/config.scm")))
       (add-after 'hall-scan 'hall-build-system
         (lambda _
           (invoke "hall" "build-system" "-x")
           (substitute* "Makefile.am"
             (("EXTRA_DIST =")
              "EXTRA_DIST = guix.scm channels.scm"))))
       (add-after 'hall-build-system 'support-config.scm
         (lambda _
           (let ((expanded-variables
                  '(("prefix" . "PREFIX")
                    ("bindir" . "BINDIR")
                    ("exec_prefix" . "EXEC_PREFIX")
                    ("guilemoduledir" . "GUILEMODULEDIR")
                    ("guileobjectdir" . "GUILEOBJECTDIR")
                    ("localedir" . "LOCALEDIR"))))
             (let ((subst
                    (string-join
                     (map
                      ((@ (ice-9 match) match-lambda)
                        ((var . expanded)
                         (format #f "\
AX_RECURSIVE_EVAL([$~a], EXPANDED_~a)
AC_SUBST([EXPANDED_~a])"
                                 var expanded expanded)))
                      expanded-variables)
                     "\n")))
               (substitute* "configure.ac"
                 (("AC_OUTPUT")
                  (string-append subst "
AC_CONFIG_FILES([disfluid/config.scm])
AC_OUTPUT")))))
           (rename-file "Makefile.am" "hall.mk")
           (call-with-output-file "Makefile.am"
             (lambda (port)
               (format port "\
include %reldir%/hall.mk

dist-hook:
\trm -rf $(distdir)/disfluid/config.scm
")))
           (call-with-output-file "disfluid/config.scm.in"
             (lambda (port)
               (for-each
                (lambda (code)
                  ((@ (ice-9 pretty-print) pretty-print) code port)
                  (newline port))
                '((define-module (disfluid config)
                    #:export
                    (
                     package
                      package-bugreport
                      version
                      localedir
                      guilemoduledir
                      prefix
                      exec-prefix
                      pkg-config
                      ))
                  (define package "@PACKAGE@")
                  (define package-bugreport "@PACKAGE_BUGREPORT@")
                  (define version "@VERSION@")
                  (define prefix "@EXPANDED_PREFIX@")
                  (define exec-prefix "@EXPANDED_EXEC_PREFIX@")
                  (define localedir "@EXPANDED_LOCALEDIR@")
                  (define guilemoduledir "@EXPANDED_GUILEMODULEDIR@")
                  (define pkg-config "@PKG_CONFIG@")))))))
       (add-after 'support-config.scm 'gettextize
         (lambda _
           (substitute* "configure.ac"
             (("AC_OUTPUT")
              "
AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION([0.21])
AC_OUTPUT
")
             (("AC_CONFIG_FILES\\(\\[Makefile")
              "AC_CONFIG_FILES([Makefile po/Makefile.in"))
           (substitute* "hall.mk"
             (("EXTRA_DIST =")
              "EXTRA_DIST = guix.scm channels.scm"))
           (rename-file "Makefile.am" "withconfig.mk")
           (call-with-output-file "Makefile.am"
             (lambda (port)
               (format port "SUBDIRS = po
include withconfig.mk
")))
           (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 "collect-potfiles.sh"
           (lambda (port)
             (format port "
(for pattern in '*.scm' ;
 do find . -name \"$pattern\" ;
 done) > po/POTFILES.in
")
             (chmod port #o755)))
         (call-with-output-file "collect-linguas.sh"
           (lambda (port)
             (format port "
(for pofile in po/*.po ;
 do echo \"$pofile\" | cut -d '/' -f 2 | cut -d '.' -f 1 ;
 done) > po/LINGUAS
")
             (chmod port #o755)))
         (invoke "bash" "collect-potfiles.sh")
         (invoke "bash" "collect-linguas.sh")))
       (add-after 'hall-build-system 'define-package-bugreport
         (lambda _
           (substitute* "configure.ac"
             (("AC_INIT")
              (format #f "AC_INIT([disfluid], [~a], [vivien@planete-kraus.eu])
dnl AC_INIT"
                      ,version)))))
       (add-after 'unpack 'fix-gnutls-location
         (lambda* (#:key inputs #:allow-other-keys)
           (let ((gnutls (search-input-file inputs "/lib/libgnutls.so")))
             (substitute* '("disfluid/gnutls/datum.scm"
                            "disfluid/gnutls/global.scm"
                            "disfluid/gnutls/pubkey.scm"
                            "disfluid/gnutls/privkey.scm"
                            "disfluid/gnutls/x509/privkey.scm")
               (("\"libgnutls\"")
                (format #f "~s" gnutls))))))
       (add-after 'bootstrap 'fix-po-makefile-shell
         (lambda _
           (substitute* "po/Makefile.in.in"
             (("SHELL = /bin/sh")
              "SHELL = @SHELL@"))))
       (add-after 'check 'distcheck
         (lambda* (#:key make-flags inputs #:allow-other-keys)
           (apply invoke "make"
                  `(,@make-flags
                    "distcheck"
                    ,(format #f "DISTCHECK_CONFIGURE_FLAGS=SHELL=~a"
                             (search-input-file inputs "/bin/bash"))))
           (copy-file ,(format #f "disfluid-~a.tar.gz" version)
                      ,(format #f "/tmp/disfluid-~a.tar.gz" version))
           (with-directory-excursion "/tmp"
             (invoke "tar" "xf"
                     ,(format #f "disfluid-~a.tar.gz" version))
             (delete-file ,(format #f "disfluid-~a.tar.gz" version))
             (invoke "tar"
                     ;; see https://reproducible-builds.org/docs/archives/
                     "--sort=name"
                     "--mtime=2022-01-01 00:00Z"
                     "--owner=0"
                     "--group=0"
                     "--numeric-owner"
                     "--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime"
                     "-cf" ,(format #f "disfluid-~a.tar.gz" version)
                     ,(format #f "disfluid-~a" version)))
           (copy-file ,(format #f "/tmp/disfluid-~a.tar.gz" version)
                      ,(format #f "disfluid-~a.tar.gz" version))))
       (add-after 'build 'html
         (lambda* (#:key make-flags #:allow-other-keys)
           (apply invoke "make" "html" make-flags)))
       (add-before 'check 'set-tz
         (lambda* (#:key inputs #:allow-other-keys)
           (setenv "TZ" "CET")
           (setenv "TZDIR"
                   (search-input-directory inputs
                                           "share/zoneinfo"))))
       (add-after 'install 'install-complete-corresponding-source
         (lambda* (#:key outputs #:allow-other-keys)
           (let ((out (assoc-ref outputs "out")))
             (mkdir-p (string-append out "/share/disfluid"))
             (copy-file
              ,(format #f "disfluid-~a.tar.gz" version)
              (string-append
               out
               "/share/disfluid/complete-corresponding-source.tar.gz")))))
       (add-after 'install 'install-html
         (lambda* (#:key make-flags #:allow-other-keys)
           (apply invoke "make" "install-html" make-flags)))
       (add-after 'install 'wrap-disfluid
         (lambda* (#:key inputs outputs #:allow-other-keys)
           (let ((out (assoc-ref outputs "out")))
             (wrap-program (string-append out "/bin/disfluid")
               `("GUILE_LOAD_PATH" prefix
                 ,(search-path-as-list
                   '("share/guile/site/3.0")
                   (map cdr inputs)))
               `("GUILE_COMPILED_LOAD_PATH" prefix
                 ,(search-path-as-list
                   '("lib/guile/3.0/site-ccache")
                   (map cdr inputs)))
               `("GUILE_EXTENSIONS_PATH" prefix
                 ,(search-path-as-list
                   '("lib")
                   (map cdr inputs))))))))))