linux 源码编译 ./configure 的配置和用法


1. linux从源码编译到安装软件的3个步骤

./configure  
make  
make install  

1)./configure:
configure是一个脚本,一般由Autoconf工具生成,它会检验当前的系统环境,看是否满足安装软件所必需的条件:比如当前系统是否支持待安装软件,是否已经安装软件依赖等。configure脚本最后会生成一个Makefile文件。
2)make
make是一个命令,它使用第1步得到的Makefile文件,如果只有"make"命令,而没有指明"目标",一般情况下是编译源码。
3)make install
make install表示运行"目标为install的make命令",即将编译后的结果复制到相应目录中。

2. ./configure 的配置和用法

每个configure脚本可配置参数都是不同的,具体可通过以下命令来查看:

./configure --help

下面以编译gdb-7.12.tar.gz为例,执行./configure --help

mayue6@Cpl-Ezviz-General-14-173:~/bulidspace/gdb-7.12-01/gdb-7.12/gdb$ ./configure --help
`configure' configures this package to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
  -h, --help              display this help and exit
      --help=short        display options specific to this package
      --help=recursive    display the short help of all the included packages
  -V, --version           display version information and exit
  -q, --quiet, --silent   do not print `checking...' messages
      --cache-file=FILE   cache test results in FILE [disabled]
  -C, --config-cache      alias for `--cache-file=config.cache'
  -n, --no-create         do not create output files
      --srcdir=DIR        find the sources in DIR [configure dir or `..']

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install 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'.

