출처 : GCC 완전정복 (에이콘. Kurt Wall, William von Hagen 지음. 김경현 옮김. 3만원 짜리책)

root@realg-desktop:~/test_CODE/C/struct_point# l
합계 24
drwxr-xr-x 2 realg realg 4096 2009-04-21 19:24 .
drwxr-xr-x 9 realg realg 4096 2009-04-08 16:40 ..
-rwxr-xr-x 1 realg realg 9146 2009-03-30 19:35 a.out
-rw-r--r-- 1 realg realg  373 2009-03-30 19:35 struct_point.c

autoscan 을 실행한다.

root@realg-desktop:~/test_CODE/C/struct_point# autoscan
root@realg-desktop:~/test_CODE/C/struct_point# l
합계 16
drwxr-xr-x 2 realg realg 4096 2009-04-21 19:24 .
drwxr-xr-x 9 realg realg 4096 2009-04-08 16:40 ..
-rw-r--r-- 1 root  root     0 2009-04-21 19:24 autoscan.log
-rw-r--r-- 1 root  root   534 2009-04-21 19:24 configure.scan
-rw-r--r-- 1 realg realg  373 2009-03-30 19:35 struct_point.c

configure.scan 과 autoscan.log 파일이 생겼다.

root@realg-desktop:~/test_CODE/C/struct_point# cat configure.scan
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.61)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([struct_point.c])
AC_CONFIG_HEADER([config.h]) 삭제

# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([string.h])
AC_CONFIG_FILES([Makefile]) 추가

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
AC_CHECK_FUNCS([memset])

AC_OUTPUT
root@realg-desktop:~/test_CODE/C/struct_point#

configure.scan 의 내용이다.

AC_PREREQ : autoconf 버전 2.61패키지를 이용해서 이 autoconf 파일을 만들었다.
AC_INIT : 기본 autoconf 초기화 매크로 이다. autoconf를 이용해서 설정한 응용프로그램 패키지에 대해 사용자가 정의한 이름, 현재 설정된 패키지의 버전, 프로그램의 버그를 보고할 e-mail주소, 이렇게 세개의 인자가 필요하다.
AC_CONFIG_SRCDIR : 설정과 컴파일을 하기 위해서 소스 디렉토리에 있어야 하는 소스 파일의 이름을 인자로 하는 매크로이다. 원래 이 매크로는 autoconf가 제대로 동작하는가를 확인하기 위한 목적이다. 일반적으로 이 값은 설정하는 프로그램의 main루틴을 가지고 있는 파일의 이름이다.
AC_CONFIG_HEADER : 크로스 플랫폼이나 여러 플랫폼에 대한 설정 정보를 담고 있는 헤더 파일을 사용하고자 할 때 그것을 지정해주는 매크로이다. 이 설정 헤더 파일의 기본 이름은 config.h이다. 응용프로그램이 플랫폼의 특정 기능에 의존적이지 않다면, 이 항목을 지워도 된다. 이 기능을 사용하고자 할 때 지나치지 않게 하기 위해서 autoscan 스크립트가 이 값을 기본적으로 넣는다.
AC_PROG_CC : C컴파일러가 있는지 확인하는 매크로이다.
AC_HEADER_STDC : stdlib.h, stdarg.h string.h, float.h 헤더파일을 확인해서 ANSI C 헤더 파일이 있는지 확인하는 매크로이다.
AC_CHECK_HEADERS : stdio.h를 제외한 C 언어의 특정 헤더 파일이 있는지 확인하는 매크로이다.
AC_CONFIG_FILES autoconf가 템플릿 파일을 이용해서 지정된 파일을 만들도록 하는 매크로이다. autoconf 설정 파일에 있는 다른 매크로 구문에 기반해서 최대한 변수 치환을 수행한다. 기본적으로 템플릿 파일은 지정된 파일과 같은 이름(확장다는 .in이다.)을 갖는다. 생성할 파일의 이름을 콜론으로 구분해서 다른 템플릿 파일을 지정할 수 있다. 예를 들어 Makefile:foo.in은 foo.in템플릿 파일을 이용해서 Makefile파일을 생성하라는 것을 지정한다.
AC_OUTPUT : autoconf 프로그램이 config.status 셸 스크립트를 만들어서 그것을 실행하도록 하는 매크로이다. 보통 autoconf 설정 파일의 맨 마지막 매크로이다.


