From 958831df8698e93b8e23ddb69271ca6a1201f55f Mon Sep 17 00:00:00 2001 From: Kazuhiro Ito Date: Sun, 23 Feb 2025 22:47:00 +0900 Subject: [PATCH] Avoid defining unneeded variables on Cygw32 lisp/term/w32-win.el contained definitions of variables which were not used on Cygw32. It is now to split into two files, common part and Windows native build specific part. The latter is a new file, lisp/term/w32-nt.el. * src/image.c (Qlibpng_version, Qlibgif_version) (Qlibjpeg_version): Don't define on Cygw32 build. * src/treesit.c (Qtree_sitter__library_abi): Ditto. * lisp/term/w32-win.el (dynamic-library-alist, libpng-version) (libgif-version, libjpeg-version, libgnutls-version) (tree-sitter--library-abi, gui-backend-set-selection) (gui-backend-get-selection, gui-backend-selection-owner-p) (gui-selection-exists-p): Moved to lisp/term/w32-nt.el. * lisp/term/w32-nt.el: New file, separated Windows native build specific part from lisp/term/w32-win.el. * lisp/loadup.el: Load term/w32-nt.el on Windows native build. (Bug#75926) (cherry picked from commit 64b3ad5c763ed3d2a9978fce06c0ccbdd085fe35) --- lisp/loadup.el | 1 + lisp/term/w32-nt.el | 153 +++++++++++++++++++++++++++++++++++++++++++ lisp/term/w32-win.el | 108 ------------------------------ src/image.c | 2 +- src/treesit.c | 2 +- 5 files changed, 156 insertions(+), 110 deletions(-) create mode 100644 lisp/term/w32-nt.el diff --git a/lisp/loadup.el b/lisp/loadup.el index 8b7d532317b..3d571315672 100644 --- a/lisp/loadup.el +++ b/lisp/loadup.el @@ -332,6 +332,7 @@ (load "term/w32-win") (load "disp-table") (when (eq system-type 'windows-nt) + (load "term/w32-nt") (load "w32-fns") (load "ls-lisp") (load "dos-w32")) diff --git a/lisp/term/w32-nt.el b/lisp/term/w32-nt.el new file mode 100644 index 00000000000..7ff9472839d --- /dev/null +++ b/lisp/term/w32-nt.el @@ -0,0 +1,153 @@ +;;; w32-nt.el --- MS-Windows native build specific definitions -*- lexical-binding: t -*- + +;; Copyright (C) 1993-1994, 2001-2025 Free Software Foundation, Inc. + +;; Author: FSF +;; Keywords: terminals + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;; w32-nt.el: this file contains MS-Windows native build specific +;; definitions formerly included in w32-win.el. + +;;; Code: + + +(eval-when-compile (require 'cl-lib)) + + +(defvar dynamic-library-alist) +(defvar libpng-version) ; image.c #ifdef HAVE_NTGUI +(defvar libgif-version) +(defvar libjpeg-version) + +(defvar libgnutls-version) ; gnutls.c + +(defvar tree-sitter--library-abi) ; treesit.c + +;;; Set default known names for external libraries +(setq dynamic-library-alist + (list + '(gdiplus "gdiplus.dll") + '(shlwapi "shlwapi.dll") + '(xpm "libxpm.dll" "xpm4.dll" "libXpm-nox4.dll") + ;; Versions of libpng 1.4.x and later are incompatible with + ;; earlier versions. Set up the list of libraries according to + ;; the version we were compiled against. (If we were compiled + ;; without PNG support, libpng-version's value is -1.) + (if (>= libpng-version 10400) + (let ((major (/ libpng-version 10000)) + (minor (mod (/ libpng-version 100) 10))) + (list 'png + ;; libpngXY.dll is the default name when building + ;; with CMake or from a lpngXYY tarball on w32, + ;; libpngXY-XY.dll is the DLL name when building + ;; with libtool / autotools + (format "libpng%d%d.dll" major minor) + (format "libpng%d%d-%d%d.dll" major minor major minor))) + '(png "libpng12d.dll" "libpng12.dll" "libpng3.dll" "libpng.dll" + ;; these are libpng 1.2.8 from GTK+ + "libpng13d.dll" "libpng13.dll")) + '(tiff "libtiff-5.dll" "libtiff3.dll" "libtiff.dll") + (if (> libjpeg-version 62) + ;; Versions of libjpeg after 6b are incompatible with + ;; earlier versions, and each of versions 7, 8, and 9 is + ;; also incompatible with the preceding ones (the core data + ;; structures used for communications with the library + ;; gained additional members with each new version). So we + ;; must use only the version of the library which Emacs was + ;; compiled against. + (list 'jpeg (format "libjpeg-%d.dll" (/ libjpeg-version 10))) + '(jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")) + ;; Versions of giflib 5.0.0 and later changed signatures of + ;; several functions used by Emacs, which makes those versions + ;; incompatible with previous ones. We select the correct + ;; libraries according to the version of giflib we were + ;; compiled against. (If we were compiled without GIF support, + ;; libgif-version's value is -1.) + (if (>= libgif-version 50100) + ;; Yes, giflib 5.0 uses 6 as the major version of the API, + ;; and giflib 5.1 uses 7, thus "libgif-7.dll" and + ;; "libgif-6.dll" below (giflib 4.x used 5 as the major API + ;; version). giflib5.dll is from the lua-files project, + ;; and gif.dll is from luapower. + '(gif "libgif-7.dll") + (if (>= libgif-version 50000) + '(gif "libgif-6.dll" "giflib5.dll" "gif.dll") + '(gif "libgif-5.dll" "giflib4.dll" "libungif4.dll" "libungif.dll"))) + '(svg "librsvg-2-2.dll") + '(webp "libwebp-7.dll" "libwebp.dll") + '(webpdemux "libwebpdemux-2.dll" "libwebpdemux.dll") + '(sqlite3 "libsqlite3-0.dll") + '(gdk-pixbuf "libgdk_pixbuf-2.0-0.dll") + '(glib "libglib-2.0-0.dll") + '(gio "libgio-2.0-0.dll") + '(gobject "libgobject-2.0-0.dll") + (if (>= libgnutls-version 30400) + '(gnutls "libgnutls-30.dll") + '(gnutls "libgnutls-28.dll" "libgnutls-26.dll")) + '(libxml2 "libxml2-2.dll" "libxml2.dll") + '(zlib "zlib1.dll" "libz-1.dll") + '(lcms2 "liblcms2-2.dll") + '(gccjit "libgccjit-0.dll") + ;; MSYS2 distributes libtree-sitter.dll, without API version + ;; number, upto and including version 0.24.3-2; later versions + ;; come with libtree-sitter-major.minor.dll (as in + ;; libtree-sitter-0.24.dll). Sadly, the header files don't have + ;; any symbols for library version, so we can only use the + ;; library-language ABI version; according to + ;; https://github.com/tree-sitter/tree-sitter/issues/3925, the + ;; language ABI must change when the library's ABI is modified. + (if (<= tree-sitter--library-abi 14) + '(tree-sitter "libtree-sitter-0.24.dll" + "libtree-sitter.dll" + "libtree-sitter-0.dll") + '(tree-sitter "libtree-sitter-0.25.dll")))) + + +;;;; Selections + +(declare-function w32--set-selection "w32-win.el") + +(declare-function w32--get-selection "w32-win.el") + +(declare-function w32--selection-owner-p "w32-win.el") + +(declare-function w32-selection-exists-p "w32select.c" + (&optional selection terminal)) + +;; Make copy&pasting in w32's console interact with the system's clipboard! +(cl-defmethod gui-backend-set-selection (type value + &context (window-system nil)) + (w32--set-selection type value)) + +(cl-defmethod gui-backend-get-selection (type data-type + &context (window-system nil)) + (w32--get-selection type data-type)) + +(cl-defmethod gui-backend-selection-owner-p (selection + &context (window-system nil)) + (w32--selection-owner-p selection)) + +(cl-defmethod gui-selection-exists-p (selection + &context (window-system nil)) + (w32-selection-exists-p selection)) + +(provide 'term/w32-nt) + +;;; w32-nt.el ends here diff --git a/lisp/term/w32-win.el b/lisp/term/w32-win.el index af53345a377..fa7862d9bff 100644 --- a/lisp/term/w32-win.el +++ b/lisp/term/w32-win.el @@ -240,94 +240,6 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.") "Report an error when a suspend is attempted." (error "Suspending an Emacs running under W32 makes no sense")) -(defvar dynamic-library-alist) -(defvar libpng-version) ; image.c #ifdef HAVE_NTGUI -(defvar libgif-version) -(defvar libjpeg-version) - -(defvar libgnutls-version) ; gnutls.c - -(defvar tree-sitter--library-abi) ; treesit.c - -;;; Set default known names for external libraries -(setq dynamic-library-alist - (list - '(gdiplus "gdiplus.dll") - '(shlwapi "shlwapi.dll") - '(xpm "libxpm.dll" "xpm4.dll" "libXpm-nox4.dll") - ;; Versions of libpng 1.4.x and later are incompatible with - ;; earlier versions. Set up the list of libraries according to - ;; the version we were compiled against. (If we were compiled - ;; without PNG support, libpng-version's value is -1.) - (if (>= libpng-version 10400) - (let ((major (/ libpng-version 10000)) - (minor (mod (/ libpng-version 100) 10))) - (list 'png - ;; libpngXY.dll is the default name when building - ;; with CMake or from a lpngXYY tarball on w32, - ;; libpngXY-XY.dll is the DLL name when building - ;; with libtool / autotools - (format "libpng%d%d.dll" major minor) - (format "libpng%d%d-%d%d.dll" major minor major minor))) - '(png "libpng12d.dll" "libpng12.dll" "libpng3.dll" "libpng.dll" - ;; these are libpng 1.2.8 from GTK+ - "libpng13d.dll" "libpng13.dll")) - '(tiff "libtiff-5.dll" "libtiff3.dll" "libtiff.dll") - (if (> libjpeg-version 62) - ;; Versions of libjpeg after 6b are incompatible with - ;; earlier versions, and each of versions 7, 8, and 9 is - ;; also incompatible with the preceding ones (the core data - ;; structures used for communications with the library - ;; gained additional members with each new version). So we - ;; must use only the version of the library which Emacs was - ;; compiled against. - (list 'jpeg (format "libjpeg-%d.dll" (/ libjpeg-version 10))) - '(jpeg "jpeg62.dll" "libjpeg.dll" "jpeg-62.dll" "jpeg.dll")) - ;; Versions of giflib 5.0.0 and later changed signatures of - ;; several functions used by Emacs, which makes those versions - ;; incompatible with previous ones. We select the correct - ;; libraries according to the version of giflib we were - ;; compiled against. (If we were compiled without GIF support, - ;; libgif-version's value is -1.) - (if (>= libgif-version 50100) - ;; Yes, giflib 5.0 uses 6 as the major version of the API, - ;; and giflib 5.1 uses 7, thus "libgif-7.dll" and - ;; "libgif-6.dll" below (giflib 4.x used 5 as the major API - ;; version). giflib5.dll is from the lua-files project, - ;; and gif.dll is from luapower. - '(gif "libgif-7.dll") - (if (>= libgif-version 50000) - '(gif "libgif-6.dll" "giflib5.dll" "gif.dll") - '(gif "libgif-5.dll" "giflib4.dll" "libungif4.dll" "libungif.dll"))) - '(svg "librsvg-2-2.dll") - '(webp "libwebp-7.dll" "libwebp.dll") - '(webpdemux "libwebpdemux-2.dll" "libwebpdemux.dll") - '(sqlite3 "libsqlite3-0.dll") - '(gdk-pixbuf "libgdk_pixbuf-2.0-0.dll") - '(glib "libglib-2.0-0.dll") - '(gio "libgio-2.0-0.dll") - '(gobject "libgobject-2.0-0.dll") - (if (>= libgnutls-version 30400) - '(gnutls "libgnutls-30.dll") - '(gnutls "libgnutls-28.dll" "libgnutls-26.dll")) - '(libxml2 "libxml2-2.dll" "libxml2.dll") - '(zlib "zlib1.dll" "libz-1.dll") - '(lcms2 "liblcms2-2.dll") - '(gccjit "libgccjit-0.dll") - ;; MSYS2 distributes libtree-sitter.dll, without API version - ;; number, upto and including version 0.24.3-2; later versions - ;; come with libtree-sitter-major.minor.dll (as in - ;; libtree-sitter-0.24.dll). Sadly, the header files don't have - ;; any symbols for library version, so we can only use the - ;; library-language ABI version; according to - ;; https://github.com/tree-sitter/tree-sitter/issues/3925, the - ;; language ABI must change when the library's ABI is modified. - (if (<= tree-sitter--library-abi 14) - '(tree-sitter "libtree-sitter-0.24.dll" - "libtree-sitter.dll" - "libtree-sitter-0.dll") - '(tree-sitter "libtree-sitter-0.25.dll")))) - ;;; multi-tty support (defvar w32-initialized nil "Non-nil if the w32 window system has been initialized.") @@ -554,26 +466,6 @@ also be textual." &context (window-system w32)) (w32-selection-exists-p selection)) -(when (eq system-type 'windows-nt) - ;; Make copy&pasting in w32's console interact with the system's clipboard! - ;; We could move those cl-defmethods outside of the `when' and use - ;; "&context (system-type (eql windows-nt))" instead! - (cl-defmethod gui-backend-set-selection (type value - &context (window-system nil)) - (w32--set-selection type value)) - - (cl-defmethod gui-backend-get-selection (type data-type - &context (window-system nil)) - (w32--get-selection type data-type)) - - (cl-defmethod gui-backend-selection-owner-p (selection - &context (window-system nil)) - (w32--selection-owner-p selection)) - - (cl-defmethod gui-selection-exists-p (selection - &context (window-system nil)) - (w32-selection-exists-p selection))) - ;; The "Windows" keys on newer keyboards bring up the Start menu ;; whether you want it or not - make Emacs ignore these keystrokes ;; rather than beep. diff --git a/src/image.c b/src/image.c index b051e4ca796..65d8db24adc 100644 --- a/src/image.c +++ b/src/image.c @@ -13003,7 +13003,7 @@ non-numeric, there is no explicit limit on the size of images. */); DEFSYM (Qgs_load_image, "gs-load-image"); #endif /* HAVE_GHOSTSCRIPT */ -#ifdef HAVE_NTGUI +#ifdef WINDOWSNT /* Versions of libpng, libgif, and libjpeg that we were compiled with, or -1 if no PNG/GIF support was compiled in. This is tested by w32-win.el to correctly set up the alist used to search for the diff --git a/src/treesit.c b/src/treesit.c index 585be9efe29..9622addd09b 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -4683,7 +4683,7 @@ applies to LANGUAGE-A will be redirected to LANGUAGE-B instead. */); defsubr (&Streesit_subtree_stat); #endif /* HAVE_TREE_SITTER */ defsubr (&Streesit_available_p); -#ifdef HAVE_NTGUI +#ifdef WINDOWSNT DEFSYM (Qtree_sitter__library_abi, "tree-sitter--library-abi"); Fset (Qtree_sitter__library_abi, #if HAVE_TREE_SITTER -- 2.39.5