小白也能看懂的踩坑日记--ubuntu(rk3588)安装LXR(阅读源码工具)服务器

一、什么是LXR

        LXR是一个通用的源代码索引器和交叉引用器 它提供了一个基于 web 的可浏览任意定义以及任意标识的用法。 它支持很多种语言。

        LXR 曾经被作为 “Linux 交叉引用器” 但是已经被证明它可以用来作为任意基于 Linux 内核的项目的交叉引用 它基于股票网站技术 (这意味着它的输出是标准的 HTML) 所以可以选择任意的可用 web 浏览器来作为他的客户端。 它被设计为不依赖 java 或者任何第三方客户端脚本,这样可以保证系统需求和依赖的最小化。

        人们经常问起 LXR 与 LXRng (见于 http://lxr.linux.no) 之间的差别。 LXRng 是从 LXR 中 fork 出来带有实验性质的用来探索其他技术的分支。 它基于 ajax 并且依赖很多 CPAN 的包。 它使用了很多的客户端脚本,这意味着运算的负载被服务端和客户端一起分担了。 CAUTION!

It looks like lxr.linux.no has closed without notice some time during the first half of 2014. Whether there is a backup of LXRng is unknown.

        在服务端, 任意的带有 cgi 能力的 web 服务器都能表现的很好。在开发过程中,LXR 是一个很有价值的项目合成观察角色。 对于从头开始学习源代码的人来说,它也是一个很有用的工具。 否则,学习曲线会很陡峭。

        简单的说就是一个源码阅读工具,使用web浏览,源码中的各种信息储存在数据库里面,以标签的形式存在。window下有source insight,但有时候不是很方便使用SI阅读源码,因此,搭建打一个lxr服务器来阅读源码。

LXR 项目站点 : https://lxr.sourceforge.io/zh/1-0-InstallSteps/1-0-install.php

源码下载: https://sourceforge.net/projects/lxr/files/stable/

二、安装

        博主使用的是Ubuntu20系统(固件名ROC-RK3588S-PC_Ubuntu20.04-Gnome-r240_v1.0.6f_230404.img),运行在rk3588上面,直接使用apt-get安装相关依赖即可。

        需要的工具有:git、exuberant-ctags 、glimpse、swish-e、apache2、mysql-server、perl、libapache2-mod-perl2、libdbd-mysql-perl。

        glimpse、swish-e安装一个就行,我这里都安装了,推荐安装glimpse,据实践,不安装swish-e貌似有点小问题,但安装了又要再配置文件里面去掉0.0。

sudo apt-get update

sudo apt-get install exuberant-ctags glimpse swish-e

sudo apt-get install perl libapache2-mod-perl2 libdbd-mysql-perl

sudo apt-get install libfile-mmagic-perl

sudo apt-get install apache2 mysql-server

安装完整之后,先去下载lxr源码,解压到/usr/local/share/lxr中,路径可以替换。

1、配置lxr

进入到/usr/local/share/lxr路径中,使用

./genxref --checkonly

 其中,perl大于5.10版本,ctags大于5.0,glimpse和swish-e有一个就行。到这里之后,需要对lxr进行配置,生成配置文件lxr.conf、web服务器配置文件和数据库初始化文件。

./scripts/configure-lxr.pl -vv

        具体的在附录,基本上全默认就行了,具体的可以参考https://lxr.sourceforge.io/zh/1-0-InstallSteps/1-0-install.php这个链接就行。比较重要的是源码存放路径、数据库存放路径和代码版本,博主的参数如下:

/usr/local/share/linux_kernel
/usr/local/share/glimpse_DB
/usr/local/share/swish_e_DB

2.4.18

对于lxr来说,代码root目录在/usr/local/share/linux_kernel,里面每一个版本代表一个工程,名字随意起,博主起名2.4.18,表示Linux2.4.18版本。

第一个参数表示代码树(就是工程数量)是一个还是多个,这里只能在./scripts/configure-lxr.pl -vv运行是配置,无法通过后面修改配置文件修改功能,我这里选择m,表示多个代码树。

 

 其他的参数基本上可以说随意了。

2、初始化数据库

首先,在数据库中,生成对应的表:

sudo ./custom.d/initdb.sh

将lxr.conf移动到/usr/local/share/lxr目录下,生成检索信息时会用到。

sudo cp custom.d/lxr.conf .

在里面要将swish-e相关路径给屏蔽了。

之后,还需要将linux源码解压到/usr/local/share/linux_kernel/2.4.18目录下,

 

到这里以及准备好了lxr大部分东西了,现在需要对Linux源码生成检索信息,信息存放在数据库里面,路径为:/usr/local/share/glimpse_DB

 sudo ./genxref --url=http://localhost/lxr --version=2.4.18

这个过程很慢很慢,rk3588来处理2.4.18内核大概需要2个小时,睡一觉起来再看它。

3、配置apache2服务器

好了之后,启动apache2服务器,需要先配置下服务器。

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

在重启apache2之前,我们还需更改 /etc/apache2/conf-available/serve-cgi-bin.conf文件。

vim /etc/apache2/conf-available/serve-cgi-bin.conf

 同时还要修改

vim /etc/apache2/sites-enabled/000-default.conf

 <Directory /usr/local/share/lxr>
               AddHandler perl-script .pl .cgi
               PerlResponseHandler ModPerl::Registry
               Options +ExecCGI +FollowSymLinks +MultiViews
               PerlOptions +ParseHeaders
               AllowOverride All
               Order allow,deny
               Allow from all 
         </Directory>

这里一切顺利的化,可以启动apache2服务器了。

sudo a2enmod cgid

 sudo a2dismod mpm*

 sudo a2enmod mpm_worker

sudo systemctl restart apache2

        启动之后,可以使用浏览器查看http://localhost/lxr/source网址中的信息。 博主rk3588的局域网ip是192.168.31.193,若是使用http://192.168.31.193/lxr/source查看,会得到错误,无法显示,,提示找不到源码树(我就掉这个坑里了,一直以为是我哪里配置错了,在局域网用ip访问就看不到信息,百度谷歌翻遍了都没找到),像这样的错误。

其实,这个问题是网络权限问题,只要在lxr.conf中将自己的ip添加到host_names里面就行了。

        这样在局域网也能查看到了,这里附一张局域网下看到的linux源码图像。虽然没有source insight看起来舒服,但凑合用吧(博主一直用SI看代码,但SI有版权,某些时候不方便)。

恭喜你完成了lxr的安装与配置!

三、总结

       我找到的 LXR相关资料,都是比较老了,基本上都是在ubuntu16以前安装的,整体还算可以,唯独在局域网ip访问这里被坑到了,rk3588没屏幕是看不到的,搞了一天才解决这个问题,记录下这个坑,希望能对各位小伙伴有所帮助。

附录 

firefly@firefly:~/3rlib/lxr-2.3.6$ ./scripts/configure-lxr.pl -vv
*** LXR configurator (version: 2.4) ***

LXR root directory is /home/firefly/3rlib/lxr-2.3.6
Configuration will be stored in custom.d/

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 host
   hostname
   embedded in section
 > 

The computer hosting the server is described by an URL.
The form is !scheme://host_name:port
where:
  - ! is an optional flag (see below),
  - scheme is either http or https,
  - host_name can be given as an IPv4 address such as 123.45.67.89,
              an IPv6 address like [fe80::1234:90ab]
              or a domain name like localhost or lxr.url.example,
  - port is 1 to 65535.
Scheme: or :port must be specified if you want to restrict
access to the tree through the designated scheme or port.
This restriction is requested with the ! prefix flag.
--- Host name or IP? [//localhost] > 
--- 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] > 
All databases can be accessed with the same username and
can also be described under the same names.
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 glimpse databases? > /usr/local/share/glimpse_DB
--- Directory for swish-e databases? > /usr/local/share/swish_e_DB
REMINDER: after this configuration step, open lxr.conf
and comment out one of 'glimpsebin' or 'swishbin'.

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 //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) > HTQ_LXR
Do you want a speed switch button for this tree ? [YES/no] > 
--- Short title for button? (e.g. XYZZY) > HTQ_BTN
--- Tree identification in URL? (e.g. the-tree) > the-tree
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) > /usr/local/share/linux_kernel
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?  > 2.4.18
--- 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? > lxr_database
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
configuration saved in custom.d/lxr.conf
DB initialisation script is custom.d/initdb.sh

猜你喜欢

转载自blog.csdn.net/zichuanning520/article/details/130901047
今日推荐