autoscan을 이용하여 템플릿 파일을 만들었다면, 이 파일을 autoconf의 기본 설정 파일인 configure.ac로 복사하거나 이름을 변경해야 한다.

root@realg-desktop:~/test_CODE/C/struct_point# l
합계 16
drwxr-xr-x 2 realg realg 4096 2009-04-21 19:24 .
drwxr-xr-x 9 realg realg 4096 2009-04-08 16:40 ..
-rw-r--r-- 1 root  root     0 2009-04-21 19:24 autoscan.log
-rw-r--r-- 1 root  root   534 2009-04-21 19:24 configure.scan
-rw-r--r-- 1 realg realg  373 2009-03-30 19:35 struct_point.c


root@realg-desktop:~/test_CODE/C/struct_point# mv configure.scan configure.ac
root@realg-desktop:~/test_CODE/C/struct_point# ls
autoscan.log  configure.ac  struct_point.c


root@realg-desktop:~/test_CODE/C/struct_point# autoconf
root@realg-desktop:~/test_CODE/C/struct_point# ls
autom4te.cache  autoscan.log  configure  configure.ac  struct_point.c

이렇게 하면 configure 스크립트와 autom4te.cache 라는 이름의 디렉토리가 만들어진다. 이 디렉토리에는 프로그램에 대한 캐시된 정보가 들어 있는데, autoconf 패키지에 있는 autom4te 프로그램(m4의 고 수준 레이어를 제공한다.)에서 이 정보를 사용한다.

이제 configure를 실행해보자

root@realg-desktop:~/test_CODE/C/struct_point# ./configure
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking for memset... yes
configure: creating ./config.status
config.status: error: cannot find input file: Makefile.in


root@realg-desktop:~/test_CODE/C/struct_point# ls
autom4te.cache  autoscan.log  config.log  config.status  configure  configure.ac  struct_point.c

Makefile이 만들어지지 않았다.
왜냐? 에러났으니까.!
스크립트 파일인 Makefile.am 을 일단 만들고 그다음에 automake 프로그램이 Makefile.am을 좀더 강력하고 복잡한 Makefile.in으로 확장시킨다.


automake 사용 과정

1. 응용프로그램에 대한 Makefile.am 파일을 만든다.
2. 현재는 없지만 automake 프로그램을 설치할 때 함께 설치된 템플릿을 복사하기 위해 --addmissing command-line 옵션을 사용해서 automake 프로그램을 실행시킨다. 또한 이 과정은 직접 만들어야 하는 파일이 올바른지 확인한다.
3. 전 단계에서 확인한 파일들을 만든다.
4. 응용프로그램의 configure.ac파일에 AM_INIT_AUTOMAKE(program, version) 매크로를 응용프로그램에 맞게 수정해서 추가한다. 이 매크로는 configure.ac. 파일에서 AC_INIT 매크로 다음에 위치해야 한다.
5. AM_INIT_AUTOMAKE 매크로는 표준 autoconf 매크로가 아니라 automake 매크로이기 때문에 , autoconf에서 사용할 m4 매크로의 정의(AM_INIT_AUTOMAKE 매크로 정의 등을 가리킨다.)를 가진 지역 파일을 만들기 위해서 aclocal 스크립트를 실행시켜야 한다.
6. autoconf 프로그램을 다시 실행 시킨다.
7. automake 프로그램을 다시 실행시켜서 Makefile.am에서 완전한 Makefile.in 파일을 만든다.


configure.ac. 파일을 다음과 같이
AM_INIT_AUTOMAKE 라는 부분을 삽입하고 저장한다. 이것음 automake 에서 사용하는 매크로에 대한 초기화 구문이다.

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.61)
AC_INIT(Testprogram, 1.0, hyb------@gmail.com)
AM_INIT_AUTOMAKE(Testprogram, 1.0)
AC_CONFIG_SRCDIR([struct_point.c])


# Checks for programs.
AC_PROG_CC

# Checks for libraries.

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([string.h])
AC_CONFIG_FILES([Makefile])
# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
AC_CHECK_FUNCS([memset])

