|
| 1 | +;;; pq-compile.el --- Compile the `pq-core` module -*- lexical-binding: t; -*- |
| 2 | + |
| 3 | +;; Copyright (C) 2022 Free Software Foundation, Inc. |
| 4 | + |
| 5 | +;; This program is free software; you can redistribute it and/or modify |
| 6 | +;; it under the terms of the GNU General Public License as published by |
| 7 | +;; the Free Software Foundation, either version 3 of the License, or |
| 8 | +;; (at your option) any later version. |
| 9 | + |
| 10 | +;; This program is distributed in the hope that it will be useful, |
| 11 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +;; GNU General Public License for more details. |
| 14 | + |
| 15 | +;; You should have received a copy of the GNU General Public License |
| 16 | +;; along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +;;; Commentary: |
| 19 | + |
| 20 | +;; |
| 21 | + |
| 22 | +;;; Code: |
| 23 | + |
| 24 | +(defvar pq--compile-directory |
| 25 | + (file-name-directory |
| 26 | + (or |
| 27 | + (if (fboundp 'macroexp-file-name) (macroexp-file-name)) ;Emacs≥28 |
| 28 | + load-file-name |
| 29 | + buffer-file-name |
| 30 | + (locate-library "pq")))) |
| 31 | + |
| 32 | +(defun pq--compile-module () |
| 33 | + "Compile the `pq-core' module." |
| 34 | + (with-temp-buffer |
| 35 | + (setq default-directory pq--compile-directory) |
| 36 | + (let* ((exitcode (call-process "make" nil t))) |
| 37 | + (if (zerop exitcode) |
| 38 | + (message "Compilation of `pq-core' succeeded") |
| 39 | + (let ((out (buffer-string))) |
| 40 | + (with-current-buffer (get-buffer-create "*pq-compile*") |
| 41 | + (setq default-directory pq--compile-directory) |
| 42 | + (let ((inhibit-read-only t)) |
| 43 | + (erase-buffer) |
| 44 | + (insert out)) |
| 45 | + (compilation-mode) |
| 46 | + (pop-to-buffer (current-buffer)) |
| 47 | + (error "Compilation of `pq-core' failed"))))))) |
| 48 | + |
| 49 | +(defun pq--compile-maybe () |
| 50 | + ;; FIXME: Should we first try it silently (i.e. without prompting the user)? |
| 51 | + (if (not (y-or-n-p "PQ needs to compile the `pq-core' module. Do it now?")) |
| 52 | + (message "Continuing without `pq-core'; some operations may fail") |
| 53 | + (pq--compile-module) |
| 54 | + (require 'pq-core))) |
| 55 | + |
| 56 | + |
| 57 | +(provide 'pq-compile) |
| 58 | +;;; pq-compile.el ends here |
0 commit comments