| Neelakanth Nadgir |
|
소개
소프트웨어는 일반적으로 여러 플랫폼상에서 사용되도록 개발됩니다. 이들 플랫폼들은 각기 다른 언어로 작성된 파일을 처리하는 이기종 컴파일러를 보유하고 있기 때문에 다양한 플랫폼에서 실행되도록 하기 위해서는 Makefiles와 스크립트를 작성해야 합니다. 이러한 문제에 직면한 무료 소프트웨어 커뮤니티(Project GNU)는 Makefiles를 생성하고 다양한 플랫폼상에서 실행되는 스크립트를 작성하기 위한 일련의 툴을 개발했습니다. 소스에서 GNU 소프트웨어를 다운로드하여 구축했다면 configure 스크립트를 보다 친숙하게 다룰 수 있을 것입니다. configure 스크립트는 일련의 테스트를 통해 사용 중인 시스템에 대한 정보를 파악합니다. 다음은 configure 결과 샘플입니다.
foo@pastwatch: ...neel/projects/gpstat> ./configure loading cache ./config.cache checking whether to enable debugging... yes checking host system type... sparc-sun-solaris2.8 checking target system type... sparc-sun-solaris2.8 checking build system type... sparc-sun-solaris2.8 =========================================================== Setting up build environment for sparc solaris2.8 =========================================================== checking whether build environment is sane... yes
Project GNU는 이식 가능한 Makefiles의 생성을 단순화하는 automake와 스크립트를 구성하는 autoconf의 2가지 프로그램을 제공합니다. automake는 Makefile.am에서 자동으로 이식 가능한 makefile 템플릿을 생성하는 프로그램입니다. Makefile.am과 automake는 아래에서 더 자세히 설명합니다. autoconf는 configure.in에서 구성 파일을 생성하는 툴이며, 구성 스크립트를 생성하는 데 유용한 autoconf, aclocal 및 autoscan이 포함된 일련의 유틸리티 스크립트를 제공합니다.
GNU 구축 툴 - 단계별 진행
GNU 구축 툴 사용 시의 과정은 다음과 같습니다.makefile.am템플릿 작성.configure.in. 작성
- 2.1 autoscan을 사용해 템플릿 생성
- 2.2 생성된
configure.scan을 해당 프로젝트에 맞게 조정 - 2.3
configure.scan의 이름을configure.in으로 수정
automake를 실행해Makefile.am에서Makefile.in생성(automake가configure.in을 검사해 프로젝트에 대한 자세한 정보 확인)aclocal을 실행해 모든autoconf매크로의 로컬 사본 생성. 이 매크로들이 프로젝트에 포함됩니다.autoconf를 실행해 구성 생성
automake
automake는 autoconf와 함께 사용될 때 더욱 쉽게 Makefiles를 생성할 수 있습니다. automake가 Makefile.am에서 실행되어 Makefile.in을 생성하면 Makefile.in이 Makefile을 생성하는 configure 스크립트에 의해 처리됩니다. Makefile.am에는 automake에 의해 처리되는 매크로가 포함됩니다. 샘플 Makefile.am은 아래와 같습니다. @으로 둘러 쌓인 변수들은 Makefile.in에 아무런 변경 없이 자동으로 전파됩니다. Makefile.in을 Makefile로 파싱할 때 configure 스크립트는 필요한 구성 요소를 만듭니다(예를 들어, @LDFLAGS@는 "-lm -Ithread로 확장됨):
bin_PROGRAMS = gpstat
gpstat_SOURCES = about.c interface.c multi-plot.c attach_process.c
gpstat_LDFLAGS = @LDFLAGS@ @GTK_LIBS@ -lgthread
INCLUDES = @GTK_CFLAGS@
automake는 객체 파일과 객체 파일이 실행되는 플랫폼의 실행 파일의 생성 규칙을 알고 있습니다. 위의 매크로 세트는 automake가 다음을 수행하도록 합니다.
- 최종 실행 파일의 이름을
gpstat으로 지정 gpstatt의 소스 값을gpstat_SOURCES으로 지정- 링크 행에 @LDFLAGS@, @GTK_LIBS@ 및 -lgthread 추가 (
configure스크립트가LD_FLAGS와GTK_LIBS를 적당한 값으로 교체) - 컴파일 행에 변수
$INCLUDES포함
autoconf
configure 스크립트는 autoconf를 사용하여 configure.in에서 생성됩니다. configure.in은 여러 autoconf 매크로를 포함하는 일반적인 텍스트 파일입니다. 이러한 매크로는 수행될 테스트를 지정합니다. 일반적인 configure 스크립트의 사용은 다음과 같습니다.
- 시스템 정보(호스트 이름, 버전...) 찾기
- 특정 프로그램(bison, lex, ..)으로의 경로 찾기
- 툴이 기능을 지원하는지 여부 확인(예를 들어 컴파일러가 bool을 지원하는지 여부)
- 필요한 라이브러리가 해당 시스템에서 사용가능한지 여부 확인
Makefile.in을 처리해Makefile생성
주석은 dnl 또는 a #로 시작합니다. 다음은 제대로 문서화된 자기 설명적인 소형 configure.in 파일입니다.
#============================start configure.in============================
dnl Process this file with autoconf to produce a configure script.
dnl notice how comments are preceded by "dnl"
# comments can also begin with a #
dnl This macro is a must, and this tests if the configure
dnl script is running in the correct directory
AC_INIT(src/about.c)
dnl This macro tells the configure script to put
dnl "defines" in a file rather than the command line.
AM_CONFIG_HEADER(config.h)
dnl get the flags
CFLAGS="${CFLAGS=}"
dnl this macro is used to get the arguments supplied
dnl to the configure script (./configure --enable-debug)
dnl Check if we have enable debug support.
AC_MSG_CHECKING(whether to enable debugging)
debug_default="yes"
AC_ARG_ENABLE(debug, [ --enable-debug=[no/yes] turn on debugging
[default=$debug_default]],, enable_debug=$debug_default)
dnl Yes, shell scripts can be used
if test "x$enable_debug" = "xyes"; then
CFLAGS="$CFLAGS -g -DDEBUG"
AC_MSG_RESULT(yes)
else
CFLAGS="$CFLAGS -O3 -ffast-math -mcpu=v8 -mtune=ultrasparc"
AC_MSG_RESULT(no)
fi
dnl tells us that we require autoconf with version greater than
dnl 2.12 to generate configure
AC_PREREQ(2.12)
dnl get system information
AC_CANONICAL_SYSTEM
dnl Since foo is currently untested on any os other
dnl than solaris, so check the os and quit if not solaris.
UNSUPPORTED_OS="FOO is currently unsupported on your platform.
If you are interested in making it work on your platform, you are
more than *welcome*. Contact foo@bar.sun.com for details."
case "${target_os}" in
solaris*)
echo ===========================================================
echo Setting up build environment for ${target_cpu}${target_os}
echo ===========================================================
;;
*)
AC_MSG_ERROR($UNSUPPORTED_OS)
esac
# Build time sanity check...
AM_SANITY_CHECK
dnl get path to install program
AC_PROG_INSTALL
AC_ARG_PROGRAM
VERSION=0.1
PACKAGE=foo
dnl initialize automake
AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
dnl Checks for c compiler.
AC_PROG_CC
dnl check for standard c headers
AC_HEADER_STDC
dnl export these variable (so Makefile substitutions
dnl can be made.
AC_SUBST(CFLAGS)
AC_SUBST(LDFLAGS)
dnl Checks for libraries.
dnl AC_CHECK_LIB(gthread, g_thread_init)
dnl AC_CHECK_LIB(pthread, pthread_create)
dnl Check for /proc
AC_CHECK_FILE(/proc,,AC_MSG_ERROR(Cannot
find /proc. See the file 'README' for help.))
dnl check for procfs.h
AC_CHECK_HEADER(procfs.h,,
AC_MSG_ERROR(Cannot
find procfs.h. See the file 'README' for help.))
dnl Checks for header files.
AC_CHECK_HEADERS(fcntl.h)
AC_CHECK_HEADERS(time.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_PID_T
dnl Create these files, making substitutions if necessary
AC_OUTPUT([
src/Makefile
Makefile
]
)
#============================end configure.in============================
automake는 또한 configure.in 템플릿을 생성하는 데 유용한 유틸리티 스크립트인 autoscan을 제공합니다. autoscan은 프로그램 소스를 검사하여 configure.in에 적합한 매크로를 추가합니다. 이 매크로에서 configure.scan을 생성하고, configure.scan은 적합한 수정을 거친 후 configure.in으로 이름이 수정됩니다.
automake는 aclocal이라는 프로그램도 제공합니다. aclocal은 다른 개발자들이 configure.in 파일을 수정할 수 있도록 모든 autoconf 매크로의 로컬 사본을 만듭니다
다음과 같이 automake, aclocal 및 autoconf를 결합하여 호출할 수 있습니다:
foo@pastwatch$ aclocal&& automake && autoconf
결론
automake와 autoconf는 다양한 플랫폼에서 프로젝트를 보다 쉽게 구축할 수 있도록 하는 강력한 툴입니다. Makefile.am과 configure.in 파일만 있으면 이러한 툴을 작성할 수 있습니다. 이러한 툴을 사용하면 여러 플랫폼에서 이식 가능한 프로젝트를 만들 수 있습니다. 이들은 구성 기능이 뛰어나며, 여러 사전 정의된 매크로들이 이미 제공되고 있습니다. 프로젝트를 다양한 플랫폼에서 사용할 수 있도록 만들 계획이라면, automake와 autoconf의 사용을 고려해 보는 것이 좋습니다.
유용한 자료들
"솔라리스" 카테고리의 다른 글
- 드라이버 개발자들을 위한 DTrace 이용 사례 분석 (댓글 1개 / 트랙백 0개) 2006/05/25
- DTrace FAQ (댓글 1개 / 트랙백 0개) 2005/05/25
- 존과 Crossbow (댓글 0개 / 트랙백 0개) 2009/08/27
- CPU 와 코어 매핑하기 (댓글 0개 / 트랙백 0개) 2009/08/27
- 솔라리스 10을 말한다 (댓글 1개 / 트랙백 2개) 2005/05/25
- CD가 필요 없는 Solaris 인스톨 방법 (댓글 1개 / 트랙백 0개) 2006/07/23
- 코드 레이아웃을 변경하여 어플리케이션의 퍼포먼스를 향상시키는 방법 (댓글 2개 / 트랙백 0개) 2006/07/23
- DTrace를 이용한 C++ 프로그램 프로파일링과 디버깅 (댓글 1개 / 트랙백 0개) 2005/05/25
- 솔라리스의 NFS 기본 소개 (댓글 0개 / 트랙백 0개) 2009/08/27
- GNU 구축툴 소개 (댓글 1개 / 트랙백 0개) 2006/06/23
댓글을 달아 주세요
좋은 정보 감사해요~
2007/09/19 04:23