build: Have configure create a git archive.
[mes.git] / guix.scm
1 ;;; guix.scm -- Guix package definition
2
3 ;;; Mes --- Maxwell Equations of Software
4 ;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5
6 ;;; Also borrowing code from:
7 ;;; guile-sdl2 --- FFI bindings for SDL2
8 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
9
10 ;;;
11 ;;; guix.scm: This file is part of Mes.
12 ;;;
13 ;;; Mes is free software; you can redistribute it and/or modify it
14 ;;; under the terms of the GNU General Public License as published by
15 ;;; the Free Software Foundation; either version 3 of the License, or (at
16 ;;; your option) any later version.
17 ;;;
18 ;;; Mes is distributed in the hope that it will be useful, but
19 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 ;;; GNU General Public License for more details.
22 ;;;
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with Mes.  If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Commentary:
27 ;;
28 ;; GNU Guix development package.  To build and install, run:
29 ;;
30 ;;   guix package -f guix.scm
31 ;;
32 ;; To build it, but not install it, run:
33 ;;
34 ;;   guix build -f guix.scm
35 ;;
36 ;; To use as the basis for a development environment, run:
37 ;;
38 ;;   guix environment -l guix.scm
39 ;;
40 ;;; Code:
41
42 (use-modules (srfi srfi-1)
43              (srfi srfi-26)
44              (ice-9 match)
45              (ice-9 popen)
46              (ice-9 rdelim)
47              (gnu packages)
48              (gnu packages base)
49              (gnu packages commencement)
50              (gnu packages cross-base)
51              (gnu packages gcc)
52              (gnu packages guile)
53              (gnu packages man)
54              (gnu packages mes)
55              (gnu packages package-management)
56              (gnu packages version-control)
57              (gnu packages perl)
58              (gnu packages texinfo)
59              ((guix build utils) #:select (with-directory-excursion))
60              (guix build-system gnu)
61              (guix build-system trivial)
62              (guix gexp)
63              (guix download)
64              (guix git-download)
65              (guix licenses)
66              (guix packages))
67
68 (define %source-dir (dirname (current-filename)))
69
70 (define git-file?
71   (let* ((pipe (with-directory-excursion %source-dir
72                  (open-pipe* OPEN_READ "git" "ls-files")))
73          (files (let loop ((lines '()))
74                   (match (read-line pipe)
75                     ((? eof-object?)
76                      (reverse lines))
77                     (line
78                      (loop (cons line lines))))))
79          (status (close-pipe pipe)))
80     (lambda (file stat)
81       (match (stat:type stat)
82         ('directory #t)
83         ((or 'regular 'symlink)
84          (any (cut string-suffix? <> file) files))
85         (_ #f)))))
86
87 (define-public nyacc-for-mes
88   (package
89     (inherit nyacc)
90     (version "0.80.42")
91       (source (origin
92                 (method url-fetch)
93                 (uri (string-append "https://gitlab.com/janneke/nyacc"
94                                     "/-/archive/v" version
95                                     "/nyacc-" version ".tar.gz"))
96                 (sha256
97                  (base32
98                   "0c8c8kxir0h2d4nxr131xbkfs7c80haipmkp2g6677sh14wn0b3y"))))))
99
100 (define-public mescc-tools
101   (package
102     (name "mescc-tools")
103     (version "0.5.1")
104     (source (origin
105               (method url-fetch)
106               (uri (string-append
107                     "https://github.com/oriansj/mescc-tools/archive/Release_"
108                     version
109                     ".tar.gz"))
110               (file-name (string-append name "-" version ".tar.gz"))
111               (sha256
112                (base32
113                 "0rsxbjc3bg0jl3h7ai4hndxx2iyyk8bvwj9nd3xv2vgz3bmypnah"))))
114     (build-system gnu-build-system)
115     (supported-systems '("i686-linux" "x86_64-linux"))
116     (arguments
117      `(#:make-flags (list (string-append "PREFIX=" (assoc-ref %outputs "out")))
118        #:test-target "test"
119        #:phases (modify-phases %standard-phases
120                   (delete 'configure))))
121     (synopsis "Tools for the full source bootstrapping process")
122     (description
123      "Mescc-tools is a collection of tools for use in a full source
124 bootstrapping process.  Currently consists of the M1 macro assembler and the
125 hex2 linker.")
126     (home-page "https://github.com/oriansj/mescc-tools")
127     (license gpl3+)))
128
129 (define-public mes
130   (let ((commit "f9a4e219727bedd504ea49885c3260c38755c1d0")
131         (revision "0")
132         (triplet "i686-unknown-linux-gnu")
133         (version "0.16"))
134     (package
135       (name "mes")
136       (version (string-append version "-" revision "." (string-take commit 7)))
137       (source (origin
138                 (method git-fetch)
139                 (uri (git-reference
140                       (url "https://gitlab.com/janneke/mes")
141                       (commit commit)))
142                 (file-name (string-append name "-" version))
143                 (sha256
144                  (base32 "0dsilpm9bzsz5cprvlxjf86xk7zhihr7vkm5svi5rjyavig0s644"))))
145       (build-system gnu-build-system)
146       (supported-systems '("i686-linux" "x86_64-linux"))
147       (propagated-inputs
148        `(("mescc-tools" ,mescc-tools)
149          ("nyacc" ,nyacc-for-mes)))
150       (native-inputs
151        `(("git" ,git)
152          ("guile" ,guile-2.2)
153          ,@(if (string-prefix? "x86_64-linux" (or (%current-target-system)
154                                                   (%current-system)))
155                ;; Use cross-compiler rather than #:system "i686-linux" to get
156                ;; MesCC 64 bit .go files installed ready for use with Guile.
157                `(("i686-linux-binutils" ,(cross-binutils triplet))
158                  ("i686-linux-gcc" ,(cross-gcc triplet)))
159                '())
160          ("help2man" ,help2man)
161          ("perl" ,perl)                ; build-aux/gitlog-to-changelog
162          ("texinfo" ,texinfo)))
163       (arguments
164        `(#:phases
165          (modify-phases %standard-phases
166            (add-before 'build 'make-git-source-writable
167            (lambda* (#:key outputs #:allow-other-keys)
168              (for-each make-file-writable
169                        (find-files "." ".*\\.M1"))))
170            (add-before 'install 'generate-changelog
171              (lambda _
172                (with-output-to-file "ChangeLog"
173                  (lambda ()
174                    (display "Please run
175     build-aux/gitlog-to-changelog --srcdir=<git-checkout> > ChangeLog\n")))
176                #t))
177            (delete 'strip)))) ; binutil's strip b0rkes Mescc/M1/hex2 binaries
178       (synopsis "Scheme interpreter and C compiler for full source bootstrapping")
179       (description
180        "Mes [Maxwell Equations of Software] aims to create full source
181 bootstrapping for GuixSD.  It consists of a mutual self-hosting [close to
182 Guile-] Scheme interpreter prototype in C and a Nyacc-based C compiler in
183 [Guile] Scheme.")
184       (home-page "https://gitlab.com/janneke/mes")
185       (license gpl3+))))
186
187 (define-public mes.git
188  (let ((version "0.16")
189         (revision "0")
190         (commit (read-string (open-pipe "git show HEAD | head -1 | cut -d ' ' -f 2" OPEN_READ))))
191     (package
192       (inherit mes)
193       (name "mes.git")
194       (version (string-append version "-" revision "." (string-take commit 7)))
195       (source (local-file %source-dir #:recursive? #t #:select? git-file?)))))
196
197 ;; Return it here so `guix build/environment/package' can consume it directly.
198 mes.git