Linux源码编译安装

论坛 期权论坛 脚本     
匿名网站用户   2020-12-21 03:38   42   0

源码在GithubThe Linux KernelArchives上都以一个tarball档案的方式发布。tarball是压缩过的tartape archive)档案。源码tarball名称通常有版本资讯(如linux-2.6.32.tar.gz中的linux-2.6.32),副档名为.tar.gz.tgz(如linux-2.6.32.tar.gz中的.tar.gz)。

tarball套件安装的基本步骤如下:

步骤

说明

<1>下载tarball

<2>tarball解打包压缩

通常解包到/usr/local/src/tarballname的目录下,包含:

<1>源码档案

<2>源码检测档案(可能是configureconfig等档名)

<3>本套件的简易说明与安装说明(INSTALLREADME

<3>安装依赖套件

比如要编译源文件,则需要gcc套件

<4>执行configure

检测工作环境,并生成Makefile档案

<5>执行make

将源码编译成可执行文件,并放置在当前的目录下

<6>执行make install

将当前目录下的可执行文件安装到预定安装的目录中

默认情况下,Linuxdistribution发布安装的软件大多是在/usr里面的,而用户自行安装的软件则建议放置在/usr/local里面,源码(tarball)则建议放置在/usr/local/src下面。

gcc来说明linuxdistribution的默认安装路径:

root@ubuntu:~# find / -name gcc

/etc/bash_completion.d/gcc /*gcc命令自动补全功能*/

/usr/bin/gcc /*可执行文件*/

/usr/lib/gcc /*函数库*/

/usr/share/man/man1/gcc-4.4.1.gz/*gcc在线帮助文档*/

/usr/share/doc/gcc-4.4-base/gcc /*gcc文件说明*/

root@ubuntu:~#

如果将自行安装的软件放置在/usr/local里面,则由于/usr/local原本就默认了这几个目录,所以数据就会被放在:

/usr/local/bin

/usr/local/lib

/usr/local/man

自行安装时,默认路径就是/usr/local,但将来想要升级或删除时需要追查文件源并一一删除,这样会比较麻烦。所以一般建议将安装路径设为/usr/local/tarballname。当需要卸载时,直接rm -rf /usr/local/tarballname即可。

/usr/local/tarballname/bin

/usr/local/tarballname/lib

/usr/local/tarballname/man

当然,需要设置命令的路径。因为在执行某些命令时,与该命令是否在PATH这个环境变量所记录的路径有关,如果不想以绝对路径执行(/usr/local/tarballname/bin),需要在PATH里加入/usr/local/tarballname/bin。另外,/usr/local/tarballname/man也需要加入man page的搜索路径当中/etc/manpath.config

root@ubuntu:/usr/local# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

步骤解析:

1 tarball的解打包压缩

*.tar.gz使用命令:tar zxvf *.tar.gz

*.tar.bz2使用命令:tar jxvf*.tar.bz2

2】执行./configure

configure的参数可通过--help来查看:

root@ubuntu:/usr/local/src/fuse-2.8.4# ./configure --help

Configuration:

-h, --helpdisplay this help and exit

--help=shortdisplay options specific to this package

--help=recursivedisplay the short help of all the included packages

-V, --versiondisplay version information and exit

Installation directories:/*指定软件安装路径*/

--prefix=PREFIXinstall architecture-independent files in PREFIX

[/usr/local]

--exec-prefix=EPREFIXinstall architecture-dependent files in EPREFIX

[PREFIX]

By default, `make install' will install all the files in

`/usr/local/bin', `/usr/local/lib' etc.You can specify

an installation prefix other than `/usr/local' using `--prefix',

for instance `--prefix=$HOME'.

Program names:

--program-prefix=PREFIXprepend PREFIX to installed program names

--program-suffix=SUFFIXappend SUFFIX to installed program names

--program-transform-name=PROGRAMrun sed PROGRAM on installed program names

System types:

--build=BUILDconfigure for building on BUILD [guessed]

--host=HOSTcross-compile to build programs to run on HOST [BUILD]

--target=TARGETconfigure for building compilers for TARGET [HOST]

Optional Features:

--disable-option-checkingignore unrecognized --enable/--with options

--disable-FEATUREdo not include FEATURE (same as --enable-FEATURE=no)

--enable-FEATURE[=ARG]include FEATURE [ARG=yes]

--enable-shared[=PKGS]build shared libraries [default=yes]

Optional Packages:

--with-PACKAGE[=ARG]use PACKAGE [ARG=yes]

--without-PACKAGEdo not use PACKAGE (same as --with-PACKAGE=no)

Some influential environment variables:

CCC compiler command

CFLAGSC compiler flags

3】执行make

make的参数可通过help来查看:

root@ubuntu: /usr/local/src/fuse-2.8.4#make --help

Usage: make [options] [target] ...

Options:

-b, -mIgnored for compatibility.

-B, --always-makeUnconditionally make all targets.

-h, --helpPrint this message and exit.

-i, --ignore-errorsIgnore errors from commands.

-j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg.

-k, --keep-goingKeep going when some targets can't be made.

4】执行make install

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP