曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 7492|回复: 0
打印 上一主题 下一主题

安装 LXR cross referencer 过程记录(查看内核源码)

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2009-10-21 19:36:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
LXR 真是难安装,搞了大半天才将其装上,而且还是有点糊里糊涂的,甚至一度想放弃不装了,下面记录一下过程。

安装的 LXR版本: 0.96
(截至发帖时为最新版)

安装当前版本 LXR 需要确保以下软件都已安装:

1) ctags
http://sf.net/projects/ctags 可以获得。

2) MySQL (4.x/5.x)
http://www.mysql.com  可以获得。

3)Apache ( Apache-1 或 Apache-2)
http://httpd.apache.org/ 可以获得。

4) Glimpse 或 swish-e
可以在 http://glimpse.cs.arizona.deu 可以获得 glimpse
可以在 http://swish-e.org/download/index.html 可以获得 swish-e

5) Perl 数据库驱动接口 DBI 以及相关DBD 驱动

6) Perl 文件 : MMagic 模块、mod_perl 模块
我的是 Mandriva 2009.1 ,在“安装/删除“软件里似乎找不到这个模块,只好上网找,在:
http://fr2.rpmfind.net/linux/RPM ... v2009.0.noarch.html
这里可以下载得到。

7) 如果需要 CVS 支持,还需要安装 rcs


至于安装上面这些软件,现在发行版的 Linux 里都有类似的傻瓜安装软件管理器,不需要手动编译,添加参数。

把下载的 lxr 文件包,解压缩到 /usr/local  下,默认解压缩后的文件夹包含版本号,但为了方便起见,将这个文件夹就命名为 lxr 。

下面步骤,基本按照 INSTALL 说明文档进行,有些步骤忽略掉,但不影响最后使用。

当相关软件都安装好,然后 cd 到 lxr 的目录下,登录 mysql ,默认的 mysql 用户 root 是不要密码的,这么登录:
mysql -u root

登录好数据库后,执行命令:
\. initdb-mysql
这条命令的意思是,执行 lxr 目录下的 initdb-mysql 脚本。其目的是创建相应的数据库以及用户名。所以,对于 mysql 用户,root 才有 GRANT 权限,也就是可以创建其他用户及为其分配相关权限。用下面命令看到了新建的数据库 lxr 的信息:
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| lxr                |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.03 sec)
mysql> show tables;
+------------------+
| Tables_in_lxr    |
+------------------+
| lxr_declarations |
| lxr_files        |
| lxr_indexes      |
| lxr_releases     |
| lxr_status       |
| lxr_symbols      |
| lxr_useage       |
+------------------+
7 rows in set (0.01 sec)

现在,要把 LXR 用到的 perl 模块放到 mod_perl 能找到的地方。如果你用的是 Apache 1.x ,那么在说明文档上是这么做的:
cp /usr/local/lxr/Local.pm /usr/lib/perl5/site_perl/
 cp -r /usr/local/lxr/lib/LXR /usr/lib/perl5/site_perl

但是对于 Apache2 ,文档上说有 Apache2 对于外部模块有更聪明的处理办法,但没有具体说明。我对 Apache2 是不熟悉的,我也不知道这个聪明的办法是什么。于是根据 “要把 LXR 用到的 perl 模块放到 mod_perl 能找到的地方“ 这句话,在 /usr/local/perl5/ 目录下建立了一个 site_perl 目录( Mandriva 没有这个目录 ),然后按照上面说的,也把 Local.pm ,以及 LXR 目录搬到下面来。但是在后面的一连串试验中,似乎并不奏效,因为在浏览器里浏览那些 perl 文件时,浏览器却把这些源码都给原本不漏的当成纯文本的显示出来,基于此则推想,可能是 mod_perl 找不到这么些个 Local.pm 文件。于是,会过头来查看了一下 mod_perl 的安装路径:
/usr/lib/apache-extramodules/mod_perl.so
‎/usr/lib/perl5/vendor_perl/5.10.0
‎/usr/lib/perl5/vendor_perl/5.10.0/i386-linux-thread-multi
... ...
第一个是 mod_perl 模块要用到的库,以下的目录都是 mod_perl 所相关连的。所以,尝试索性把 Local.pm 文件和 LXR 目录都拷贝在 /usr/lib/perl5/vendor_pler/5.10.0 里;也同样拷贝另外一份放到 /usr/lib/apache-extramodules/ 中。至于此后到底是哪个目录发生了作用,我并没有去做下试验证明,不想折腾了。但从后面修改的 lxr.conf 文件来看,应该是放在/usr/lib/perl5/vendor_pler/5.10.0 这里才对。也许,不同的 linux 发行版,相关的目录会有所不同。

