18dffb485Schristos;; Verify that preprocessor symbols are defined in config.in. 28dffb485Schristos 3*5ba1f45fSchristos;; Copyright (C) 2020-2024 Free Software Foundation, Inc. 48dffb485Schristos;; 58dffb485Schristos;; This file is part of GDB. 68dffb485Schristos;; 78dffb485Schristos;; This program is free software; you can redistribute it and/or modify 88dffb485Schristos;; it under the terms of the GNU General Public License as published by 98dffb485Schristos;; the Free Software Foundation; either version 3 of the License, or 108dffb485Schristos;; (at your option) any later version. 118dffb485Schristos;; 128dffb485Schristos;; This program is distributed in the hope that it will be useful, 138dffb485Schristos;; but WITHOUT ANY WARRANTY; without even the implied warranty of 148dffb485Schristos;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 158dffb485Schristos;; GNU General Public License for more details. 168dffb485Schristos;; 178dffb485Schristos;; You should have received a copy of the GNU General Public License 188dffb485Schristos;; along with this program. If not, see <http://www.gnu.org/licenses/>. 198dffb485Schristos 208dffb485Schristos;; To use: 218dffb485Schristos;; cd gdbsupport 228dffb485Schristos;; emacs --script check-defines.el 238dffb485Schristos 248dffb485Schristos(require 'cl-lib) 258dffb485Schristos 268dffb485Schristos(setq-default case-fold-search nil) 278dffb485Schristos 288dffb485Schristos;; The currently recognized macros. 298dffb485Schristos(defconst check-regexp "\\_<\\(\\(HAVE\\|PTRACE_TYPE\\|SIZEOF\\)_[a-zA-Z0-9_]+\\)\\_>") 308dffb485Schristos 318dffb485Schristos(defvar check-seen 0) 328dffb485Schristos 338dffb485Schristos;; Whitelist. These are things that have names like autoconf-created 348dffb485Schristos;; macros, but that are managed directly in the code. 358dffb485Schristos(put (intern "HAVE_USEFUL_SBRK") :check-ok t) 368dffb485Schristos(put (intern "HAVE_SOCKETS") :check-ok t) 378dffb485Schristos(put (intern "HAVE_F_GETFD") :check-ok t) 388dffb485Schristos(put (intern "HAVE_DOS_BASED_FILE_SYSTEM") :check-ok t) 398dffb485Schristos 408dffb485Schristos(defun check-read-config.in (file) 418dffb485Schristos (save-excursion 428dffb485Schristos (find-file-read-only file) 438dffb485Schristos (goto-char (point-min)) 448dffb485Schristos (while (re-search-forward "^#undef \\(.+\\)$" nil t) 458dffb485Schristos (let ((name (match-string 1))) 468dffb485Schristos (put (intern name) :check-ok t))))) 478dffb485Schristos 488dffb485Schristos(defun check-one-file (file) 498dffb485Schristos (save-excursion 508dffb485Schristos (find-file-read-only file) 518dffb485Schristos (goto-char (point-min)) 528dffb485Schristos (while (re-search-forward check-regexp nil t) 538dffb485Schristos (let ((name (match-string 1))) 548dffb485Schristos (unless (get (intern name) :check-ok) 558dffb485Schristos (save-excursion 568dffb485Schristos (goto-char (match-beginning 0)) 578dffb485Schristos (cl-incf check-seen) 588dffb485Schristos (message "%s:%d:%d: error: name %s not defined" 598dffb485Schristos file 608dffb485Schristos (line-number-at-pos) 618dffb485Schristos (current-column) 628dffb485Schristos name))))))) 638dffb485Schristos 648dffb485Schristos(defun check-directory (dir) 658dffb485Schristos (dolist (file (directory-files dir t "\\.[ch]$")) 668dffb485Schristos (check-one-file file))) 678dffb485Schristos 688dffb485Schristos(check-read-config.in "config.in") 698dffb485Schristos(check-read-config.in "../gnulib/config.in") 708dffb485Schristos(check-directory ".") 718dffb485Schristos(check-directory "../gdb/nat") 728dffb485Schristos(check-directory "../gdb/target") 738dffb485Schristos 748dffb485Schristos(when (> check-seen 0) 758dffb485Schristos (message "%d errors seen" check-seen)) 76