此篇再說明如何建立一個 Cross-Compile 的 Linux x86 編譯環境,透過相對應 CPU 及作業系統的 toolchain,就可編譯適合嵌入系統的 Asterisk 套件。
重點項目如下:
cd /home/alang/ARM_Cross-Compile/build_start/ncurses-5.9/ CC=arm-none-linux-gnueabi-gcc \ CXX=arm-none-linux-gnueabi-g++ \ ./configure arm-linux --host=arm-none-linux-gnueabi --with-shared --without-ada --with-build-cc=gcc --with-build-cpp=arm-none-linux-gnueabi-g++ --enable-termcap --prefix=/home/alang/ARM_Cross-Compile/build_opt/ncurses_build_by_codesourcery make make install
NOTEs:如果要使用 IAX2 必須在編譯 Asterisk 啟用這兩個模組。
Channel Drivers > [*] chan_iax2
Resource Modules > [*] res_crypto
然而,模組 res_crypto 要啟用必須先編譯 openssl,詳細可參閱FAQ Install Asterisk 1.4/1.6/1.8 on Debian。
wget http://www.openssl.org/source/openssl-1.0.1.tar.gz ./Configure linux-generic32 --prefix=/home/alang/ARM_Cross-Compile/build_opt/openssl_build_by_codesourcery --openssldir=/home/alang/ARM_Cross-Compile/build_opt/openssl_build_by_codesourcery shared
TIPs:
Configure,C 是大寫。
參數要加上 shared,才能編譯成 shared libraries(*.so)。
編輯 Makefile
... CC= arm-none-linux-gnueabi-gcc AR= arm-none-linux-gnueabi-ar $(ARFLAGS) r RANLIB= arm-none-linux-gnueabi-ranlib ...
TIPs:
AR 指令後要加 $(ARFLAGS) r。
開始編譯
make make install
TIPs
在編譯 Asterisk 時要加上這兩個參數
--with-crypto=<openssl安裝目錄> --with-ssl=<openssl安裝目錄>
僅適用於 Asterisk 10.x
./configure CC=arm-none-linux-gnueabi-gcc CXX=arm-none-linux-gnueabi-g++ --host=arm-none-linux-gnueabi --prefix=/home/alang/ARM_Cross-Compile/build_opt/sqlite3_build_by_codesourcery make make install
for Asterisk 1.8.x
cd /home/alang/ARM_Cross-Compile/build_start/asterisk-1.8.10.1 ./configure \ CC=arm-none-linux-gnueabi-gcc \ AR=arm-none-linux-gnueabi-ar \ CXX=arm-none-linux-gnueabi-g++ \ CPPFLAGS="-I/home/alang/ARM_Cross-Compile/build_opt/ncurses_build_by_codesourcery/include/ncurses/" \ LDFLAGS="-L/home/alang/ARM_Cross-Compile/build_opt/ncurses_build_by_codesourcery/lib" \ RANLIB=arm-none-linux-gnueabi-ranlib \ --host=arm-none-linux-gnueabi --target=arm-none-linux-gnueabi --without-pwlib --without-curl --with-ncurses=/home/alang/ARM_Cross-Compile/build_opt/ncurses_build_by_codesourcery --disable-xmldoc make menuselect make make install DESTDIR=/home/alang/ARM_Cross-Compile/build_opt/asterisk18_arm make samples DESTDIR=/home/alang/ARM_Cross-Compile/build_opt/asterisk18_arm
for Asterisk 10.x
註:Asterisk 10 已經將內建的 AST DB 改成 SQLite3,所以必須先編譯 SQLite3。
cd /home/alang/ARM_Cross-Compile/build_start/asterisk-10.2.1 ./configure \ CC=arm-none-linux-gnueabi-gcc \ AR=arm-none-linux-gnueabi-ar \ CXX=arm-none-linux-gnueabi-g++ \ CPPFLAGS="-I/home/alang/ARM_Cross-Compile/build_opt/ncurses_build_by_codesourcery/include/ncurses/" \ LDFLAGS="-L/home/alang/ARM_Cross-Compile/build_opt/ncurses_build_by_codesourcery/lib" \ RANLIB=arm-none-linux-gnueabi-ranlib \ --host=arm-none-linux-gnueabi --target=arm-none-linux-gnueabi --without-pwlib --without-curl --with-ncurses=/home/alang/ARM_Cross-Compile/build_opt/ncurses_build_by_codesourcery --with-sqlite3=/home/alang/ARM_Cross-Compile/build_opt/sqlite3_build_by_codesourcery --disable-xmldoc make menuselect make make install DESTDIR=/home/alang/ARM_Cross-Compile/build_opt/asterisk10_arm_build_by_codesourcery make samples DESTDIR=/home/alang/ARM_Cross-Compile/build_opt/asterisk10_arm_build_by_codesourcery
TIPs
- CPPFLAGS 用法是 -I<非標準的 include 目錄>
- LDFLAGS 用法是 -L<非標準的 library 目錄>
- 不要使用 --prefix=非標準目錄,這會使編譯後的 Asterisk 在啟動時找不到設定檔 /etc/asterisk/asterisk.conf。
- DESTDIR 為 Asterisk 的安裝目錄。
Ans:移除 SDL 函式庫
sudo apt-get remove libsdl1.2-dev
checking for mandatory modules: NCURSES OPENSSL... fail
configure: ***
configure: *** The OPENSSL installation appears to be missing or broken.
Ans:
configure: error: *** termcap support not found (on modern systems, this typically means the ncurses development package is missing)
Ans:在 configure 時加上參數。
CPPFLAGS="-I<ncurses 安裝目錄>/include/ncurses"