2011年1月28日 星期五

Cross Compile Lighttpd + PHP + MySQL for ARM (1)

目標是要在ARM platform上跑HTTP Server並且支援PHP & MySQL.
HTTP server選擇lighttpd.整個cross comiple流程大致是先build MySQL,
因為PHP需要連結MySQL,再來是bulid PHP 最後才是lighttpd.
ARM cross compile 是 CodeSourcery 2008q1版本.

首先了解一下cross compile搜尋路徑
$ arm-none-linux-gnueabi-gcc -print-search-dirs
install: /opt/arm-2008q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.2.3/
programs: =/opt/arm-2008q1/bin/../libexec/gcc/arm-none-linux-gnueabi/4.2.3/:/opt/arm-2008q1/bin/../libexec/gcc/:/opt/arm-2008q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.2.3/../../../../arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi/4.2.3/:/opt/arm-2008q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.2.3/../../../../arm-none-linux-gnueabi/bin/
libraries: =/opt/arm-2008q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.2.3/:/opt/arm-2008q1/bin/../lib/gcc/:/opt/arm-2008q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.2.3/../../../../arm-none-linux-gnueabi/lib/arm-none-linux-gnueabi/4.2.3/:/opt/arm-2008q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.2.3/../../../../arm-none-linux-gnueabi/lib/:/opt/arm-2008q1/bin/../arm-none-linux-gnueabi/libc/lib/arm-none-linux-gnueabi/4.2.3/:/opt/arm-2008q1/bin/../arm-none-linux-gnueabi/libc/lib/:/opt/arm-2008q1/bin/../arm-none-linux-gnueabi/libc/usr/lib/arm-none-linux-gnueabi/4.2.3/:/opt/arm-2008q1/bin/../arm-none-linux-gnueabi/libc/usr/lib/

由以上libraries搜尋路徑偶選擇 /opt/arm-2008q1/arm-none-linux-gnueabi/libc/usr 作為相關所需libraries的安裝位置

1.Download & cross compile pcre-8.12 & ncurses-5.7

$ cd pcre-8.12/

$ CC=arm-none-linux-gnueabi-gcc AR=arm-none-linux-gnueabi-ar CXX=arm-none-linux-gnueabi-g++ ./configure --host=arm-linux --target=arm-linux --prefix=/opt/arm-2008q1/arm-none-linux-gnueabi/libc/usr --cache-file=/dev/null
$ make
$ sudo PATH=$PATH:/opt/arm-2008q1/bin make install

$ cd ../ncurses-5.7

$ CC=arm-none-linux-gnueabi-gcc AR=arm-none-linux-gnueabi-ar CXX=arm-none-linux-gnueabi-g++ ./configure --host=arm-linux --target=arm-linux --prefix=/opt/arm-2008q1/arm-none-linux-gnueabi/libc/usr --cache-file=/dev/null

$ make
$ sudo PATH=$PATH:/opt/arm-2008q1/bin make install

在make install 時加上PATH=$PATH:/opt/arm-2008q1/bin是為了在root權限下也能執行cross compiler.

2.Cross compile mysql-5.5.8

MySQL在5.5之後不在使用autoconf系統而採cmake.

建立 toolchain.cmake 內容如下

# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)

# specify the cross compiler
SET(CMAKE_C_COMPILER   /opt/arm-2008q1/bin/arm-none-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER /opt/arm-2008q1/bin/arm-none-linux-gnueabi-g++)
SET(CMAKE_STRIP           /opt/arm-2008q1/bin/arm-none-linux-gnueabi-strip)

# where is the target environment
SET(CMAKE_FIND_ROOT_PATH  /opt/arm-2008q1/arm-none-linux-gnueabi/libc)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

接著執行cmake

$ cmake -DCMAKE_TOOLCHAIN_FILE=./toolchain.cmake -DMYSQL_DATADIR=/var/lib/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_USER=mysql -DCMAKE_INSTALL_PREFIX=/home/gigijoe/BeagleBoard/rootfs/usr/local/mysql -DWITH_EMBEDDED_SERVER=1 -DCMAKE_C_COMPILER=arm-none-linux-gnueabi-gcc -DCMAKE_CXX_COMPILER=arm-none-linux-gnueabi-g++ -DSTACK_DIRECTION=1

$ make VERBOSE=1

出現錯誤

