make-init-c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/sh
  2. # Copyright (C) 2013-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. # Generate the init.c source file.
  19. #
  20. # Usage:
  21. #
  22. # ./make-init-c source-files > init.c-tmp
  23. #
  24. # Where SOURCE-FILES is the list of source files to extract init functions from.
  25. #
  26. # Formatting conventions: The name of the initialization routines must begin
  27. # with `_initialize_`, must start in column zero, and be followed with exactly
  28. # ` ()`. For example:
  29. #
  30. # void
  31. # _initialize_foo ()
  32. # {
  33. # ...
  34. # }
  35. #
  36. # Abort on command error.
  37. set -e
  38. echo "/* Do not modify this file. */"
  39. echo "/* It is created automatically by the Makefile. */"
  40. echo "#include \"defs.h\" /* For initialize_file_ftype. */"
  41. echo "#include <algorithm>"
  42. echo ""
  43. sed -n -e 's/^\(_initialize_[a-zA-Z0-9_]*\) ()$/\1/p' "$@" | while read -r name; do
  44. echo "extern initialize_file_ftype $name;"
  45. done
  46. echo ""
  47. echo "void initialize_all_files ();"
  48. echo "void"
  49. echo "initialize_all_files ()"
  50. echo "{"
  51. echo " std::vector<initialize_file_ftype *> functions ="
  52. echo " {"
  53. sed -n -e 's/^\(_initialize_[a-zA-Z0-9_]*\) ()$/\1/p' "$@" | while read -r name; do
  54. echo " $name,"
  55. done
  56. echo " };"
  57. echo ""
  58. echo " /* If GDB_REVERSE_INIT_FUNCTIONS is set (any value), reverse the"
  59. echo " order in which initialization functions are called. This is"
  60. echo " used by the testsuite. */"
  61. echo " if (getenv (\"GDB_REVERSE_INIT_FUNCTIONS\") != nullptr)"
  62. echo " std::reverse (functions.begin (), functions.end ());"
  63. echo ""
  64. echo " for (initialize_file_ftype *function : functions)"
  65. echo " function ();"
  66. echo "}"