[gdb/testsuite] Fix license text in gdb.reverse/map-to-same-line.{c,exp}
[binutils-gdb.git] / gdbsupport / check-defines.el
blobb7cf61ba8599ba37b413dfd05d030457c625797e
1 ;; Verify that preprocessor symbols are defined in config.in.
3 ;; Copyright (C) 2020-2024 Free Software Foundation, Inc.
4 ;;
5 ;; This file is part of GDB.
6 ;;
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ;; To use:
21 ;; cd gdbsupport
22 ;; emacs --script check-defines.el
24 (require 'cl-lib)
26 (setq-default case-fold-search nil)
28 ;; The currently recognized macros.
29 (defconst check-regexp "\\_<\\(\\(HAVE\\|PTRACE_TYPE\\|SIZEOF\\)_[a-zA-Z0-9_]+\\)\\_>")
31 (defvar check-seen 0)
33 ;; Whitelist. These are things that have names like autoconf-created
34 ;; macros, but that are managed directly in the code.
35 (put (intern "HAVE_USEFUL_SBRK") :check-ok t)
36 (put (intern "HAVE_SOCKETS") :check-ok t)
37 (put (intern "HAVE_F_GETFD") :check-ok t)
38 (put (intern "HAVE_DOS_BASED_FILE_SYSTEM") :check-ok t)
40 (defun check-read-config.in (file)
41 (save-excursion
42 (find-file-read-only file)
43 (goto-char (point-min))
44 (while (re-search-forward "^#undef \\(.+\\)$" nil t)
45 (let ((name (match-string 1)))
46 (put (intern name) :check-ok t)))))
48 (defun check-one-file (file)
49 (save-excursion
50 (find-file-read-only file)
51 (goto-char (point-min))
52 (while (re-search-forward check-regexp nil t)
53 (let ((name (match-string 1)))
54 (unless (get (intern name) :check-ok)
55 (save-excursion
56 (goto-char (match-beginning 0))
57 (cl-incf check-seen)
58 (message "%s:%d:%d: error: name %s not defined"
59 file
60 (line-number-at-pos)
61 (current-column)
62 name)))))))
64 (defun check-directory (dir)
65 (dolist (file (directory-files dir t "\\.[ch]$"))
66 (check-one-file file)))
68 (check-read-config.in "config.in")
69 (check-read-config.in "../gnulib/config.in")
70 (check-directory ".")
71 (check-directory "../gdb/nat")
72 (check-directory "../gdb/target")
74 (when (> check-seen 0)
75 (message "%d errors seen" check-seen))