간단한 예제
1. 우선 test1.c 라는 이름으로 아래의 소스를 작성합니다.
#include <stdio.h>
main()
{
fprintf(stderr, “Hello World!n”);
}
2. vi 로 Makefile.am을 만들어 아래와 같은 내용을 입력후 저장합니다.
bin_PROGRAMS = test1
test1_SOURCES = test1.c
3. 프롬프트에서 autoscan 을 실행 합니다.
[root@virus_man test1]# autoscan
[root@virus_man test1]# ls
Makefile.am configure.scan test1.c
[root@virus_man test1]#
configure.scan 파일이 생성되었음을 확인해 봅니다.
configure.scan 파일 내용은 다음과 같습니다.
dnl Process this file with autoconf to produce a configure script.
AC_INIT(test1.c)
dnl Checks for programs.
dnl Checks for libraries.
dnl Checks for header files.
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for library functions.
AC_OUTPUT()
4. 위 내용을 아래와 같이 수정한후 저장합니다.
AC_INIT(test1.c)
AM_INIT_AUTOMAKE(test1, 1.0)
AC_CONFIG_HEADERS(config.h)
dnl Checks for programs.
dnl Checks for libraries.
dnl Checks for header files.
AC_CHECK_HEADERS(unistd.h)
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for library functions.
AC_OUTPUT(Makefile)
5. configure.scan 파일을 configure.in 으로 확장자를 바꿉니다.
[root@virus_man test1]# mv configure.scan configure.in
6. 그다음 aclocal, autoconf, automake 를 실행합니다.
[root@virus_man test1]# aclocal
[root@virus_man test1]# autoconf
[root@virus_man test1]# automake –add-missing
automake: configure.in: installing `./install-sh’
automake: configure.in: installing `./mkinstalldirs’
automake: configure.in: installing `./missing’
automake: Makefile.am: installing `./INSTALL’
automake: Makefile.am: required file `./NEWS’ not found
automake: Makefile.am: required file `./README’ not found
automake: Makefile.am: installing `./COPYING’
automake: Makefile.am: required file `./AUTHORS’ not found
automake: Makefile.am: required file `./ChangeLog’ not found
automake: Makefile.am: C source seen but `CC’ not defined in `configure.in’
[root@virus_man test1]# ls
COPYING@ Makefile.am aclocal.m4 configure.in missing@ test1.c
INSTALL@ Makefile.in configure* install-sh@ mkinstalldirs@
여기 내용을 보면 configure.in에 CC 가 정의되지 않았다는 내용이 있습니다. (automake –add-missing 마지막 출력내용)
이럴경우 configure.in 을 열어 AC_PROG_CC 매크로를 아래와 같이 작성+저장후 autoconf 부터 다시 실행합니다.
AC_INIT(test1.c)
AM_INIT_AUTOMAKE(test1, 1.0)
AC_CONFIG_HEADERS(config.h)
dnl Checks for programs.
AC_PROG_CC
dnl Checks for libraries.
dnl Checks for header files.
AC_CHECK_HEADERS(unistd.h)
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for library functions.
AC_OUTPUT(Makefile)
7. configure 를 실행합니다.
[root@virus_man test1]# ./configure
creating cache ./config.cache
checking for a BSD compatible install… /usr/bin/install -c
checking whether build environment is sane… yes
checking whether make sets ${MAKE}… yes
checking for working aclocal… found
checking for working autoconf… found
checking for working automake… found
checking for working autoheader… found
checking for working makeinfo… found
updating cache ./config.cache
creating ./config.status
creating Makefile
[root@virus_man test1]# ls
COPYING@ Makefile.am config.cache configure* missing@
INSTALL@ Makefile.in config.log configure.in mkinstalldirs@
Makefile aclocal.m4 config.status* install-sh@ test1.c
8. 이제 make 를 실행해 봅시다.
[root@virus_man test1]# make
-DPACKAGE=”test1″ -DVERSION=”1.0″ -I. -I. -c test1.c
cc -o test1 test1.o
[root@virus_man test1]# ls
COPYING@ Makefile.am config.cache configure* missing@ test1.c
INSTALL@ Makefile.in config.log configure.in mkinstalldirs@ test1.o
Makefile aclocal.m4 config.status* install-sh@ test1*
9. test1 예제를 실행합니다.
[root@virus_man test1]# ./test1
Hello World!