AC_OUTPUT

automake.am 파일을 생성하고
기본적인 내용인 다음 두줄을 넣는다. (접두어는 Makefile을 만들때 사용된다.)

bin_PROGRAMS = Testprogram
Testprogram_SOURCES = struct_point.c

이렇게 하면

root@realg-desktop:~/test_CODE/C/struct_point# ls
autom4te.cache  automake.am  autoscan.log  config.log  config.status  configure  configure.ac  struct_point.c

위와 같은 파일이 남게 된다.

여기서 aclocal 명령어를 실행한다.

root@realg-desktop:~/test_CODE/C/struct_point# aclocal
root@realg-desktop:~/test_CODE/C/struct_point# ls
aclocal.m4      automake.am   config.log     configure     struct_point.c
autom4te.cache  autoscan.log  config.status  configure.ac


aclocal 명령을 실행하면 autoconf 매크로의 위치와 정의에 대한 정보를 모아서 aclocal.m4파일에 저장하게 된다.
(aclocal 스크립트는 configure.ac 파일에 AM_INIT_AUTOMAKE 매크로가 있을때에는 aclocal.m4 파일만을 생성한다. 그러나 AM_INIT_AUTOMAKE가 없으면 아무런 동작도 안하거나 실패한다. aclocal.m4가 생성되지 않는다면 configure.ac 에서 AM_INIT_AUTOMAKE 매크로를 선언했는지 확인해보기 바란다.)

드디어 다음으로 automake 프로그램을 실행한다.
automake --add-missing

root@realg-desktop:~/test_CODE/C/struct_point# automake --add-missing
configure.ac:6: installing `./install-sh'
configure.ac:6: installing `./missing'
automake: no `Makefile.am' found for any configure output
root@realg-desktop:~/test_CODE/C/struct_point# ls
aclocal.m4      automake.am   config.log     configure     install-sh  struct_point.c
autom4te.cache  autoscan.log  config.status  configure.ac  missing
root@realg-desktop:~/test_CODE/C/struct_point#

뭔가 잘못되었다. -_-;;;;;;;;

위에서 automake.ac 이 아니라 Makefile.ac 으로 만들었어야 했다.!!! ㅠ.ㅠ

파일명을 바꾸고 다시 도전해본다.

root@realg-desktop:~/test_CODE/C/struct_point# rm aclocal.m4 install-sh missing
root@realg-desktop:~/test_CODE/C/struct_point# mv automake.am Makefile.am
root@realg-desktop:~/test_CODE/C/struct_point# ls
autom4te.cache  autoscan.log  config.log  config.status  configure  configure.ac  Makefile.am  struct_point.c

root@realg-desktop:~/test_CODE/C/struct_point# aclocal
root@realg-desktop:~/test_CODE/C/struct_point# automake --add-missing
configure.ac:6: installing `./install-sh'
configure.ac:6: installing `./missing'
Makefile.am: installing `./INSTALL'
Makefile.am: required file `./NEWS' not found
Makefile.am: required file `./README' not found
Makefile.am: required file `./AUTHORS' not found
Makefile.am: required file `./ChangeLog' not found
Makefile.am: installing `./COPYING'
Makefile.am: installing `./depcomp'
root@realg-desktop:~/test_CODE/C/struct_point# l
합계 220
drwxr-xr-x 3 realg realg   4096 2009-04-21 21:01 .
drwxr-xr-x 9 realg realg   4096 2009-04-08 16:40 ..
-rw-r--r-- 1 root  root   32230 2009-04-21 21:01 aclocal.m4
drwxr-xr-x 2 root  root    4096 2009-04-21 21:01 autom4te.cache
-rw-r--r-- 1 root  root       0 2009-04-21 20:01 autoscan.log
-rw-r--r-- 1 root  root   10225 2009-04-21 20:12 config.log
-rwxr-xr-x 1 root  root   20814 2009-04-21 20:12 config.status
-rwxr-xr-x 1 root  root  125035 2009-04-21 20:12 configure
-rwxr--r-- 1 root  root     559 2009-04-21 21:00 configure.ac
lrwxrwxrwx 1 root  root      32 2009-04-21 21:01 COPYING -> /usr/share/automake-1.10/COPYING
lrwxrwxrwx 1 root  root      32 2009-04-21 21:01 depcomp -> /usr/share/automake-1.10/depcomp
lrwxrwxrwx 1 root  root      32 2009-04-21 21:01 INSTALL -> /usr/share/automake-1.10/INSTALL
lrwxrwxrwx 1 root  root      35 2009-04-21 21:01 install-sh -> /usr/share/automake-1.10/install-sh
-rwxr--r-- 1 root  root      64 2009-04-21 21:00 Makefile.am
lrwxrwxrwx 1 root  root      32 2009-04-21 21:01 missing -> /usr/share/automake-1.10/missing
-rw-r--r-- 1 realg realg    373 2009-03-30 19:35 struct_point.c
root@realg-desktop:~/test_CODE/C/struct_point#