为了方便,在 lxr 目录下建立一个 http 的目录,为的是放一些网页文件,于是执行命令:
cp /usr/local/lxr/templates/* /usr/local/http/

最后,http 目录里被我放了一大堆文件:
[beyes@localhost http]$ ls
diff*     html-dir.html   html-ident.html           html-search-swish.html  Local.pm   lxr.css
find*     html-find.html  html-ident-refs.html      html-tail.html          lxr.conf   search*
genxref*  html-head.html  html-search-glimpse.html  ident*                  lxr.conf~  source*

上面所显示的文件,Local.pm ,genxref 文件也许不是必须的。但其它的都拷贝过去吧,少了会出问题,多了则不会:)

之后,在 lxr 目录下建立一个 http/lxr.conf 的一个软链接:
ln -s /usr/local/lxr/http/lxr.conf /usr/local/lxr/lxr.conf

下面修改 lxr.conf 文件,具体修改就不列出,干脆把整个文件都呈现出来,以后也好比对:
# -*- mode: perl -*-
# Configuration file
#
(
    {
        # Global configuration

        # Path to glimpse executables.
        # Define this OR the swish-e variable depending which search engine you want to use.
        'glimpsebin'   => '/usr/local/bin/glimpse',
        'glimpseindex' => '/usr/local/bin/glimpseindex',

        # Location of SWISH-E binary
        #'swishbin' => '/usr/local/bin/swish-e',

        # Path to Exuberant Ctags executable
        'ectagsbin' => '/usr/bin/ctags',

        # Place where lxr can write temporary files
        'tmpdir' => '/tmp',

        # Location of the Generic.pm config file
        'genericconf' => '/usr/lib/perl5/vendor_perl/5.10.0/LXR/Lang/generic.conf',

        # Location of the ectags.conf file
        'ectagsconf' => '/usr/lib/perl5/vendor_perl/5.10.0/LXR/Lang/ectags.conf',

        # Paths for CVS module
        'cvspath' => '/bin:/usr/local/bin:/usr/bin:/usr/sbin',
    },

    {

        # Configuration for http://192.168.1.3/lxr.
        # baseurl is used to select configuration block.

        'baseurl' => 'http://127.0.0.1/lxr',    # Put your URL here
             # baseurl_aliases allows other URLs to be used to reach the site
             # comment this out if you do not want any aliases
        'baseurl_aliases' => [ 'http://localhost/lxr', 'http://mydomain/lxr' ],
        'virtroot'        => '/lxr/',                   # The bit after the / above

        'variables' => {

            # Define typed variable "v".  This is the list of versions to index.
            'v' => {
                'name' => '2.6.31.2',

                # This can come from a file, a function or be explicitly
                # ennumerated.
                # From a file:
                'range' => [ readfile('/usr/local/lxr/src/2.6.31.2') ],

                # Explicitly:
                # 'range' => [qw(v1 v2 v3.1 v4 experimental)],
                # If files within a tree can have different versions,
                # e.g in a CVS tree, 'range' can be specified as a
                # function to call for each file:
                #'range'   => sub { return
                #            ($files->allreleases($LXR::Common::pathname),
                #             $files->allrevisions($LXR::Common::pathname))
                #            }, # deferred function call.
                #
                # When using a GIT repo, you can use its tags
                # to create a list of versions. As an extra
                # bonus, with the Linux::KernelSort Perl module,
                # you can properly sort kernel versions. Just
                # leave it off for generic projects.
                #
                #    Simple example for any GIT repo:
                #    'range' => sub {
                #        my $some_dir = "/path/to/project/.git/refs/tags";
                #        opendir (DIR, $some_dir) || die "cannot opendir $some_dir: $!";
                #        my @files = grep { -f "$some_dir/$_" } readdir (DIR);
                #        closedir DIR;
                #        return sort @files;
                #    },
                #
                #    Advanced example for Linus's upstream
                #    linux-2.6 kernel repository:
                #    'range' => sub {
                #        use Linux::KernelSort;
                #        my $kernel = new Linux::KernelSort;
                #
                #        my $some_dir = "/path/to/linux-2.6/.git/refs/tags";
                #        opendir (DIR, $some_dir) || die "cannot opendir $some_dir: $!";
                #        my @files = grep { -f "$some_dir/$_" } readdir (DIR);
                #        closedir DIR;
                #        # Linus's tags all have a leading "v"
                #        # which we must cut off for sorting
                #        # add again afterwards.
                #        for (my $i = 0; $i < scalar (@files); $i++) {
                #            $files[$i] =~ s/^v//;
                #        }
                #        @files = $kernel->sort (@files);
                #        for (my $i = 0; $i < scalar (@files); $i++) {
                #            $files[$i] =~ s/^/v/;
                #        }
                #
                #        return @files;
                #    },

                # The default version to display
                'default' => '2.6.31.2'
            },

            # Define typed variable "a".  First value is default.
            'a' => {
                'name'  => 'Architecture',
                'range' => [qw(i386 alpha arm m68k mips ppc sparc sparc64)]
            },
        },

        # These do funky things to paths in the system - you probably don't need them.
        'maps' => {
            '/include/asm[^\/]*/' => '/include/asm-$a/',
            '/arch/[^\/]+/'       => '/arch/$a/',
        },

        # Templates used for headers and footers
        'htmlhead'     => '/usr/local/lxr/http/html-head.html',
        'htmltail'     => '/usr/local/lxr/http/html-tail.html',
        'htmldir'     => '/usr/local/lxr/http/html-dir.html',
        'htmlident'     => '/usr/local/lxr/http/html-ident.html',
        'htmlident_refs' => '/usr/local/lxr/http/html-ident-refs.html',
        'htmlfind'     => '/usr/local/lxr/http/html-find.html',
        'htmlsearch'     => '/usr/local/lxr/http/html-search-glimpse.html',

        'sourcehead'    => '/usr/local/lxr/http/html-head.html',
        'sourcedirhead'    => '/usr/local/lxr/http/html-head.html',
        'stylesheet'    => '/usr/local/lxr/http/lxr.css',

        # sourceroot - where to get the source files from

        # For ordinary directories, this specifies a directory which has each version as a
        # subdirectory e.g.
        #  indexed-src/version1/...
        #  indexed-src/version2/...
        # The names of the version directories must match the values for the Version
        # variable above.
        'sourceroot' => '/usr/local/lxr/src',

        # Alternatively, this can specify a CVS repository by setting the value to "cvs:"
        # followed by the path to the repository.  Note this must be file accessible - remote
        # server access does NOT work.
        #     'sourceroot'    => 'cvs:/hom/karsk/a/CVSROOT/linux',

        # For a BitKeeper repository, specify bk: followed by the path to the
        # repository.  For BK it is also necessary to specify a 'cachepath' parameter in
        # the 'sourceparams' value below.  This should point to a directory where the
        # code can write and read files.
        #     'sourceroot' => 'bk:/some/repository/here',

        # Finally, you can also use GIT, Linux Kernel's new
        # distributes SCM to access the history:
        #     'sourceroot' => 'git:/some/repository/.git'
        #     'sourceroot' => 'git:/some/repostitory.git'
        # The `sourceroot' config variable points to the directory
        # in which you find the `objects', `refs', `index' etc.
        # directories.

        # The name to display for this source tree
        'sourcerootname' => '/usr/local/lxr/src/$v',

        #
        # Any parameters to the source access method should be specified below.
        #
        # BK:    'cachepath' is used for temporary files
        # GIT:    if `do_annotations' is non-zero, the file revision that
        #        introduced each line is displayed.
        #    `do_blame' will add the author of each line to the
        #        output. Keep in mind that the core LXR code
        #        will only request author information if
        #        annotations are switched on, too!
        #
        'sourceparams' => {
            'cachepath'    => '/a/path/here',
            'do_annotate'    => 1,
            'do_blame'    => 1,
        },

        # The DBI identifier for the database to use
        # For mysql, the format is dbi:mysql:dbname=<name>
        # for Postgres, it is dbi:Pg:dbname=<name>
        # for Oracle, it is dbi:Oracle:host=localhost;sid=DEVMMS;port=1521
        'dbname' => 'dbi:mysql:dbname=lxr',

        # If you need to specify the username or password for the database connection,
        # uncomment the following two lines
        #  'dbpass'        => 'foo',
        #  'dbuser'        => 'lxr',

        # If you need multiple lxr configurations in one database, set different table
        # prefixes for them.
          'dbprefix' => 'lxr_',

        # For using glimpse, the directory to store the .glimpse files in is required
        'glimpsedir' => '/usr/local/lxr/glimpse/databases',

        # Location of swish-e index database files if using swish-e
        #'swishdir' => '/a/directory/here/',

        # where to look for include files inside the sourcetree.  This is used to hyperlink
        # to included files.
        'incprefix' => [ '/include', '/include/linux' ],

        # Which extensions to treat as images when browsing.  If a file is an image,
        # it is displayed.
        'graphicfile' => '(?i)\.(gif|jpg|jpeg|pjpg|pjpeg|xbm|png)$',    #'

        # How to map files to languages
        # Note that the string for the key and the first entry in the
        # array MUST match
        'filetype' => {

            # Format is
            # Language name, filepatten regexp, module to invoke,
            # (optional )tabwidth
            # Note that to have another language supported by Generic.pm,
            # you must ensure that:
            # a) exuberant ctags supports it
            # b) generic.conf is updated to specify information about the language
            # c) the name of the language given here matches the entry in generic.conf
            'C' => [
                'C', '\.c$|\.pc$'    #'
                , 'LXR::Lang::Generic', '8'
            ],
            'C++' => [
                'C++',
                '\.C$|((?i)\.c\+\+$|\.cc$|\.cpp$|\.cxx$|\.h$|\.hh$|\.hpp$|\.hxx$|\.h\+\+$)'    #'
                , 'LXR::Lang::Generic', '8'
            ],

            # Some languages are commented out until the relevant entries in generic.conf are made
            # The list here is the set supported by ctags 5.0.1
            # 'Beta'    => [ 'Beta',   '(?i)\.bet$', 'LXR::Lang::Generic' ],
            # 'Eiffel'  => [ 'Eiffel', '(?i)\.e$',   'LXR::Lang::Generic' ],
            # 'Fortran' =>
            #   [ 'Fortran', '(?i)\.f$|\.for$|\.ftn$|\.f77$|\.f90$|\.f95$', 'LXR::Lang::Generic' ],
            'Cobol' => [ 'Cobol',  '(?i)\.cob$', 'LXR::Lang::Cobol' ],
            'Java' => [ 'Java', '(?i)\.java$', 'LXR::Lang::Java', '4' ],

            # 'Lisp' => [
            #    'Lisp', '(?i)\.cl$|\.clisp$|\.el$|\.l$|\.lisp$|\.lsp$|\.ml$', 'LXR::Lang::Generic'
            # ],

            # No tabwidth specified here as an example
            'Make' => [ 'Make', '(?i)\.mak$|(?i)\.mk$|makefile*', 'LXR::Lang::Generic' ],

            # 'Pascal' => [ 'Pascal', '(?i)\.p$|\.pas$',                'LXR::Lang::Generic' ],
            'Perl'   => [ 'Perl',   '(?i)\.pl$|\.pm$|\.perl$',     'LXR::Lang::Generic', '4' ],
            'php'    => [ 'php',    '(?i)\.php$|\.php3$|\.phtml$', 'LXR::Lang::Generic', '2' ],
            'Python' => [ 'Python', '(?i)\.py$|\.python$',         'LXR::Lang::Generic', '4' ],

            # 'rexx'   => [ 'rexx',   '(?i)\.cmd$|\.rexx$|\.rx$',       'LXR::Lang::Generic' ],
            # 'ruby'   => [ 'ruby',   '(?i)\.rb$',                      'LXR::Lang::Generic' ],
            # 'scheme' => [ 'scheme', '(?i)\.sch$|\.scheme$|\.scm$|\.sm$', 'LXR::Lang::Generic' ],
            'shell' => [ 'shell', '(?i)\.sh$|\.bsh$|\.bash$|\.ksh$|\.zsh$', 'LXR::Lang::Generic' ],

            # 's-Lang' => [ 's-Lang', '(?i)\.sl$',                'LXR::Lang::Generic' ],
            'SQL' => [ 'SQL', '(?i)\.sql$|\.pks$|\.pkb$',               'LXR::Lang::Generic' ],
            'VB'  => [ 'VB',  '(?i)\.bas$|\.cls$|\.ctl$|\.frm$|\.vbs$', 'LXR::Lang::Generic' ],
            #'tcl' => [ 'tcl', '(?i)\.tcl$|\.wish$',                     'LXR::Lang::Generic' ],
        },

        # Maps interpreter names to languages.  The format is:
        #  regexp => langname
        #   regexp is matched against the part after #! on the first line of a file
        #   langname must match one of the keys in filetype above.
        #
        # This mapping is only used if the filename doesn't match a pattern above, so
        # a shell script called shell.c will be recognised as a C file, not a shell file.

        'interpreters' => {
            'perl'   => 'Perl',
            'bash'   => 'shell',
            'csh'    => 'shell',
            'python' => 'Python',
            'ksh'    => 'shell',
            'zsh'    => 'shell',
            'sh'     => 'shell',
            'ksh'    => 'shell',
        },

        # a link of the form (prefix)($filepath)(postfix) is generated when viewing a file
        #   example for cvsweb:
        #'cvswebprefix' => 'http://cvs.myhost.com/cgi-bin/cvsweb.cgi',
        #'cvswebpostfix' => '?cvsroot=rootname',
        #   example for viewcvs:
        #'cvswebprefix' => 'http://cvs.myhost.com/cgi-bin/viewcvs.cgi/myroot',
        #'cvswebpostfix' => '',

        # Directories to always ignore. These usually are the SCM's
        # private directories which possibly may contain non-public
        # project history.
        'ignoredirs' => ['CVSROOT', '.git'],
    }
  )
