$ wget http://tamacom.com/global/global-6.5.2.tar.gz $ tar zxvf global-6.5.2.tar.gz $ cd global-6.5.2 $ sh reconf.sh $ ./configure --prefix=<PREFIX> --with-exuberant-ctags=/usr/bin/ctags $ make $ sudo make install
一开始我在运行sh reconf.sh期间我遇到了错误:
`COPYING.LIB' not found in `/usr/share/libtool/libltdl'
$ cd DIR1 $ global -xl func[1-3] func1 1 fileB.c func1(){...}
高级使用
针对指定的文件生成tag
你可以指定特定的需要生产tag的文件:
1 2 3
$ find . -type f -print >/tmp/list # make a file set $ vi /tmp/list # customize the file set $ gtags -f /tmp/list
把tag文件生成在外部目录中
如果你的代码在不可写介质上(比如光盘),你可以在外部目录建立TAGS文件。
1 2 3 4 5 6
$ mkdir /var/dbpath $ cd /cdrom/src # the root of source tree $ gtags /var/dbpath # make tag files in /var/dbpath $ export GTAGSROOT=`pwd` $ export GTAGSDBPATH=/var/dbpath $ global func
$ cd /cdrom/src # the root of source tree $ mkdir -p /usr/obj/cdrom/src $ gtags /usr/obj/cdrom/src # make tag files in /usr/obj/cdrom/src $ global func
$ pwd /develop/src/mh # this is a source project $ gtags $ ls G*TAGS GRTAGS GTAGS $ global mhl uip/mhlsbr.c # mhl() is found $ global strlen # strlen() is not found $ (cd /usr/src/lib; gtags) # library source $ (cd /usr/src/sys; gtags) # kernel source $ export GTAGSLIBPATH=/usr/src/lib:/usr/src/sys $ global strlen ../../../usr/src/lib/libc/string/strlen.c # found in library $ global access ../../../usr/src/sys/kern/vfs_syscalls.c # found in kernel
还有一种更直接的方法,直接把相关的代码软链接过来,global会把他们认为是当前工程的:
1 2 3 4 5 6 7
$ ln -s /usr/src/lib . $ ln -s /usr/src/sys . $ gtags $ global strlen lib/libc/string/strlen.c $ global access sys/kern/vfs_syscalls.c
标示符补全
如果你忘记了标示符的全名,可以使用-c来补全标示符的名字
1 2 3 4 5 6 7 8 9 10 11
$ global -c kmem # maybe k..k.. kmem.. kmem_alloc kmem_alloc_pageable kmem_alloc_wait kmem_free kmem_free_wakeup kmem_init kmem_malloc kmem_suballoc # This is what I need! $ global kmem_suballoc ../vm/vm_kern.c
其他的一些高级技巧,比如bash中自动补全,可以参考global官方文档。
高级话题
配置global
1 2 3 4 5
# cp gtags.conf /etc/gtags.conf # system wide config file. # vi /etc/gtags.conf
$ cp gtags.conf $HOME/.globalrc # personal config file. $ vi $HOME/.globalrc
如何使用ctags作为global的后备
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Installation of GLOBAL # It assumed that ctags command is installed in '/usr/local/bin'.
$ ./configure --with-exuberant-ctags=/usr/local/bin/ctags $ make $ sudo make install
# Executing of gtags # It assumed that GLOBAL is installed in '/usr/local'.