root@realg-desktop:~/test_CODE/C/struct_point# touch NEWS README AUTHORS ChangeLog
root@realg-desktop:~/test_CODE/C/struct_point# ls
aclocal.m4      autoscan.log  config.status  COPYING  install-sh   NEWS
AUTHORS         ChangeLog     configure      depcomp  Makefile.am  README
autom4te.cache  config.log    configure.ac   INSTALL  missing      struct_point.c
root@realg-desktop:~/test_CODE/C/struct_point# automake --add-missing
root@realg-desktop:~/test_CODE/C/struct_point# ls
aclocal.m4      autoscan.log  config.status  COPYING  install-sh   missing  struct_point.c
AUTHORS         ChangeLog     configure      depcomp  Makefile.am  NEWS
autom4te.cache  config.log    configure.ac   INSTALL  Makefile.in  README

Makefile.in 이 생겼다.

root@realg-desktop:~/test_CODE/C/struct_point# autoconf

root@realg-desktop:~/test_CODE/C/struct_point# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for string.h... (cached) yes
checking for memset... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
root@realg-desktop:~/test_CODE/C/struct_point#

root@realg-desktop:~/test_CODE/C/struct_point# ls
aclocal.m4      autoscan.log  config.status  COPYING  install-sh   Makefile.in  README
AUTHORS         ChangeLog     configure      depcomp  Makefile     missing      struct_point.c
autom4te.cache  config.log    configure.ac   INSTALL  Makefile.am  NEWS

Makefile 생겼다.


root@realg-desktop:~/test_CODE/C/struct_point# make
gcc -DPACKAGE_NAME=\"Testprogram\" -DPACKAGE_TARNAME=\"testprogram\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"Testprogram\ 1.0\" -DPACKAGE_BUGREPORT=\"hyb------@gmail.com\" -DPACKAGE=\"Testprogram\" -DVERSION=\"1.0\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMSET=1 -I.     -g -O2 -MT struct_point.o -MD -MP -MF .deps/struct_point.Tpo -c -o struct_point.o struct_point.c
struct_point.c: In function ‘test’:
struct_point.c:12: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
struct_point.c: In function ‘main’:
struct_point.c:22: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
mv -f .deps/struct_point.Tpo .deps/struct_point.Po
gcc  -g -O2   -o Testprogram struct_point.o 
root@realg-desktop:~/test_CODE/C/struct_point# ls
aclocal.m4      autoscan.log  config.status  COPYING  install-sh   Makefile.in  README          Testprogram
AUTHORS         ChangeLog     configure      depcomp  Makefile     missing      struct_point.c
autom4te.cache  config.log    configure.ac   INSTALL  Makefile.am  NEWS         struct_point.o
root@realg-desktop:~/test_CODE/C/struct_point# ./Testprogram
adf


=0


== 0


==!! 0
root@realg-desktop:~/test_CODE/C/struct_point#


오~~~~~ 굿잡~!!!

ㅋㅋㅋ 잘된다.

저작자 표시 비영리 변경 금지
크리에이티브 커먼즈 라이선스
Creative Commons License

'Linux > Linux 일반' 카테고리의 다른 글

Libtool 사용하기  (0) 2009/04/21
automake 사용하기.!  (0) 2009/04/21
ubuntu edgy server locale 변경  (0) 2009/04/21
GNU Autotools를 이용한 프로젝트 만들기  (0) 2009/04/21
Posted by Real_G