上面,加亮的内容都是根据相应的文件路径修改过的。在 lxr 目录下还建立了一个 scr 目录,这里用来放内核源代码。我只放一个,是 2.6.31.2 的。不想放太多,因为放一个,用 glmipse 建立索引所花去的时间比编译内核还要长,那很是痛苦。

建立源代码索引,用下面的命令:
genxref --url=http://127.0.0.1/lxr --version=2.6.31.2
参数后面的内容,根据自己的情况填写。

还需要把 lxr 目录下的 .htaccess-apache2 文件复制到 http 目录下,然后改名为 .htaccess ,按照网上说的,改了一下内容(说明文档上没有做修改,但这里还是改了),完整内容如下:
Options Indexes ExecCGI FollowSymlinks

order deny,allow

<Files lxr.conf>
deny from all
</Files>

<Files lib>
deny from all
</Files>

<Files ~ (find|search|source|ident|diff|cgi-bin)$>
SetHandler perl-script
PerlHandler ModPerl::RegistryPrefork
#PerlHandler ModPerl::Registry
<Files ~ (search|source|ident|diff|find)$>
SetHandler cgi-script
</Files>
ForceType text/html
PerlOptions +ParseHeaders
</Files>

这么做完了之后,还要再编辑一下 Apache 的 httpd.conf 文件,目的是要建立一下虚拟目录,修改的内容添加到文件最后,如下:
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog /var/log/httpd/dummy-host.example.com-error_log
#    CustomLog /var/log/httpd/dummy-host.example.com-access_log common
#</VirtualHost>
Alias /lxr/ /usr/local/lxr/http/
<Directory /usr/local/lxr/>
AllowOverride All
</Directory>

完后,重启一下 httpd 就可以使用了,截个图:



事实上,也许我的配置并不好,这个显示效果比
http://lxr.linux.no/
上的要差。

用 linux 大概就在于折腾吧。如果可以联网,就用:http://lxr.linux.no/ 这个吧,版本多,齐全,显示还更直观。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-4 13:53 , Processed in 0.079861 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表