2
0

ctags.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/sh
  2. #
  3. # Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
  4. #
  5. # Licensed under the Apache License 2.0 (the "License"). You may not use
  6. # this file except in compliance with the License. You can obtain a copy
  7. # in the file LICENSE in the source distribution or at
  8. # https://www.openssl.org/source/license.html
  9. #
  10. # Usage: ./util/ctags.sh [...arguments for ctags...]
  11. #
  12. # This script runs ctags twice. In the first pass, ctags extract macro
  13. # definitions. readtags that is part of Universal Ctags converts them
  14. # to ctags options. In the second pass, ctags reads the options and
  15. # extracts language objects with expanding the macros.
  16. #
  17. # Universal Ctags 6.0.0 or higher is assumed.
  18. #
  19. : ${CTAGS=ctags}
  20. : ${READTAGS=readtags}
  21. if ! type "${CTAGS}" > /dev/null; then
  22. echo "${CTAGS}: not found" 1>&2
  23. exit 1
  24. fi
  25. if [ $# -eq 0 ]; then
  26. set - -R
  27. fi
  28. if ! "${CTAGS}" --version | grep -q "Universal Ctags"; then
  29. "${CTAGS}" "$@"
  30. exit $?
  31. fi
  32. if "${CTAGS}" --version | grep -q "Universal Ctags 5.*"; then
  33. "${CTAGS}" "$@"
  34. exit $?
  35. fi
  36. if ! type "${READTAGS}" > /dev/null 2>&1; then
  37. echo "WARNING: ${READTAGS}: not found" 1>&2
  38. echo "WARNING: \"tagging after macro expanding\" doesn't work" 1>&2
  39. "${CTAGS}" "$@"
  40. exit $?
  41. fi
  42. if ! [ -d ./.ctags.d ]; then
  43. echo "No ./.ctags.d directory" 1>&2
  44. exit 1
  45. fi
  46. {
  47. # At the first pass, ctags should not be affected by personal
  48. # configuration files. So --options=NONE is passed.
  49. #
  50. # However, if the option is passed, ctags doesn't load the project
  51. # default configuration files under $project/.ctags.d. So we load
  52. # the project default configuration files, add-dir.ctags and
  53. # exclude.ctags, explicitly.
  54. #
  55. # openssl-stage1 contains a configuration file specialized to
  56. # extract macro definitions. It should not be used in normal ctags
  57. # usage.
  58. $CTAGS --quiet --options=NONE \
  59. --options=./.ctags.d/add-dir.ctags \
  60. --options=./.ctags.d/exclude.ctags \
  61. --options=openssl-stage1
  62. } | {
  63. macros=.ctags.d/openssl-stage2/50macro-definitons.ctags
  64. cat > "$macros" <<EOF
  65. #
  66. # This file is automatically generated by $0.
  67. # DON'T EDIT THIS FILE MANUALLY
  68. #
  69. EOF
  70. # Extract macro definitions and convert them to ctags options.
  71. $READTAGS --tag-file - \
  72. -Q '(and (eq? $kind "d") ($ "macrodef"))' \
  73. -F '(list "-D" $name $signature "=" ($ "macrodef") #t)' \
  74. -l >> "$macros" &&
  75. # At the second path, ctags extract tags with expanding macros stored in
  76. # 50macro-definitons.ctags.
  77. $CTAGS --options=openssl-stage2 \
  78. "$@"
  79. }