리눅스

Apache cross compile

불량껌 2009. 2. 11. 17:06

예전에 S3C2410에 Apache 올렸던 것입니다.

< How to Apache Cross Compile >필자의 개발환경

OS : wowlinux 7.1

Kernel : 2.4.2

Machine : x.86Target 환경

OS : linux Kernel : 2.4.18

Machine : arm (S3C2410)

#1. Download apache file at www.apache.orgversion apache_1.3.33

#2. 압축 해제[root@wc02 utils]# tar xvfz apache_1.3.33.tar.gz

#3. 압축 해제한 디렉토리를 하나 복사해 둔다.

[root@wc02 utils]# cp apache_1.3.33 host_apache_1.3.33 -a

#4. 복사한 아파치 디렉토리로 가서 우선 Host PC용으로 컴파일 해둔다.

이유는 크로스 컴파일 도중에 필요한 파일들이 있기 때문이므로

gcc 컴파일러를 이용해 미리 컴파일 해 두는 것이다.

[root@wc02 utils]# cd host_apache_1.3.33/

[root@wc02 host_apache_1.3.33]# mkdir /usr/local/apache/

[root@wc02 host_apache_1.3.33]# ./configure --prefix=/usr/local/apache/

 

Configuring for Apache, Version 1.3.33 + using installation path layout: Apache (config.layout)Creating MakefileCreating Configuration.apaci in srcCreating Makefile in src + configured for Linux platform + setting C compiler to gcc + setting C pre-processor to gcc -E + using "tr [a-z] [A-Z]" to uppercase + checking for system header files + adding selected modules + using system Expat + checking sizeof various data types + doing sanity check on compiler and optionsCreating Makefile in src/supportCreating Makefile in src/regexCreating Makefile in src/os/unixCreating Makefile in src/apCreating Makefile in src/mainCreating Makefile in src/modules/standard[root@wc02 host_apache_1.3.33]#

[root@wc02 host_apache_1.3.33]# make

/*여기까지 작업이 끝났으면 크로스 컴파일 할 아파치 디렉토리로 이동한다. Host PC에서 실제 make install해 실행해 본 결과 웹서버로 잘 동작했다.*/

#5. 환경 변수 설정 및 configure 화일 수정

[root@wc02 src]# export CC=arm-linux-gcc

[root@wc02 src]# export CPP=arm-linux-gcc

[root@wc02 src]# export LD=arm-linux-ld

[root@wc02 src]# export STRIP=arm-linux-strip

[root@wc02 src]# export OBJCOPY=arm-linux-objcopy

[root@wc02 apache_1.3.33]# vi configure

#### determine platform id#### PLATFORM="`$aux/GuessOS`" <----------- 이 부분을 다음줄 처럼 수정한다.

PLATFORM=arm-whatever-riscix/*이부분을 수정하는 이유는 설치될 환경을 arm으로 고정시키기 위해서이다. 크로스 컴파일이므로 그냥 두면 i.*86계열로 host pc 환경이 저장된다. 만일 arm계열이 아는 다른 cpu를 사용한다면

(Root_dir)/src/helpers/GuessOS 파일의 내용을 살펴보기 바란다.

내용중 해당 cpu에 대한 항목이 있으면 그 부분을 복사해서 PLATFORM을 교체한다.

 

#6. 설치 위치 설정 및 환경 설정

[root@wc02 apache_1.3.33]# ./configure --prefix=/usr/local/apache

 

Configuring for Apache, Version 1.3.33 + using installation path layout: Apache (config.layout)Creating MakefileCreating Configuration.apaci in src./helpers/TestCompile: /home/hi78s/utils/apache_1.3.33/src/helpers/testfunc:cannot execute binary file./helpers/TestCompile: /home/hi78s/utils/apache_1.3.33/src/helpers/testfunc:cannot execute binary file./helpers/TestCompile: /home/hi78s/utils/apache_1.3.33/src/helpers/testfunc:cannot execute binary file./helpers/TestCompile: /home/hi78s/utils/apache_1.3.33/src/helpers/testfunc:cannot execute binary file./helpers/TestCompile: /home/hi78s/utils/apache_1.3.33/src/helpers/testfunc:cannot execute binary fileCreating Makefile in src + configured for Linux platform + setting C pre-processor to NOT-AVAILABLE + using "tr [a-z] [A-Z]" to uppercase + checking for system header files + adding selected modules + using builtin Expat + checking sizeof various data types + doing sanity check on compiler and optionsCreating Makefile in src/supportCreating Makefile in src/regexCreating Makefile in src/os/unixCreating Makefile in src/apCreating Makefile in src/mainCreating Makefile in src/lib/expat-liteCreating Makefile in src/modules/standard

[root@wc02 apache_1.3.33]# * 주의 : 실제 타겟 환경과 같은 경로상에 실행파일을 설치해야 한다..그리고 위와 같이 실행했을때 크로스 컴파일이라는 환경 때문에 에러가 발생한다.에러가 발생하는 이유는 환경에 필요한 파일을 생성중 컴파일러가 arm-linux-gcc이므로 이기때문에 x.86환경의 호스트 PC에서 파일을 읽지 못하기 때문이다.지금부터 문제를 하나씩 잡아 나간다.

 

#7. (Root_dir)/src/main 디렉토리로 이동한다.make를 두번 하게되면 아래와 같은 두개의 파일이 생성된다.

[root@wc02 main]# make/(Root_Dir)/src/main/gen_test_char

[root@wc02 main]# make/(Root_Dir)/src/main/gen_uri_delims 이 두개의 파일이 생성되면 #4번에서 Host PC용으로 make 해둔 곳으로 이동해이 두개의 파일을 현재 생성된 파일과 교체한다.

 

#8. Change compiled file at host pc/(Root_Dir)/src/main/gen_test_char/(Root_Dir)/src/main/gen_uri_delims

[root@wc02 main]# cp ../../../host_apache_1.3.33/src/main/gen_test_char ./

[root@wc02 main]# cp ../../../host_apache_1.3.33/src/main/gen_uri_delims ./

 

#9. make install/*source의 /(Root_dir)로 이동해 make install을 실행한다.*/

