# 下載源碼
$ wget http://zlib.net/zlib-1.2.11.tar.gz
$ tar -zxvf zlib-1.2.11.tar.gz# 創建安裝目錄install
$ mkdir install
$ ls
install zlib-1.2.11 zlib-1.2.11.tar.g
$ cd zlib-1.2.11# 查看幫助文檔
$ ./configure --help
usage:configure [--const][--zprefix][--prefix=PREFIX][--eprefix=EXPREFIX][--static][--64][--libdir=LIBDIR][--sharedlibdir=LIBDIR][--includedir=INCLUDEDIR][--archs="-arch i386 -arch x86_64"]
# 這里并沒有提示類似--host,--cross_complie之類方便指定交叉編譯工具鏈的選項
# --prefix=PREFIX 指定安裝路徑
# --static 編譯靜態庫, 注意這里最好編譯動態庫,不要選--static
# 編譯靜態庫時,在后面配置dropbear時可能會報"checking for deflate in -lz... no"這樣的錯誤
# ./configure --prefix=`pwd`/../install --static# 編譯動態庫
$ ./configure --prefix=`pwd`/../install# 運行configure之后,打開生成的makefile,可以從中找到關鍵的CC,CPP這些和交叉編譯有關的地方,修改成自己的交叉編譯工具,如
# CC=arm-linux-gcc
# CPP=arm-linux-gcc -E
# AR=arm-linux-ar
# RANLIB=arm-linux-ranlib
# LDSHARED=arm-linux-gcc
# 注意在make之前要將交叉編譯工具的路徑添加到當前的shell環境中,可以命令export=$PATH:交叉編譯工具的路徑
# 或者使用廠家提供的sdk中的source來設置交叉編譯工具的環境,如果先用這種方式設置環境,再使用configure,一般都不必再修改Makefile了# 編譯和安裝
make
make install# 編譯安裝結果
$ ls ../install/
include lib share
2. 編譯dropbear
#表示注釋 $表示命令行
# 下載源碼
$ wget https://matt.ucc.asn.au/dropbear/releases/dropbear-2020.81.tar.bz2# 解壓
$ tar -jxvf dropbear-2020.81.tar.bz2# 創建安裝路徑
mkdir install
$ ls
install dropbear-2020.81 dropbear-2020.81.tar.bz2
$ cd dropbear-2020.81
# 查看編譯幫助文檔
$ ./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 inFILE[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 inPREFIX[/usr/local]--exec-prefix=EPREFIX install architecture-dependent files inEPREFIX[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=DIRC header files [PREFIX/include]--oldincludedir=DIRC 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]System types:--build=BUILD configure for building on BUILD[guessed]--host=HOST cross-compile to build programs to run on HOST[BUILD]Optional Features:--disable-option-checking ignore unrecognized --enable/--with options--disable-FEATUREdo not include FEATURE(same as--enable-FEATURE=no)--enable-FEATURE[=ARG] include FEATURE[ARG=yes]--enable-static Build static binaries--disable-harden Don't set hardened build flags--disable-largefile omit support for large files--disable-zlib Don't include zlib support--enable-pam Try to include PAM support--disable-openpty Don't use openpty, use alternative method--disable-syslog Don't include syslog support--disable-shadow Don't use shadow passwords(if available)--enable-plugin Enable support for External Public Key Authentication plug-in--enable-fuzz Build fuzzing. Not recommended for deployment.--enable-bundled-libtom Force using bundled libtomcrypt/libtommath even if a system version exists.--disable-bundled-libtom Force using system libtomcrypt/libtommath, fail if it does not exist.Default is to use system if available, otherwise bundled.Dropbear requires system libtommath >=1.2.0 and libtomcrypt >=1.18.0--disable-lastlog Disable use of lastlog even if detected no--disable-utmp Disable use of utmp even if detected no--disable-utmpx Disable use of utmpx even if detected no--disable-wtmp Disable use of wtmp even if detected no--disable-wtmpx Disable use of wtmpx even if detected no--disable-loginfunc Disable use oflogin() etc. no--disable-pututline Disable use ofpututline() etc.(uwtmp) no--disable-pututxline Disable use ofpututxline() etc.(uwtmpx) noOptional Packages:--with-PACKAGE[=ARG] use PACKAGE[ARG=yes]--without-PACKAGEdo not use PACKAGE(same as--with-PACKAGE=no)--with-zlib=PATH Use zlib inPATH--with-pam=PATH Use pam inPATH--with-lastlog=FILE|DIR specify lastlog location common locationsSome influential environment variables:CCC compiler commandCFLAGSC compiler flagsLDFLAGS linker flags, e.g.-L<lib dir>if you have libraries in anonstandard directory <lib dir>LIBS libraries to pass to the linker, e.g.-l<library>CPPFLAGS(Objective)C/C++ preprocessor flags, e.g.-I<include dir>ifyou have headers in a nonstandard directory <include dir>CPPC preprocessorCXXC++ compiler commandCXXFLAGSC++ compiler flagsUse 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.# 配置
# configure --prefix=安裝路徑 --host=arm CC=交叉編譯鏈gcc名稱 --with-zlib=zlib安裝路徑
# 安裝路徑最后使用絕對路徑
$ ./configure --prefix=/opt/dropbear/install --host=arm CC=arm-linux-gcc --with-zlib=/opt/zlib/install# 編譯
$ make
$ make scp
# 編譯出來的scp在dropbear的源碼目錄下,而非安裝--prefix=/opt/dropbear/install目錄下
$ make install# 注,編譯完成后可以使用arm-linux-strip工具去除調試信息, 對.so同樣適用, 這樣優化后能減小文件大小,對嵌入式系統很有用, 比如:
$ arm-linux-strip scp