1

简介

LXR 是一个通用的源代码索引器和交叉引用器 它提供了一个基于 web 的可浏览任意定义以及任意标识的用法。 它支持很多种语言。在linux平台下,一款非常好用的源代码浏览工具。废话不多说,下面就是安装步骤:

必须工具包

sudo apt-get install apache2 libapache2-mod-perl2
sudo apt-get install mysql-server libdbd-mysql-perl libdbi-perl
sudo apt-get install exuberant-ctags swish-e libfile-mmagic-perl

下载LXR

wget https://jaist.dl.sourceforge.net/project/lxr/stable/lxr-2.3.1.tgz

最好解压至/usr/local/share/目录

tar  -xzf lxr-2.3.1.tgz -C /usr/local/share/
mv lxr-2.3.1 lxr
cd lxr

检查必要的工具有没有被安装

./genxref --checkonly

终端会输出如下提示:

[  OK  ]     Perl     version ... 5.22.1
[  OK  ]     ctags    version ... 5.9
Parameter 'glimpsebin' not defined - trying to find glimpse
glimpse not found, `command -v glimpse` returned a null string
Parameter 'glimpseindex' not defined - trying to find glimpseindex
glimpseindex not found, `command -v glimpseindex` returned a null string
[  OK  ]    swish-e   version ... 2.4.7
genxref stopped without indexing by --checkonly option

这样的输出是没有问题的
先看一下我的/home/$USER/LXR/目录下文件结构,下面配置就会以这个为具体例子

.
├── linux-4.14
│   └── linux-4.14.48
├── linux-4.16
│   └── linux-4.16.14
└── lxr
    ├── linux-4.14
    └── linux-4.16

接下来执行配置脚本配置LXR的源代码树,配置过程如下(多树结构):

$ ./scripts/configure-lxr.pl -vv
*** LXR configurator (version: 2.3) ***

LXR root directory is /home/charleye/Downloads/lxr-2.3.1
Configuration will be stored in custom.d/
directory custom.d created
directory custom.d/db-scripts.d created

Configure for single/multiple trees? [S/m] > m  选择创建单源代码树还是多源代码树

*** LXR web server configuration ***

Many different configurations are possible, they are related to the way
LXR service is accessed, i.e. to the structure of the URL.
Refer to the User's Manual for a description of the variants.

LXR can be located at the server-root (so called dedicated)
or lower in the server hierarchy (shared because there are
usually other pages or sections).
Server type? [dedicated/SHARED] >  默认就可以,直接回车

Selecting which tree to display can be done in various ways:
  1. from the host name (all names are different),
  2. from a prefix to a common host name (similar to previous)
  3. from the site section name (all different)
  4. from interpretation of a section name part (similar to previous)
  5. from the head of script arguments
Method 5 is highly recommended because it has no impact on webserver
  configuration.
Method 3 is second choice but involves manually setting up many
  symbolic links (one per source-tree).
Method 1 & 2 do not involve symbolic links but need populating webserver
  configuration with virtual hosts.
  Note that method 2 does not work well on //localhost.
Method 4 is deprecated because it has proved not easily portable
  under alternate webservers (other than Apache).

Tree designation?:
   ARGUMENT
   section name
   prefix in hos
   hostname
   embedded in section
 > 默认就可以,直接回车

The computer hosting the server is described by an URL.
The form is scheme://host_name:port
where:
  - scheme is either http or https (http: can be omitted),
  - host_name can be given as an IP address such as 123.45.67.89
              or a domain name like localhost or lxr.url.example,
  - port may be omitted if standard for the scheme.
