summaryrefslogtreecommitdiff
path: root/guix.scm
blob: 3c2a8d332c52a22b2c1e7b193238224962e6c3e3 (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
(define-module (guix)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages base)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages build-tools)
  #:use-module (gnu packages check)
  #:use-module (gnu packages code)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages glib)
  #:use-module (gnu packages gnome)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages imagemagick)
  #:use-module (gnu packages perl)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages tex)
  #:use-module (gnu packages texinfo)
  #:use-module (gnu packages valgrind)
  #:use-module (gnu packages version-control)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix build utils)
  #:use-module (guix build-system gnu)
  #:use-module (guix gexp)
  #:use-module (guix git-download)
  #:use-module (guix git)
  #:use-module (guix modules)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (guix store)
  #:use-module (guix monads)
  #:use-module (guix derivations)
  #:use-module (guix download)
  #:use-module (ice-9 popen)
  #:use-module (ice-9 rdelim)
  #:use-module (srfi srfi-19))

(define git-exec
  (run-with-store
   (open-connection)
   (mlet %store-monad ((git (package->derivation git)))
         (mlet %store-monad ((built
                              (built-derivations
                               (list git))))
               (return (string-append (derivation->output-path git)
                                      "/bin/git"))))))

(define disfluid:package-version
  (with-directory-excursion
      (dirname (current-filename))
    (let ((port (open-pipe* OPEN_READ git-exec "describe" "--tags")))
      (let ((version (read-line port)))
        (when (eof-object? version)
          (set! version "0.0.0"))
        (close-port port)
	version))))

(define disfluid:commit-date
  (with-directory-excursion
      (dirname (current-filename))
    (let ((port (open-pipe* OPEN_READ git-exec "log" "-1" "--format=%ci")))
      (let ((date (read-line port)))
        (close-port port)
        (string->date date "~Y-~m-~d ~H:~M:~S ~z")))))

(define disfluid:local-dir
  (dirname (current-filename)))

(define disfluid:package-source
  (git-checkout
   (url (string-append "file://" disfluid:local-dir))))

(define disfluid:translations
  (git-checkout
   (url (string-append "file://" (dirname (current-filename))))
   (branch "translations")))

