emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/emacsql 394bb062aa 219/427: Add a small library for determ


From: ELPA Syncer
Subject: [nongnu] elpa/emacsql 394bb062aa 219/427: Add a small library for determining binary to use.
Date: Tue, 13 Dec 2022 02:59:45 -0500 (EST)

branch: elpa/emacsql
commit 394bb062aa17d9e6214c61f520005c79cc1d06ff
Author: Christopher Wellons <wellons@nullprogram.com>
Commit: Christopher Wellons <wellons@nullprogram.com>

    Add a small library for determining binary to use.
---
 Makefile          |  3 ++-
 emacsql-sqlite.el |  3 ++-
 emacsql-system.el | 44 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 8c0a9554ec..4ee2f453be 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,8 @@ BATCH   := $(VIRTUAL) -batch -Q -L .
 PACKAGE := emacsql
 VERSION := $(shell $(CASK) version)
 
-EL = emacsql-compiler.el emacsql.el emacsql-sqlite.el emacsql-psql.el
+EL = emacsql-compiler.el emacsql-system.el emacsql.el \
+     emacsql-sqlite.el emacsql-psql.el
 ELC = $(EL:.el=.elc)
 EXTRA_DIST = README.md UNLICENSE
 
diff --git a/emacsql-sqlite.el b/emacsql-sqlite.el
index 1d63360920..7491999050 100644
--- a/emacsql-sqlite.el
+++ b/emacsql-sqlite.el
@@ -5,9 +5,10 @@
 (require 'cl-lib)
 (require 'eieio)
 (require 'emacsql)
+(require 'emacsql-system)
 
 (defvar emacsql-sqlite-executable
-  (expand-file-name "bin/emacsql-sqlite-linux-x86_64"
+  (expand-file-name (emacsql-system-binary "bin/emacsql-sqlite")
                     (file-name-directory load-file-name))
   "Path to the Emacsql backend (this is not the sqlite3 shell).")
 
diff --git a/emacsql-system.el b/emacsql-system.el
new file mode 100644
index 0000000000..2ac8bfcc21
--- /dev/null
+++ b/emacsql-system.el
@@ -0,0 +1,44 @@
+;;; emacsql-system.el --- detect OS and machine -*- lexical-binding: t; -*-
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'cl-lib)
+
+(defun emacsql-system-normalize-arch (arch)
+  "Normalize the name of string ARCH."
+  (cl-case (intern arch)
+    ((x86 i386 i486 i586 i686) 'x86)
+    ((x86_64 amd64) 'x86_64)
+    (otherwise (intern arch))))
+
+(defun emacsql-system-architecture ()
+  "Determine this system's architecture."
+  (emacsql-system-normalize-arch
+    (if (executable-find "uname")
+        (with-temp-buffer
+          (call-process "uname" nil (current-buffer) nil "-m")
+          (replace-regexp-in-string "\\s " "" (buffer-string)))
+      (getenv "PROCESSOR_ARCHITECTURE"))))
+
+(defun emacsql-system-tuple ()
+  "Return a tuple (kernel architecture) for the current system."
+  (list
+   (cl-ecase system-type
+     (gnu 'hurd)
+     (gnu/linux 'linux)
+     ((gnu/kfreebsd berkeley-unix) 'bsd)
+     (darwin 'darwin)
+     (ms-dos 'dos)
+     (windows-nt 'windows)
+     (cygwin 'windows))
+   (emacsql-system-architecture)))
+
+(defun emacsql-system-binary (prefix)
+  "Determine an executable name for PREFIX."
+  (concat prefix "-" (mapconcat #'symbol-name (emacsql-system-tuple) "-")))
+
+(provide 'emacsql-system)
+
+;;; emacsql-system.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]