Fix make_etags failure on Mac.
authorTatsuo Ishii <ishii@postgresql.org>
Wed, 15 Feb 2023 00:52:42 +0000 (09:52 +0900)
committerTatsuo Ishii <ishii@postgresql.org>
Wed, 15 Feb 2023 00:52:42 +0000 (09:52 +0900)
Previously make_etags always ran make_ctags -e when make_etags was
executed.  However, because non-Exuberant ctags on Mac does not
support -e option (and also on other platforms including old Linux),
ctags failed. To avoid the failure change make_ctags so that if
non-Exuberant ctags is used and ctags -e option is requested, run
etags command instead. If etags command does not exist, make_ctags
will fail.

Also refactor make_ctags and tweak make_etags to emit proper usage
message.

Author: Fujii Masao
Reviewed-by: Tatsuo Ishii
Discussion: https://www.postgresql.org/message-id/369c13b9-8b0f-d6f9-58fc-61258ec8f713%40oss.nttdata.com

src/tools/make_ctags
src/tools/make_etags

index 102881667b610592c04044ad2b1c5b2d4813bcbe..aa7d7b573f09fd54f183f989fd0446025f333034 100755 (executable)
@@ -9,15 +9,19 @@ then  echo $usage
        exit 1
 fi
 
-MODE=
+EMACS_MODE=
 NO_SYMLINK=
+IS_EXUBERANT=
+PROG="ctags"
+TAGS_OPT="-a -f"
 TAGS_FILE="tags"
+FLAGS=
+IGNORE_IDENTIFIES=
 
 while [ $# -gt 0 ]
 do
        if [ $1 = "-e" ]
-       then    MODE="-e"
-               TAGS_FILE="TAGS"
+       then    EMACS_MODE="Y"
        elif [ $1 = "-n" ]
        then    NO_SYMLINK="Y"
        else
@@ -27,15 +31,24 @@ do
        shift
 done
 
-command -v ctags >/dev/null || \
+if [ ! "$EMACS_MODE" ]
+then   (command -v ctags >/dev/null) || \
        { echo "'ctags' program not found" 1>&2; exit 1; }
+fi
 
-trap "ret=$?; rm -rf /tmp/$$; exit $ret" 0 1 2 3 15
-rm -f ./$TAGS_FILE
-
-IS_EXUBERANT=""
 ctags --version 2>&1 | grep Exuberant && IS_EXUBERANT="Y"
 
+if [ "$EMACS_MODE" ]
+then   TAGS_FILE="TAGS"
+       if [ "$IS_EXUBERANT" ]
+       then PROG="ctags -e"
+       else    (command -v etags >/dev/null) || \
+               { echo "neither 'etags' nor exuberant 'ctags' program not found" 1>&2; exit 1; }
+               PROG="etags"
+               TAGS_OPT="-a -o"
+       fi
+fi
+
 # List of kinds supported by Exuberant Ctags 5.8
 # generated by ctags --list-kinds
 # --c-kinds was called --c-types before 2003
@@ -56,20 +69,23 @@ ctags --version 2>&1 | grep Exuberant && IS_EXUBERANT="Y"
 
 if [ "$IS_EXUBERANT" ]
 then   FLAGS="--c-kinds=+dfmstuv"
-else   FLAGS="-dt"
+elif [ ! "$EMACS_MODE" ]
+then   FLAGS="-dt"
 fi
 
 # Use -I option to ignore a macro
 if [ "$IS_EXUBERANT" ]
 then   IGNORE_IDENTIFIES="-I pg_node_attr+"
-else   IGNORE_IDENTIFIES=
 fi
 
+trap "ret=$?; rm -rf /tmp/$$; exit $ret" 0 1 2 3 15
+rm -f ./$TAGS_FILE
+
 # this is outputting the tags into the file 'tags', and appending
 find `pwd`/ \( -name tmp_install -prune -o -name tmp_check -prune \) \
        -o \( -name "*.[chly]" -o -iname "*makefile*" -o -name "*.mk" -o -name "*.in" \
        -o -name "*.sql" -o -name "*.p[lm]" \) -type f -print |
-       xargs ctags $MODE -a -f $TAGS_FILE "$FLAGS" "$IGNORE_IDENTIFIES"
+       xargs $PROG $TAGS_OPT $TAGS_FILE $FLAGS $IGNORE_IDENTIFIES
 
 # Exuberant tags has a header that we cannot sort in with the other entries
 # so we skip the sort step
index afc57e3e892682d016b0ea04887f8fe7e616ff94..7e51bb4c4e2e7e32c6ed4812065df9602da305c3 100755 (executable)
@@ -1,5 +1,11 @@
 #!/bin/sh
-# src/tools/make_etags
+
+# src/tools/make_etags [-n]
+
+if [ $# -gt 1 ] || ( [ $# -eq 1 ] && [ $1 != "-n" ] )
+then   echo "Usage: $0 [-n]"
+       exit 1
+fi
 
 cdir=`dirname $0`
 dir=`(cd $cdir && pwd)`