[  2%] Building C object cmd-line-utils/libedit/CMakeFiles/edit.dir/term.c.o
cd /home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit && /opt/arm-2008q1/bin/arm-none-linux-gnueabi-gcc  -DHAVE_CONFIG_H -Wall -O2 -g -DDBUG_OFF -I/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit -I/home/gigijoe/BeagleBoard/mysql-5.5.8/include   -o CMakeFiles/edit.dir/term.c.o   -c /home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c
/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c:59:20: error: curses.h: No such file or directory
/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c: In function 'term_set':
/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c:928: warning: implicit declaration of function 'tgetent'
/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c:946: warning: implicit declaration of function 'tgetflag'
/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c:955: warning: implicit declaration of function 'tgetnum'
/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c:959: warning: implicit declaration of function 'tgetstr'
/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c:960: warning: passing argument 3 of 'term_alloc' makes pointer from integer without a cast
/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c: In function 'term_tputs':
/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c:1261: warning: implicit declaration of function 'tputs'
/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c: In function 'term_echotc':
/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c:1560: warning: assignment makes pointer from integer without a cast
make[2]: *** [cmd-line-utils/libedit/CMakeFiles/edit.dir/term.c.o] Error 1
make[2]: Leaving directory `/home/gigijoe/BeagleBoard/mysql-5.5.8'
make[1]: *** [cmd-line-utils/libedit/CMakeFiles/edit.dir/all] Error 2
make[1]: Leaving directory `/home/gigijoe/BeagleBoard/mysql-5.5.8'
make: *** [all] Error 2

修改 /home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit/term.c

#ifdef HAVE_CURSES_H
-#include
+#include
#endif
#ifdef HAVE_NCURSES_H
-#include
+#include
#endif
/* Don't use Solaris's term.h. */
#if (defined(HAVE_TERM_H) && !defined(__SunOS))
-#include
+#include
#endif

再次嘗試

$ make VERBOSE=1

出現錯誤

[ 28%] Generating ../include/mysqld_error.h, ../sql/share/english/errmsg.sys
cd /home/gigijoe/BeagleBoard/mysql-5.5.8/extra && ./comp_err --charset=/home/gigijoe/BeagleBoard/mysql-5.5.8/sql/share/charsets --out-dir=/home/gigijoe/BeagleBoard/mysql-5.5.8/sql/share/ --header_file=/home/gigijoe/BeagleBoard/mysql-5.5.8/include/mysqld_error.h --name_file=/home/gigijoe/BeagleBoard/mysql-5.5.8/include/mysqld_ername.h --state_file=/home/gigijoe/BeagleBoard/mysql-5.5.8/include/sql_state.h --in_file=/home/gigijoe/BeagleBoard/mysql-5.5.8/sql/share/errmsg-utf8.txt
./comp_err: 1: Syntax error: word unexpected (expecting ")")
make[2]: *** [include/mysqld_error.h] Error 2
make[2]: Leaving directory `/home/gigijoe/BeagleBoard/mysql-5.5.8'
make[1]: *** [extra/CMakeFiles/GenError.dir/all] Error 2
make[1]: Leaving directory `/home/gigijoe/BeagleBoard/mysql-5.5.8'
make: *** [all] Error 2

有個comp_err無法執行,先找出它在哪

$ find ./ -name "comp_err" -print
./extra/comp_err

看一下屬性

$ file ./extra/comp_err
./extra/comp_err: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped

嗯,看來需要先在host side compile mysql.

3.Compile mysql-5.5.8 for host

$ cmake -DMYSQL_DATADIR=/var/lib/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_USER=mysql -DWITH_EMBEDDED_SERVER=1 -DSTACK_DIRECTION=1

$ make VERBOSE=1

4.Continue cross compile mysql-5.5.8

以host版本comp_err覆蓋

$ cp ../../mysql-5.5.8/extra/comp_err extra/

$ make VERBOSE=1

出現錯誤