(define disfluid:raw-source
  (computed-file "disfluid-raw-source"
    (with-imported-modules
        (source-module-closure '((guix build utils)))
      #~(begin
          (use-modules (guix build utils))
          (mkdir-p #$output)
          (with-directory-excursion #$output
            (invoke #$(file-append git "/bin/git") "init")
            (invoke #$(file-append git "/bin/git") "branch" "-m" "main")
            (invoke #$(file-append git "/bin/git") "config"
                    "user.email" "vivien@planete-kraus.eu")
            (invoke #$(file-append git "/bin/git") "config"
                    "user.name" "Vivien Kraus")
            (copy-recursively #$(file-append disfluid:package-source "/.") "."
                              #:follow-symlinks? #t)
            (invoke #$(file-append git "/bin/git") "add" ".")
            (invoke #$(file-append git "/bin/git") "commit"
                    "-m" #$(format #f "Set up disfluid source code for ~a" disfluid:package-version))
            (invoke #$(file-append git "/bin/git") "checkout" "-b" "translations")
            (copy-recursively #$(file-append disfluid:translations "/.") "."
                              #:follow-symlinks? #t)
            (invoke #$(file-append git "/bin/git") "add" ".")
            (false-if-exception
             (invoke #$(file-append git "/bin/git") "commit"
                     "-m" #$(format #f "Set up disfluid translations for ~a"
                                    disfluid:package-version)))
            (invoke #$(file-append git "/bin/git") "checkout" "main")
            (invoke #$(file-append git "/bin/git") "tag" "-a"
                    "-m" #$(format #f "Version ~a" disfluid:package-version)
                    #$(format #f "v~a" disfluid:package-version)))))))

(define-public disfluid-boot
  (package
    (name "disfluid-boot")
    (version disfluid:package-version)
    (source disfluid:raw-source)
    (build-system gnu-build-system)
    (arguments
     (list
      #:phases
      #~(modify-phases
            %standard-phases
          (add-before 'bootstrap 'bootstrap-bootstrap
            (lambda _
              (invoke "sh" "bootstrap-bootstrap")))
          (add-after 'bootstrap 'fix-/bin/sh-in-po
            (lambda _
	      (substitute*
	          "po/Makefile.in.in"
	        (("SHELL = /bin/sh")
	         (format #f "SHELL = ~a" (which "sh"))))))
          (add-after 'check 'syntax-check
            (lambda _
              (invoke "make" "syntax-check")))
          (replace 'install
            (lambda _
              (invoke "git" "checkout" "--" "bootstrap-bootstrap")
              (patch-shebang "configure")
              (invoke "make" "-j8" "distcheck"
                      (format #f "DISTCHECK_CONFIGURE_FLAGS=SHELL=~a" (which "sh")))
              (invoke "tar" "xf" #$(format #f "disfluid-~a.tar.gz" disfluid:package-version))
              (with-directory-excursion
                  #$(format #f "disfluid-~a" disfluid:package-version)
                  (substitute* "po/Makefile.in.in"
                    (("SHELL = /gnu/store/.*/bin/sh")
                     "SHELL = /bin/sh"))
                  (substitute* "configure"
                    (("#!/gnu/store/.*/bin/sh")
                     "#!/bin/sh"))
                  (substitute* "configure"
                    (("/gnu/store/.*/bin/file")
                     "/bin/file"))
                  (with-directory-excursion "build-aux"
                    (substitute* '("config.rpath" "git-version-gen" "gitlog-to-changelog"
                                   "install-sh" "do-release-commit-and-tag"
                                   "useless-if-before-free" "test-driver" "depcomp"
                                   "announce-gen" "ltmain.sh" "config.sub" "libtool-reloc"
                                   "missing" "config.libpath" "reloc-ldflags" "ar-lib"
                                   "config.guess" "vc-list-files" "install-reloc")
                      (("#!/gnu/store/.*/bin/sh")
                       "#!/bin/sh"))))
              (invoke "sh" "-c" "grep '/gnu/store/' -R disfluid-* && exit 1 ; true")
              (mkdir-p #$output)
              (invoke "tar"
                      #$(format #f "--mtime=~a" (date->string disfluid:commit-date "~4"))
                      "--sort=name"
                      "--owner=0" "--group=0" "--numeric-owner"
                      "--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime"
                      "-cvzf" (string-append #$output "/complete-source.tar.gz")
                      #$(format #f "disfluid-~a" disfluid:package-version)))))))
    (native-inputs
     (list autoconf autoconf-archive automake libtool gnu-gettext
	   git valgrind (list glibc "debug")
	   tar gzip global pkg-config
	   texinfo (texlive-updmap.cfg (list texlive))
           perl gnulib gtk check (list glib "bin")
           gobject-introspection imagemagick))
    (inputs
     (list gtk libadwaita check gnu-gettext))
    (home-page "https://labo.planete-kraus.eu/disfluid.git")
    (synopsis "Demanding Interoperability to Strengthen the Free/Libre Web: Introducing Disfluid")
    (description "This provides tools for web interoperability.")
    (license license:agpl3+)))

(package
  (inherit disfluid-boot)
  (name "disfluid")
  (source #f)
  (outputs (list "out" "complete-corresponding-source.tar.gz"))
  (arguments
   (list
    #:phases
    #~(modify-phases %standard-phases
        (replace 'unpack
          (lambda _
            (invoke "tar" "xf" #+(file-append disfluid-boot "/complete-source.tar.gz"))
            (chdir #$(format #f "disfluid-~a" disfluid:package-version))))
        (replace 'install-license-files
          (lambda _
            ;; Do not try to install COPYING in the
            ;; complete-corresponding-source.tar.gz output
            (let ((dir (format #f "~a/~a"
                               #$output
                               #$(format #f "share/doc/disfluid-~a"
                                         disfluid:package-version))))
              (mkdir-p dir)
              (copy-file "COPYING" (string-append dir "/COPYING")))))
        (add-after 'install 'install-complete-corresponding-source
          (lambda _
            (mkdir-p (string-append #$output "/share/disfluid"))
            (copy-file #+(file-append disfluid-boot "/complete-source.tar.gz")
                       #$output:complete-corresponding-source.tar.gz))))))
  (native-inputs
   (list valgrind (list glibc "debug") pkg-config
         texinfo (texlive-updmap.cfg (list texlive)) tar gzip))
  (inputs
   (list gnu-gettext gtk libadwaita check)))