LXR 是一個通用的源代碼索引器和交叉引用器 它提供了一個基於 web 的可瀏覽任意定義以及任意標識的用法。 它支持不少種語言。在linux平臺下,一款很是好用的源代碼瀏覽工具。廢話很少說,下面就是安裝步驟:mysql
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
wget https://jaist.dl.sourceforge.net/project/lxr/stable/lxr-2.3.1.tgz
最好解壓至/usr/local/share/
目錄linux
tar -xzf lxr-2.3.1.tgz -C /usr/local/share/ mv lxr-2.3.1 lxr cd lxr
檢查必要的工具備沒有被安裝nginx
./genxref --checkonly
終端會輸出以下提示:git
[ 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/
目錄下文件結構,下面配置就會以這個爲具體例子web
. ├── linux-4.14 │ └── linux-4.14.48 ├── linux-4.16 │ └── linux-4.16.14 └── lxr ├── linux-4.14 └── linux-4.16
接下來執行配置腳本配置LXR的源代碼樹,配置過程以下(多樹結構):sql
$ ./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
sudo cp custom.d/apache-lxrserver.conf /etc/apache2/conf-enabled/ sudo service apach2 restart