[ 75%] Building CXX object client/CMakeFiles/mysql.dir/sql_string.cc.o
cd /home/gigijoe/BeagleBoard/mysql-5.5.8/client && /opt/arm-2008q1/bin/arm-none-linux-gnueabi-g++   -DHAVE_CONFIG_H -DHAVE_DLOPEN -Wall -Wno-unused-parameter -fno-implicit-templates -fno-exceptions -fno-rtti -O2 -g -DDBUG_OFF -I/home/gigijoe/BeagleBoard/mysql-5.5.8/include -I/home/gigijoe/BeagleBoard/mysql-5.5.8/libmysql -I/home/gigijoe/BeagleBoard/mysql-5.5.8/regex -I/home/gigijoe/BeagleBoard/mysql-5.5.8/sql -I/home/gigijoe/BeagleBoard/mysql-5.5.8/strings -I/home/gigijoe/BeagleBoard/mysql-5.5.8/cmd-line-utils/libedit -I/home/gigijoe/BeagleBoard/mysql-5.5.8/client   -o CMakeFiles/mysql.dir/sql_string.cc.o -c /home/gigijoe/BeagleBoard/mysql-5.5.8/client/sql_string.cc
Linking CXX executable mysql
cd /home/gigijoe/BeagleBoard/mysql-5.5.8/client && /usr/bin/cmake -E cmake_link_script CMakeFiles/mysql.dir/link.txt --verbose=1
/opt/arm-2008q1/bin/arm-none-linux-gnueabi-g++    -Wall -Wno-unused-parameter -fno-implicit-templates -fno-exceptions -fno-rtti -O2 -g -DDBUG_OFF   CMakeFiles/mysql.dir/completion_hash.cc.o CMakeFiles/mysql.dir/mysql.cc.o CMakeFiles/mysql.dir/readline.cc.o CMakeFiles/mysql.dir/sql_string.cc.o  -o mysql  -lpthread ../libmysql/libmysqlclient.a ../cmd-line-utils/libedit/libedit.a -lz -lm -lrt -ldl -lpthread -lcurses
/opt/arm-2008q1/bin/../lib/gcc/arm-none-linux-gnueabi/4.2.3/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -lcurses
collect2: ld returned 1 exit status
make[2]: *** [client/mysql] Error 1
make[2]: Leaving directory `/home/gigijoe/BeagleBoard/mysql-5.5.8'
make[1]: *** [client/CMakeFiles/mysql.dir/all] Error 2
make[1]: Leaving directory `/home/gigijoe/BeagleBoard/mysql-5.5.8'
make: *** [all] Error 2

用以下方式修正

編輯
/home/gigijoe/BeagleBoard/mysql-5.5.8/client/CMakeFiles/mysql.dir/link.txt

/home/gigijoe/BeagleBoard/mysql-5.5.8/libmysqld/examples/CMakeFiles/mysql_embedded.dir/link.txt

將 -lcurses 成 -lncurses

$ make VERBOSE=1

出現錯誤

[ 76%] Generating mysql_fix_privilege_tables_sql.c
cd /home/gigijoe/BeagleBoard/mysql-5.5.8/scripts && /usr/bin/cmake -E chdir /home/gigijoe/BeagleBoard/mysql-5.5.8/scripts /bin/cat mysql_system_tables.sql mysql_system_tables_fix.sql > /home/gigijoe/BeagleBoard/mysql-5.5.8/scripts/mysql_fix_privilege_tables.sql
cd /home/gigijoe/BeagleBoard/mysql-5.5.8/scripts && /home/gigijoe/BeagleBoard/mysql-5.5.8/scripts/comp_sql mysql_fix_privilege_tables mysql_fix_privilege_tables.sql mysql_fix_privilege_tables_sql.c
/home/gigijoe/BeagleBoard/mysql-5.5.8/scripts/comp_sql: 1: Syntax error: word unexpected (expecting ")")
make[2]: *** [scripts/mysql_fix_privilege_tables_sql.c] Error 2
make[2]: Leaving directory `/home/gigijoe/BeagleBoard/mysql-5.5.8'
make[1]: *** [scripts/CMakeFiles/GenFixPrivs.dir/all] Error 2
make[1]: Leaving directory `/home/gigijoe/BeagleBoard/mysql-5.5.8'
make: *** [all] Error 2

以host版本comp_sql覆蓋

$ cp ../../mysql-5.5.8/scripts/comp_sql scripts/

$ make VERBOSE=1

出現錯誤

[ 78%] Generating lex_hash.h
cd /home/gigijoe/BeagleBoard/mysql-5.5.8/sql && ./gen_lex_hash > lex_hash.h
./gen_lex_hash: 1: Syntax error: word unexpected (expecting ")")
make[2]: *** [sql/lex_hash.h] Error 2
make[2]: Leaving directory `/home/gigijoe/BeagleBoard/mysql-5.5.8'
make[1]: *** [sql/CMakeFiles/GenServerSource.dir/all] Error 2
make[1]: Leaving directory `/home/gigijoe/BeagleBoard/mysql-5.5.8'
make: *** [all] Error 2

以host版本gen_lex_hash覆蓋

cp ../../mysql-5.5.8/sql/gen_lex_hash sql/

$ make VERBOSE=1

$ make install




3 則留言:

  1. 你好,我想請問一下,這個適用於Android 系統嗎?
    如果我編譯完之後,編譯完檔案式直接放置到Android 底下的哪個路徑?

    回覆刪除