Linux 内核 makefile cscope 目标

Posted

技术标签:

【中文标题】Linux 内核 makefile cscope 目标【英文标题】:Linux kernel makefile cscope target 【发布时间】:2014-04-08 13:16:49 【问题描述】:

当我通过发出 make cscope 生成 Linux 内核 cscope 数据库时,我会得到数据库文件以及具有 relative 路径的文件列表。这对我来说是个问题,因为后来当我从除内核之外的任何目录在 vim 编辑器中附加该外部内核的数据库时,我可以轻松搜索特定符号 BUT 我无法打开包含该符号的文件.

我已经编写了下一个 bash 脚本

#!/bin/bash

SNAME="$0"
SNAME=$SNAME##*/

function usage()

    echo Generate Linux kernel cscope database
    echo "Usage: $SNAME [PATH]"
    echo -n "You must provide this script with an ABSOLUTE path of your "
    echo "kernel's root directory"


if [[ -z "$1" ]]; then
    usage
    exit -1
fi

KDIR="$1"

echo -n "Collecting a list of files... "
if find "$KDIR" -path "$KDIR/arch/*" ! -path "$KDIR/arch/x86*" -prune -o \
        -path "$KDIR/include/asm-*" \
        ! -path "$KDIR/include/asm-generic*" \
        ! -path "$KDIR/include/asm-x86*" -prune -o \
        -path "$KDIR/tmp*" -prune -o \
        -path "$KDIR/Documentation*" -prune -o \
        -path "$KDIR/scripts*" -prune -o \
        -name "*.[chxsS]" -print > cscope.files; then
    echo done
else
    echo failed
fi

echo -n "Building cscope database... "
cscope -k -qb && echo done || echo failed

使用 absolute 路径收集我需要的所有文件(x86/x86_64 架构),然后我成功地手动构建了 cscope 数据库。但我认为它必须是一些更简单的方法来实现这一点。也许我还没有找到一些 Makefile 的目标,例如 make cscope_absmake cscope_ext

有什么建议吗?

【问题讨论】:

+1 不知道它有一个 make cscope 选项。 我想到的一件事是:查看 Makefile 如何调用 cscope,如果存在变量,则可以在命令行中为 cscope 指定一些选项。 【参考方案1】:

首先,创建一个特定于特定架构的 cscope 数据库更简单,如下所示:在 Linux 内核的顶层文件夹中,运行

ARCH=x86 make cscope

这将创建一个具有 相对 路径的 cscope。 现在您可以要求 vim 以两种方式之一解释相对于 cscope.out 文件位置的路径:

方式 1: 使用cscoperelative:help csre 的输出:

If 'cscoperelative' is set, then in absence of a prefix given to cscope
(prefix is the argument of -P option of cscope), basename of cscope.out
location (usually the project root directory) will be used as the prefix
to construct an absolute path.  The default is off.  Note: This option is
only effective when cscope (cscopeprg) is initialized without a prefix
path (-P).  Examples: >
    :set csre
    :set nocsre

方式 2:(来自 Aaron Hs 在this 问题中的回答)在 vim 中添加 cscope 数据库时,指定基本位置。示例:

:cs add <base_location>/cscope.out <base_location>/

来自 vim 的 cscope 帮助页面添加:

USAGE   :cs add file|dir [pre-path] [flags]

    [pre-path] is the pathname used with the -P command to cscope.

【讨论】:

【参考方案2】:
make cscope

或针对您的具体情况 -

ARCH=x86 make cscope

【讨论】:

【参考方案3】:

来自 cscope 手册页here:

-P 路径 在预先构建的交叉引用文件中添加相对文件名的路径,这样您就不必更改到 建立了交叉引用文件。此选项仅对 -d 有效 选项。

所以我想***内核目录中的以下命令应该可以解决问题(抱歉没有方便的 linux 机器):

cscope -d -P `pwd`

我的 2 美分,

【讨论】:

【参考方案4】:

您可以在内核树的根目录中使用以下命令来生成绝对路径:

#> make O=. cscope

【讨论】:

以上是关于Linux 内核 makefile cscope 目标的主要内容,如果未能解决你的问题,请参考以下文章

kernel生成针对x86架构的tags和cscope数据库

如何确定某个函数在Linux内核代码中的位置

linux内核模块编译makefile

linux内核makefile概览

Linux 2.6内核Makefile浅析

linux-2.6.22.6内核启动分析之Makefile文件