[root@wc02 apache_1.3.33]# make install

 

Install message ................................+--------------------------------------------------------+| You now have successfully built and installed the || Apache 1.3 HTTP server. To verify that Apache actually || works correctly you now should first check the || (initially created or preserved) configuration files || || /usr/local/apache/conf/httpd.conf| || and then you should be able to immediately fire up || Apache the first time by running: || || /usr/local/apache/bin/apachectl start| || Thanks for using Apache. The Apache Group || http://www.apache.org/ |+--------------------------------------------------------+#10. Install check정상적으로 인스톨 되었다고 위에서와 같은 메시지가 뜨면 /usr/local/apache/ 로 이동해 해당 디렉토리들이 있는지 확인한다..|-- bin|-- cgi-bin|-- conf|-- htdocs| `-- manual| |-- howto| |-- images| |-- misc| |-- mod| |-- programs| `-- vhosts|-- icons| `-- small|-- include| `-- xml|-- libexec|-- logs|-- man| |-- man1| `-- man8`-- proxy/* 주의 : apache/bin으로 이동해 file 명령으로 생성된 바이너리 파일이 arm용인지 확인한다. 나의 경우 no machine로 생성되어 있었다. */

[root@wc02 bin]# file httpdhttpd: ELF 32-bit LSB executable, no machine, version 1, dynamically linked(uses shared libs), stripped/* 파일을 복사하는 과정에서 제대로 되지 않은 것 같다. 이 부분을 교체해준다.

교체해주는 위치는 /(Root_Dir)/src/ 이다.

이 위치에 가보면 httpd 파일이 존재한다. file httpd 명령으로 확인해 본다.*/

[root@wc02 src]# file httpd

httpd: ELF 32-bit LSB executable, Advanced RISC Machines ARM, version 1,dynamically linked (uses shared libs), not stripped/*

Arm 환경에서 동작할수 있는 형태의 httpd 화일이 존재한다. /user/local/apache/bin 안의 httpd 화일과 교체한다.

*/[root@wc02 src]# cp httpd /usr/local/apache/bin/

cp: overwrite `/usr/local/apache/bin/httpd'? y

 

#11. Copy to Ramdisk, Make Ramdisk Image이제 모든 작업이 끝났다. /usr/local/apache 디렉토리를 ramdisk 이미지 아래 같은 위치에 복사만 해주면 된다. ^^ 그전에 /htdocs/manual 디렉토리는 메뉴얼 페이지 인데 파일 용량(4.8Mbyte)이 너무 많으므로 삭제해준다. 여기까지 하면2.4Mbyte의 아파치 크로스 컴파일이 완료된 것이다. 이제부터는 필요없는 모듈들을 제외 시키면서 최소의 아파치 실행환경을 만든다. ARM 기반의 보드라면다른 환경에서도 잘 동작하리라 예상된다. ㅡㅡ;;/* ./htdocs의 메뉴얼 페이지를 삭제한 경우에 설치 크기이다.

필요없는 라이브러리와 모듈들을 삭제하면 더 줄일 수 있을 것이다.*/

[root@wc02 apache]# du -h889k

./bin

21k

./man/man

141k

./man/man

862k

./man

153k

./conf

512

./logs

262k

./icons/small

899k

./icons

512

./proxy

512

./libexec

8.5k

./htdocs

73k

./include/xml

370k

./include

8.5k

./cgi-bin

2.4M .

# 12. 설치후 아파치 설버 실행 법conf 디렉토리에 있는 httpd.conf 에서 다음 항목들을 찾아 아래와 같이 변경한다.

Port 80User nobodyGroup nobodyServerName 211.238.159.112ServerName는 현재 보드의 IP를 입력해 주면된다.그리고 bin 디렉토리의 ./apachectl start 라고 하면 아파치가 시작된다.이 방법 말고도 ./httpd start 하면 아파치가 동작된다.아파치 데몬을 구동 중지 시키려면 ./apachectl stop 하면 된다.