--- Host name or IP? [//localhost] >  因为是在本地搭建LXR服务,直接回车
--- Alias name or IP? > 直接回车
URL section name for LXR in your server? [/lxr] > 直接回车
Will it be shared by all trees? [YES/no] >  直接回车

*** LXR database configuration ***


The choice of the database engine can make a difference in indexing performance,
but resource consumption is also an important factor.
  * For a small personal project, try SQLite which do not
    need a server and is free from configuration burden.
  * For medium to large projects, choice is between MySQL,
    PostgreSQL and Oracle.
    Oracle is not a free software, its interface has not been
    tested for a long time.
  * PostgreSQL databases are smaller than MySQL's
    and performance is roughly equivalent.
  * MySQL is at its best with large-sized projects
    (such as kernel cross-referencing) where it is fastest at the cost
    of bigger databases.
  * Take also in consideration the number of connected users.
Database engine? [MYSQL/oracle/postgres/sqlite] > 选择默认就可以,直接回车
The safest option is to create one database per tree.
You can however create a single database for all your trees with a specific set of
tables for each tree (though this is not recommended).
How do you setup the databases? [PER TREE/global] >  直接回车
Will you share database characteristics? [YES/no] >  直接回车
Will you use the same username and password for all DBs? [YES/no] > 直接回车
--- DB user name? [lxr] >  直接回车
--- DB password ? [lxrpw] >  直接回车
Will you give the same prefix to all tables? [YES/no] >  直接回车
--- Common table prefix? [lxr_] >  直接回车
--- Directory for swish-e databases? >/home/$USER/LXR   指定生成的源代码索引存放目录,最好与源代码放在同一父目录

file .htaccess written into LXR root directory
file apache2-require.pl written into configuration directory
file apache-lxrserver.conf written into configuration directory
file lighttpd-lxrserver.conf written into configuration directory
file nginx-lxrserver.conf written into configuration directory
file thttpd-lxrserver.conf written into configuration directory
Mercurial support files written into configuration directory

*** LXR master configuration file setup ***
    Global section part

*** Configuring auxiliary tool paths
*** Host name previously defined as http://localhost
*** Configuring HTML parameters
*** 'Buttons-and-menus' interface is recommended for the kernel
*** to avoid screen cluttering.
--- Use 'buttons-and-menus' instead of 'link' interface? [YES/no] >  直接回车
*** Configuring file subsection
*** Configuring "common factors"
*** Marking tree section

*** LXR master configuration file setup ***
    Tree section part
    SQL script for database initialisation

*** Configuring LXR server parameters
*** The virtual root is the fixed URL part after the hostname.
*** You previously defined the virtual root as /lxr
--- Caption in page header? (e.g. Project XYZZY displayed by LXR) > linux-4.16 标题必填
Do you want a speed switch button for this tree ? [YES/no] >  直接回车
--- Short title for button? (e.g. XYZZY) > linux-4.16.0  别名
--- Tree identification in URL? (e.g. the-tree) > linux-4.16 这个源码代码树的名称,在生成索引,很有用
Do you need a specific encoding for this tree ? [yes/NO] >  直接回车
*** Describing tree location
How is your tree stored? [FILES/cvs/git/svn/hg/bk] > 直接回车
*** A source directory contains one sub-directory for every version.
--- Source directory? (e.g. /home/myself/project-tree) > /home/$USER/LXR/linux-4.16/ 各版本源代码存放目录
Name to display for the path root? (e.g. Project or $v for version) [$v] > 直接回车
*** Enumerating versions
Label for version selection menu?  [Version] >  直接回车
*** Versions can be explicitly enumerated, be read from a file or computed
*** by a function. The latter case is recommended for VCS-stored trees.
Version enumeration method? [LIST/file/function] >  直接回车
--- Version name?  >  linux-4.16.14  版本号
--- Version name? (hit return to stop) >  没有的话,直接回车
*** By default, first version in list is displayed. You may also indicate
*** a prefered version.
--- Default displayed version is first in 'range'? [YES/no] >  直接回车
*** Setting directory lists
*** Some directories may contain non-public project data (binaries,
*** compilers caches, SCM control data, ...). They can be hidden from LXR.
--- Directory to ignore, e.g. CVSROOT or CVS? (hit return to stop) > 直接回车
*** If your source code uses "include" statements (#include, require, ...)
*** LXR needs hints to resolve the destination file.
--- Include directory, e.g. /include? (hit return to stop) > 可以指定额外的头文件目录,这里我直接回车
*** Configuring data storage
--- Database name? > linux_4_16 这颗树的数据库名称,注意特殊字符
Do you want to override the global 'lxr' user name? [yes/NO] > 直接回车
Do you want to override the global 'lxr_' table prefix? [yes/NO] > 直接回车

*** Configure another tree? [YES/no] > 配置另外一颗树,有的话继续,没有输入no,

初始化数据库

./custom.d/initdb.sh

复制生成的配置文件

 cp custom.d/lxr.conf .

生成源代码索引

./genxref --url=http://localhost/lxr --tree=linux-4.16 --allversions
or
./genxref --url=http://localhost/lxr --tree=linux-4.16 --version=linux-4.16.14

设置web服务(apach2)

sudo cp custom.d/apache-lxrserver.conf /etc/apache2/conf-enabled/
sudo service apach2 restart

验证

图片描述
图片描述

参考

lxr-2.3.1/doc/INSTALL


Charley
3 声望0 粉丝

引用和评论

0 条评论