자동화된 빌드 시스템 구축 (2) 본문

Programming

자동화된 빌드 시스템 구축 (2)

halatha 2009. 9. 21. 16:10
출처: 열씨미와 게을러의 리눅스 개발 노하우 탐험기
2009/08/17 - [Programming] - diff, find, md5sum, patch
2009/08/17 - [Programming] - find, grep, ctags, cscope, global
2009/08/17 - [Programming] - shared library, strace, ldconfig, ldd, gcc, strings, od, nm, c++filt, readelf
2009/09/14 - [Programming] - configure
2009/09/21 - [Programming] - 자동화된 빌드 시스템 구축

Big endian & Little endian
function을 통한 endian 점검

macro를 통한 endian 점검
macro를 통해 사용자가 지정한 C program을 configure 도중 compile해 실행한 다음 결과를 확인
AC_C_ENDIAN라는 macro를 function으로 선언한 후 AC_RUN_IFELSE 내부에서 호출해 결과를 보고 endian을 결정
AC_LANG_PROGRAM macro: AC_LANG macro로 설정된(여기서는 기본 programming language인 C를 사용했으므로 특별히 AC_LANG macro를 부를 필요가 없다) programming language로 compile
AC_RUN_IFELSE macro: program이 compile과 link를 성공리에 마치고 shell variable인 $? 결과에 0을 반환하면 앞의 행위(여기서는 ac_cv_c_endian=big)를, 0이 아닌 값을 반환하면 뒤의 행위(여기서는 ac_cv_c_endian=little)를 shell command로 수행. 앞의 is_little_endian() function과 달리 big endian인 경우 shell의 입장에서 true(0)을 반환한다는 것을 주의해야 한다
program 수행 결과값을 비교하기 위해 shell command인 if test; then fi 구문을 사용해 최종적으로 AC_DEFINE으로 ENDIAN_BIG, ENDIAN_LITTLE을 정의한다. AC_DEFUN macro는 function을 정의하는 macro이며, function 선언이 끝났다면 본문 중에서 자유롭게 사용할 수 있다

Makefile.am

aclocal
autoheader
autoconf
./configure

Shared library
pwd & hello.c
configure.in

 macro name
name
비고
AC_CONFIG_AUX_DIR
libtool이 사용하는 각종 file을 생성하는 directory 위치 지정
여기서는 .. 지정
AC_PROG_LIBTOOL
libtool을 사용해서 shared library build와 link 지정
 

Makefile.am
library name이 libhello.a나 libhello.so가 아니라 libhello.la - .la는 libtool에서 사용하는 전용 library extension

--foreign: GNU project가 아닌 경우 더 느슨한 build 환경을 구축하는 option
--add-missing option으로는 ltmain.sh을 제대로 추가하지 못하는 문제점이 있음 -> libtoolize라는 libtool 전용 utility를 사용해 libtool이 요구하는 file 전부를 추가할 수 있음 -> test를 위해 --dry-run option을 붙여서 실행 후 잘 되면 이 option을 제외해서 진짜로 필요한 file을 추가하면 됨

libtoolize
--automake option: libtool과 automake를 연동
--copy, --force option: symbolic link를 만드는 대신 file을 copy하라는 의미

automake
automake에 --add-missing option을 넣어 빠진 file을 추가

./configure

make
실제 shared library는 .libs에 생성: 개발자나 사용자나 shared library extension과 location을 몰라도 program을 compile하고 수행하도록 하는 libtool의 방법

test program 작성
configure.in & Makefile.am
configure.in의 AC_CONFIG_AUX_DIR을 (.)로 지정한 이유는 libtool에서 필요한 각종 file들을 공유하기 위해서
Makefile.am에 libhello.la라는 libtool화된 library name을 지정하면 libtool이 알아서 link

sources
libtoolize는 실행할 필요 없음: 아까 library 환경 설정하면서 필요한 file들을 미리 복사했기 때문

./configure
LD_LIBRARY_PATH 경로를 설정할 필요는 없음 -> foobar를 file command로 확인해보면 shell script -> 진짜 foobar는 .libs에 있음 -> 현재 shared library path를 지정하지 않아 ldd command로 확인하면 libhello.so가 없다고 출력됨 -> shell script foobar는 shared library path를 내부적으로 지정한 다음 binary file foobar를 실행

결론
1. configure script 내부에서 각종 programming language로 만든 program을 실행하는 방법으로 test 진행 가능
2. 복잡한 shared library를 다양한 OS에서 compile하기 위해 libtool을 사용

참고
HAVE_SOCKELN_T: http://lists.ximian.com/pipemail/mono-devel-list/2003-November/002823.html
endian과 AC_C_SOCKLEN_T: http://code.sixapart.com/svn/memcached/trunk/server/configure.ac
Comments