1. 아래와 같이 소스코드를 작성합니다.
<test1.c> <test2.c>
#include <stdio.h>
main()
{
fprintf(stderr, “Hello world!n”);
}
<main.c>
#include <stdio.h>
extern void print_hello(void);
main()
{
print_hello();
}
<sub.c>
#include <stdio.h>
void print_hello(void)
{
fprintf(stderr, “Hello World!n”);
}
2. vi 로 Makefile.am을 만들어 아래와 같은 내용을 입력후 저장합니다.
bin_PROGRAMS = test1 test2 test3
test1_SOURCES = test1.c
test2_SOURCES = test2.c
test3_SOURCES = main.c sub.c
3. 프롬프트에서 autoscan 을 실행 합니다.
[root@virus_man test3]# autoscan
configure.scan 파일이 생성되었음을 확인해 봅니다.
[root@virus_man test3]# ls
Makefile.am configure.scan test1.c test2.c main.c sub.c
[root@virus_man test3]#
configure.scan 파일 내용은 다음과 같습니다.
dnl Process this file with autoconf to produce a configure script.
AC_INIT(main.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. 위 내용을 아래와 같이 수정한후 저장합니다.
ss this file with autoconf to produce a configure script.
AC_INIT(main.c)
AM_INIT_AUTOMAKE(test-3, 1.0)
dnl Checks for programs.
AC_PROG_CC
AC_PROG_AWK
AC_PROG_INSTALL
AC_PROG_LN_S
AC_ARG_PROGRAM
dnl Checks for libraries.
dnl Checks for header files.
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for library functions.
AC_OUTPUT(Makefile)
5. configure.scan 파일을 configure.in 으로 확장자를 바꿉니다.
[root@virus_man test3]# mv configure.scan configure.in
6. 그다음 aclocal, autoconf, automake 를 실행합니다.
[root@virus_man test3]# aclocal
[root@virus_man test3]# autoconf
[root@virus_man test3]# 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
[root@virus_man test3]# ls
OPYING@ Makefile.in configure.in missing@ test1.c
INSTALL@ aclocal.m4 install-sh@ mkinstalldirs@ test2.c
Makefile.am configure* main.c sub.c
7. configure 를 실행합니다.
[root@virus_man test3]# ./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
checking for gcc… gcc
checking whether the C compiler (gcc ) works… yes
checking whether the C compiler (gcc ) is a cross-compiler… no
checking whether we are using GNU C… yes
checking whether gcc accepts -g… yes
checking for gawk… gawk
checking for a BSD compatible install… /usr/bin/install -c
checking whether ln -s works… yes
updating cache ./config.cache
creating ./config.status
creating Makefile
[root@virus_man test3]# ls
OPYING@ Makefile.am config.cache configure* main.c sub.c
INSTALL@ Makefile.in config.log configure.in missing@ test1.c
Makefile aclocal.m4 config.status* install-sh@ mkinstalldirs@ test2.c
8. 이제 make 를 실행해 봅시다.
ot@virus_man test3]# make
gcc -DPACKAGE=”test-1″ -DVERSION=”1.0″ -I. -I. -g -O2 -c test1.c
gcc -g -O2 -o test1 test1.o
gcc -DPACKAGE=”test-1″ -DVERSION=”1.0″ -I. -I. -g -O2 -c test2.c
gcc -g -O2 -o test2 test2.o
gcc -DPACKAGE=”test-1″ -DVERSION=”1.0″ -I. -I. -g -O2 -c main.c
gcc -DPACKAGE=”test-1″ -DVERSION=”1.0″ -I. -I. -g -O2 -c sub.c
gcc -g -O2 -o test3 main.o sub.o
[root@virus_man test3]# ls
COPYING@ aclocal.m4 configure.in mkinstalldirs@ test1.o
INSTALL@ config.cache install-sh@ sub.c test2*
Makefile config.log main.c sub.o test2.c
Makefile.am config.status* main.o test1* test2.o
Makefile.in configure* missing@ test1.c test3*
* test1 test2 test3 파일이 생성되었는지 확인 합니다.
9. 예제를 실행합니다.
[root@virus_man test3]# ./test1
hello world
[root@virus_man test3]# ./test2
hello world
[root@virus_man test3]# ./test3
Hello world