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