check-defines.el 2.5 KB

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