For better control, use the options below.

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --libexecdir=DIR        program executables [EPREFIX/libexec]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
  --libdir=DIR            object code libraries [EPREFIX/lib]
  --includedir=DIR        C header files [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc [/usr/include]
  --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
  --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
  --infodir=DIR           info documentation [DATAROOTDIR/info]
  --localedir=DIR         locale-dependent data [DATAROOTDIR/locale]
  --mandir=DIR            man documentation [DATAROOTDIR/man]
  --docdir=DIR            documentation root [DATAROOTDIR/doc/PACKAGE]
  --htmldir=DIR           html documentation [DOCDIR]
  --dvidir=DIR            dvi documentation [DOCDIR]
  --pdfdir=DIR            pdf documentation [DOCDIR]
  --psdir=DIR             ps documentation [DOCDIR]

Program names:
  --program-prefix=PREFIX            prepend PREFIX to installed program names
  --program-suffix=SUFFIX            append SUFFIX to installed program names
  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names

X features:
  --x-includes=DIR    X include files are in DIR
  --x-libraries=DIR   X library files are in DIR

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET   configure for building compilers for TARGET [HOST]

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-maintainer-mode  enable make rules and dependencies not useful
			  (and sometimes confusing) to the casual installer
  --enable-plugins        Enable support for plugins
  --disable-largefile     omit support for large files
  --disable-build-with-cxx
                          build with C compiler instead of C++ compiler
  --enable-targets=TARGETS
                          alternative target configurations
  --enable-64-bit-bfd     64-bit support (on hosts with narrower word sizes)
  --disable-gdbcli        disable command-line interface (CLI)
  --disable-gdbmi         disable machine-interface (MI)
  --enable-tui            enable full-screen terminal user interface (TUI)
  --enable-gdbtk          enable gdbtk graphical user interface (GUI)
  --enable-profiling      enable profiling of GDB
  --disable-rpath         do not hardcode runtime library paths
  --enable-libmcheck      Try linking with -lmcheck if available
  --enable-werror         treat compile warnings as errors
  --enable-build-warnings enable build-time compiler warnings if gcc is used
  --enable-gdb-build-warnings
                          enable GDB specific build-time compiler warnings if
                          gcc is used
  --enable-sim            link gdb with simulator
  --enable-multi-ice      build the multi-ice-gdb-server
  --enable-gdbserver      automatically build gdbserver (yes/no/auto, default
                          is auto)

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-separate-debug-dir=PATH
                          look for global separate debug info in this path
                          [LIBDIR/debug]
  --with-gdb-datadir=PATH look for global separate data files in this path
                          [DATADIR/gdb]
  --with-relocated-sources=PATH
                          automatically relocate this path for source files
  --with-auto-load-dir=PATH
                          directories from which to load auto-loaded scripts
                          [$debugdir:$datadir/auto-load]
  --with-auto-load-safe-path=PATH
                          directories safe to hold auto-loaded files
                          [--with-auto-load-dir]
  --without-auto-load-safe-path
                          do not restrict auto-loaded files locations
  --with-libunwind-ia64   use libunwind frame unwinding for ia64 targets
  --with-curses           use the curses library instead of the termcap
                          library
  --with-pkgversion=PKG   Use PKG in the version string in place of "GDB"
  --with-bugurl=URL       Direct users to URL to report a bug
  --with-system-zlib      use installed libz
  --with-gnu-ld           assume the C compiler uses GNU ld default=no
  --with-libiconv-prefix[=DIR]  search for libiconv in DIR/include and DIR/lib
  --without-libiconv-prefix     don't search for libiconv in includedir and libdir
  --with-iconv-bin=PATH   specify where to find the iconv program
  --with-system-readline  use installed readline library
  --with-jit-reader-dir=PATH
                          directory to load the JIT readers from
  --with-expat            include expat support (auto/yes/no)
  --with-libexpat-prefix[=DIR]  search for libexpat in DIR/include and DIR/lib
  --without-libexpat-prefix     don't search for libexpat in includedir and libdir
  --with-python[=PYTHON]  include python support
                          (auto/yes/no/<python-program>)
  --with-guile[=GUILE]    include guile support
                          (auto/yes/no/<guile-version>/<pkg-config-program>)
  --with-intel-pt         include Intel Processor Trace support (auto/yes/no)
  --with-libipt-prefix[=DIR]  search for libipt in DIR/include and DIR/lib
  --without-libipt-prefix     don't search for libipt in includedir and libdir
  --without-included-regex
                          don't use included regex; this is the default on
                          systems with version 2 of the GNU C library (use
                          with caution on other system)
  --with-sysroot[=DIR]    search for usr/lib et al within DIR
  --with-system-gdbinit=PATH
                          automatically load a system-wide gdbinit file
  --with-lzma             support lzma compression (auto/yes/no)
  --with-liblzma-prefix[=DIR]  search for liblzma in DIR/include and DIR/lib
  --without-liblzma-prefix     don't search for liblzma in includedir and libdir
  --with-tcl              directory containing tcl configuration (tclConfig.sh)
  --with-tk               directory containing tk configuration (tkConfig.sh)
  --with-x                use the X Window System
  --with-babeltrace       include babeltrace support (auto/yes/no)
  --with-libbabeltrace-prefix[=DIR]  search for libbabeltrace in DIR/include and DIR/lib
  --without-libbabeltrace-prefix     don't search for libbabeltrace in includedir and libdir

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CXX         C++ compiler command
  CXXFLAGS    C++ compiler flags
  CPP         C preprocessor
  MAKEINFO    Parent configure detects if it is of sufficient version.
  MAKEINFOFLAGS
              Parameters for MAKEINFO.
  YACC        The `Yet Another C Compiler' implementation to use. Defaults to
              the first program found out of: `bison -y', `byacc', `yacc'.
  YFLAGS      The list of arguments that will be passed by default to $YACC.
              This script will default YFLAGS to the empty string to avoid a
              default value of `-d' given by some make applications.
  XMKMF       Path to xmkmf, Makefile generator for X Window System

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to the package provider.

基本配置

Configuration:
  -h, --help              display this help and exit
  ……

-h 或 --help
输出帮助信息。即使是有经验的用户也偶尔需要使用使用’–help’选项,因为一个复杂的项目会包含附加的选项。例如,GCC包里的’configure’脚本就包含了允许你控制是否生成和在GCC中使用GNU汇编器的选项。

-V 或 --version
打印用来产生’configure’脚本的Autoconf的版本号。

配置安装目录

Installation directories:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [PREFIX]

--prefix=PREFIX
指定程序包的安装目录,示例./configure --prefix="$PWD/install"

--exec-prefix=EPREFIX
与’–prefix’选项类似,但是他是用来设置结构倚赖的文件的安装位置.编译好的’emacs’二进制文件就是这样一个文件.如果没有设置这个选项的话,默认使用的选项值将被设为和’–prefix’选项值一样.

微调安装目录

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  ……

--bindir=DIR
指定二进制文件的安装位置,这里的二进制文件定义为可以被用户直接执行的程序。

--sbindir=DIR
指定超级二进制文件的安装位置.这是一些通常只能由超级用户执行的程序。

--libexecdir=DIR
指定可执行支持文件的安装位置。与二进制文件相反,这些文件从来不直接由用户执行,但是可以被上面提到的二进制文件所执行。

--datadir=DIR
指定通用数据文件的安装位置。

--libdir=DIR
指定库文件的安装位置。

--includedir=DIR
指定为除GCC外编译器安装的C头文件的安装位置。

--infodir=DIR
指定Info格式文档的安装位置.Info是被GNU工程所使用的文档格式。

--mandir=DIR
指定手册页的安装位置。

--srcdir=DIR
这个选项对安装没有作用,他会告诉’configure’源码的位置。一般来说不用指定此选项,因为’configure’脚本一般和源码文件在同一个目录下。

配置程序名称

Program names:
  --program-prefix=PREFIX            prepend PREFIX to installed program names
  --program-suffix=SUFFIX            append SUFFIX to installed program names
  --program-transform-name=PROGRAM   run sed PROGRAM on installed program names

--program-prefix=my
在生成的可执行文件前加前缀my,例如,使用’–program-prefix=g’来configure一个名为’tar’的程序将会使安装的程序被命名为’gtar’。当和其他的安装选项一起使用时,这个选项只有当他被`Makefile.in’文件使用时才会工作。

--program-suffix=suffix
在生成的可执行文件上加后缀suffix。

--program-transform-name=program
将可执行文件的名字设置为program,例如,假设生成的默认可执行文件的名字为hello,执行

./configure --program-prefix=test- && make && make install

则生成名字为test-hello的可执行文件。

配置系统类型

System types:
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET   configure for building compilers for TARGET [HOST]

--build=BUILD
指定软件包安装的系统平台。如果没有指定,默认值将是’–host’选项的值。

--host=HOST
指定软件运行的系统平台。如果没有指定。将会运行`config.guess’来检测。

--target=GARGET
指定软件面向(target to)的系统平台。这主要在程序语言工具如编译器和汇编器上下文中起作用。如果没有指定,默认将使用’–host’选项的值。

示例:

./configure --target=mipsel-linux --host=mipsel-linux

详细用法参考:https://blog.csdn.net/mayue_web/article/details/103987915

配置可选特性

Optional Features:
  --disable-option-checking  ignore unrecognized --enable/--with options
  ……

--enable-werror
将编译警告视为错误。

配置包选项

Optional Packages:
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  ……

–with-PACKAGE[=ARG]
在自由软件社区里,有使用已有软件包和库的优秀传统。当用’configure’来配置一个源码树时,可以提供其他已经安装的软件包的信息。例如,倚赖于Tcl和Tk的BLT器件工具包。要配置BLT,可能需要给’configure’提供一些关于我们把Tcl和Tk装的何处的信息:

./configure --with-tcl=/usr/local --with-tk=/usr/local

‘–with-PACKAGE=no’与下面将提到的’–without-PACKAGE’是同义的。

--without-PACKAGE
有时候你可能不想让你的软件包与系统已有的软件包交互。例如,你可能不想让你的新编译器使用GNU ld。通过使用这个选项可以做到这一点:

./configure --without-gnu-ld

配置编译环境变量

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  ……

CC=
.c文件的编译命令,示例CC=/usr/bin/mipsel-linux-gcc

CFLAGS=
.c文件的编译选项,示例CFLAGS="-g -O2 -I/home/mayue/bulidspace/termcap-1.3.1/install/include"

LDFLAGS=
链接选项,示例LDFLAGS="-L/home/mayue/bulidspace/termcap-1.3.1/install/lib"

LIBS=
链接库,示例LIBS="-lpthread"

CPPFLAGS=
C/C++文件预处理选项,示例

CXX=
c++文件的编译命令,示例CXX=/usr/bin/mipsel-linux-g++

CXXFLAGS=
c++文件的编译选项,示例

CPP=
C预处理器,示例

3. 综合示例

示例1:

./configure CC=/usr/bin/mipsel-linux-gcc --host=mipsel-linux --target=mipsel-linux --program-prefix=mipsel-linux --prefix=/home/mayue/bulidspace/termcap-1.3.1/install

示例2:

./configure CC=/usr/bin/mipsel-linux-gcc --enable-static CFLAGS="-g -O2 -I/home/mayue/bulidspace/termcap-1.3.1/install/include" LDFLAGS="-L/home/mayue/bulidspace/termcap-1.3.1/install/lib" --prefix=/home/mayue/bulidspace/gdb-7.6.1/install/mipsel --target=mipsel-linux --host=mipsel-linux --program-prefix=mipsel-linux-

示例3

./configure --host=x86_64-linux-gnu --target=mipsel-linux --prefix="$PWD/install"

参考资料
https://jingyan.baidu.com/article/86112f1382da1e27379787ed.html
https://blog.csdn.net/dslztx/article/details/49079303
https://www.cnblogs.com/zl-graduate/articles/6600742.html
https://www.jianshu.com/p/0d64954eb9bc

发布了60 篇原创文章 · 获赞 43 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/mayue_web/article/details/103988629
今日推荐