Linux kernel makefile cscope target
Asked Answered
L

4

6

When I generate Linux kernel cscope database by issuing make cscope I get database file along with a list of files with relative path. This is a problem for me because later on when I attach that external kernel's database in vim editor from whatever directory but kernel's I can easily search for specific symbol BUT I can't open file that symbol is contained in.

I've written the next bash script

#!/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

that collects all files I need (x86/x86_64 architecture) using absolute path and then I successfully build cscope database manually. But I think it must be some easier way to accomplish this. Maybe some Makefile's target like make cscope_abs or make cscope_ext that I have not found yet.

Any suggestions?

Lorenzalorenzana answered 8/4, 2014 at 13:16 Comment(2)
+1 did not know it has a make cscope option.Simonsen
One thing that comes to my mind is : look into the Makefile how cscope is called, if there exists a variable you then can specify some options to cscope in command line.Coldiron
C
2

From the cscope manpage here:

-P path Prepend path to relative file names in a pre-built cross-reference file so you do not have to change to the directory where the cross-reference file was built. This option is only valid with the -d option.

So I guess the following command from the top-level kernel directory should do the trick (sorry no linux machine handy):

cscope -d -P `pwd`

my 2 cents,

Crescentic answered 17/5, 2014 at 8:55 Comment(0)
A
5

First, it is simpler to create a cscope database specific to a particular architecture as follows : In Linux kernel's top folder, run

ARCH=x86 make cscope

This creates a cscope with relative paths. Now you can ask vim to interpret the paths relative to the location of the cscope.out file in one of two ways:

Way 1 : Use cscoperelative. Output of :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

Way 2 : (From Aaron Hs' answer in this question) When adding the cscope database in vim, specify base location. Example:

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

From vim's help page for cscope add:

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

    [pre-path] is the pathname used with the -P command to cscope.
Audet answered 13/4, 2015 at 11:42 Comment(0)
D
3
make cscope

or for your specific case -

ARCH=x86 make cscope
Dasteel answered 5/11, 2014 at 18:13 Comment(0)
C
2

From the cscope manpage here:

-P path Prepend path to relative file names in a pre-built cross-reference file so you do not have to change to the directory where the cross-reference file was built. This option is only valid with the -d option.

So I guess the following command from the top-level kernel directory should do the trick (sorry no linux machine handy):

cscope -d -P `pwd`

my 2 cents,

Crescentic answered 17/5, 2014 at 8:55 Comment(0)
D
0

You could use the following command in the root of the kernel tree to generate absolute paths:

#> make O=. cscope
Duty answered 2/6, 2017 at 16:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.