Subject: [PATCH] gnu: Add libx86emu.

From: Vincent Legoll <[email-masked]>
Date: Sat, 9 Jan 2021 15:42:56 +0100

* gnu/packages/emulators.scm (libx86emu): New variable.
---
 gnu/packages/emulators.scm | 48 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/gnu/packages/emulators.scm b/gnu/packages/emulators.scm
index 1d94090f48..4b76dcef79 100644
--- a/gnu/packages/emulators.scm
+++ b/gnu/packages/emulators.scm
@@ -72,6 +72,7 @@
   #:use-module (gnu packages music)
   #:use-module (gnu packages ncurses)
   #:use-module (gnu packages networking)
+  #:use-module (gnu packages perl)
   #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages pulseaudio)
   #:use-module (gnu packages python)
@@ -591,6 +592,53 @@ and Game Boy Color games.")
     ;; BSD-3, and "discord-rpc" is Expat.
     (license (list license:mpl2.0 license:lgpl2.1+ license:bsd-3 license:expat))))
 
+(define-public libx86emu
+  (package
+    (name "libx86emu")
+    (version "3.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/wfeldt/libx86emu")
+             (commit version)))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "104xqc6nj9rpi7knl3dfqvasf087hlz2n5yndb1iycw35a6j509b"))))
+    (build-system gnu-build-system)
+    (native-inputs
+     `(("nasm" ,nasm)
+       ("perl" ,perl)))   ; for the `./test/prepare_test' script
+    (arguments
+     `(#:phases
+       (modify-phases %standard-phases
+         (add-after 'unpack 'version-file
+           (lambda _
+             (invoke "chmod" "-x" "./git2log")    ; we are not in a full git repository
+             (with-output-to-file "./VERSION"     ; emulate what git2log would have done
+               (lambda _
+                 (display ,version)))
+             #t))
+         (replace 'check
+           (lambda _
+             (invoke "make" "test")))
+         (replace 'install
+           (lambda* (#:key outputs #:allow-other-keys)
+             (invoke "make" "install"
+                     (string-append "DESTDIR=" (assoc-ref outputs "out"))
+                     (string-append "LIBDIR=" (assoc-ref outputs "out") "/usr/lib")) ; avoid using `ldd /bin/sh' to choose between 32 and 64 bits libdir
+             #t))
+         (delete 'configure))))
+    (home-page "https://github.com/wfeldt/libx86emu")
+    (synopsis "x86 emulation library")
+    (description "libx86emu is a small library to emulate x86 instructions.  The
+focus here is not a complete emulation (use qemu for this) but to cover enough
+for typical firmware blobs.  At the moment 'regular' 32-bit instructions are
+covered together with basic protected mode support.  Not done are fpu, mmx, or
+any of the other instruction set extensions.")
+    (license (license:non-copyleft
+              "https://github.com/wfeldt/libx86emu/blob/master/LICENSE"))))
+
 (define-public sameboy
   (package
     (name "sameboy")
-- 
2.30.0