본문 바로가기
【🧰 SW Info & Tips】/🦿 Automake & Autoconf

GNU 빌드시스템 (2)

반응형

*원본 출처: cloudrain21.com/gnu-build-system-2

 

GNU 빌드시스템 (2) - Rain.i

All about IT tech, especially database, cloud, linux, clustering.

cloudrain21.com

자~  세상에서 가장 간단한 GNU 빌드시스템을 만들어볼까요 ?
아래 시스템에서 시험했습니다.

  1. [$] uname -a
  2. Linux smurf 2.6.32-220.el6.x86_64 #1 SMP Tue Dec 6 19:48:22 GMT 2011 x86_64 x86_64 x86_64 GNU/Linux

1.
다음과 같이 hello.c 파일을 만듭니다. 어떤 내용이든 상관없습니다.

  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. printf("hello\n");
  6. }

2.
configure.in 파일을 다음과 같이 작성합니다.

  1. dnl configure.in sample -> 주석
  2.  
  3. AC_PREREQ(2.59)
  4.  
  5. AC_INIT([hello], [1.0], [cloudrain21@gmail.com]) -> 프로그램명, 버전, 이메일주소
  6.  
  7. AM_INIT_AUTOMAKE([1.9 foreign])
  8.  
  9. AC_PROG_CC
  10.  
  11. AC_CONFIG_FILES([Makefile])
  12. AC_OUTPUT

3.
Makefile.am 파일을 다음과 같이 작성합니다.

  1. bin_PROGRAMS = hello -> bin 디렉토리에 만들 실행파일 이름
  2. hello_SOURCES = hello.c -> hello 실행파일을 만들 때 필요한 source 파일
  3. hello_LDADD = -> 빌드 시 필요한 라이브러리

4.
configure 파일을 만들기 위해 다음의 과정을 수행합니다.
가. aclocal 수행
나. autoconf 수행

  1. [$] aclocal
  2. [$] ls
  3. Makefile.am aclocal.m4 autom4te.cache/ configure.in hello.c
  4. [$] autoconf
  5. [$] ls
  6. Makefile.am aclocal.m4 autom4te.cache/ configure* configure.in hello.c

신기하게도 우리가 많이 보던 configure 파일이 생성되었네요? ㅎㅎ
aclocal 은 일단 configure 파일을 만들때 필요한 내용이 들어있는 m4 파일을 생성한다고만 알아둡시다.

5.
Makefile.in 을 만들어내기위해 automake 를 수행합니다.

  1. [$] automake
  2. configure.in:7: required file `./install-sh' not found
  3. configure.in:7: `automake --add-missing' can install `install-sh'
  4. configure.in:7: required file `./missing' not found
  5. configure.in:7: `automake --add-missing' can install `missing'
  6. Makefile.am: required file `./depcomp' not found
  7. Makefile.am: `automake --add-missing' can install `depcomp'

실행해보니 install-sh 파일 등이 없다고 나오면서 automake시  –add-missing 옵션을 사용하라고 나오는군요. 해봅시다.

  1. [$] automake --add-missing
  2. configure.in:7: installing `./install-sh'
  3. configure.in:7: installing `./missing'
  4. Makefile.am: installing `./depcomp'
  5. [$] ls
  6. Makefile.am aclocal.m4 config.log configure.in install-sh@
  7. Makefile.in autom4te.cache/ configure* depcomp@ hello.c missing@

오우~ 자동으로 필요한 파일들이 생기고 Makefile.in 파일도 생겼네요.

6.
드디어 configure 를 해봅니다.

  1. [$] ./configure
  2. checking for a BSD-compatible install... /usr/bin/install -c
  3. checking whether build environment is sane... yes
  4. checking for a thread-safe mkdir -p... /bin/mkdir -p
  5. checking for gawk... gawk
  6. checking whether make sets $(MAKE)... yes
  7. checking for gcc... gcc
  8. checking for C compiler default output file name... a.out
  9. checking whether the C compiler works... yes
  10. checking whether we are cross compiling... no
  11. checking for suffix of executables...
  12. checking for suffix of object files... o
  13. checking whether we are using the GNU C compiler... yes
  14. checking whether gcc accepts -g... yes
  15. checking for gcc option to accept ISO C89... none needed
  16. checking for style of include used by make... GNU
  17. checking dependency style of gcc... gcc3
  18. configure: creating ./config.status
  19. config.status: creating Makefile
  20. config.status: executing depfiles commands
  21. [$] ls
  22. Makefile Makefile.in autom4te.cache/ config.status* configure.in install-sh@
  23. Makefile.am aclocal.m4 config.log configure* depcomp@ hello.c missing@

와우~ Makefile 이 자동으로 생성되었습니다.
빌드 시에 우리가 결국 필요로 하는 파일이 Makefile 아니겠어요 ?

그리고, configure 를 수행했을 때의 상태그대로를 재활용하고자할 경우를  위해 생성되는 config.status 와 configure 시의 trace log 를 기록해둔 config.log 파일도 생성되었음을 볼 수 있습니다.

7.
make 를 통해 컴파일을 해봅시다.

  1. [$] make
  2. gcc -DPACKAGE_NAME=\"hello\" -DPACKAGE_TARNAME=\"hello\" -DPACKAGE_VERSION=\"1.0\" -DPACKAGE_STRING=\"hello\ 1.0\" -DPACKAGE_BUGREPORT=\"cloudrain21@gmail.com\" -DPACKAGE=\"hello\" -DVERSION=\"1.0\" -I. -g -O2 -MT hello.o -MD -MP -MF .deps/hello.Tpo -c -o hello.o hello.c
  3. mv -f .deps/hello.Tpo .deps/hello.Po
  4. gcc -g -O2 -o hello hello.o
  5. [$] ls
  6. Makefile aclocal.m4 config.status* depcomp@ hello.o
  7. Makefile.am autom4te.cache/ configure* &nb
  8. sp; hello* install-sh@
  9. Makefile.in config.log configure.in hello.c missing@
  10. [$] ./hello
  11. hello
  12. [$] make install
  13. make[1]: Entering directory `/home/bitmyer/tmp/gnu_build_2'
  14. test -z "/usr/local/bin" || /bin/mkdir -p "/usr/local/bin"
  15. /usr/bin/install -c hello '/usr/local/bin'
  16. /usr/bin/install: cannot create regular file `/usr/local/bin/hello': 허가 거부
  17. make[1]: *** [install-binPROGRAMS] 오류 1
  18. make[1]: Leaving directory `/home/bitmyer/tmp/gnu_build_2'
  19. make: *** [install-am] 오류 2

make install 할 때는 default directory 인 /usr/local 쪽으로 install 하려다가 실패했습니다.
이는 configure 할 때 –prefix=/home/cloudrain21/local 과 같이 변경가능하겠죠. ^^

다음은 위의 과정을 한번에 수행해본 결과 이미지입니다.

자~ 이제 하나의 초간단 프로젝트를 자동 빌드하는 법을 배워봤습니다.

반응형

'【🧰 SW Info & Tips】 > 🦿 Automake & Autoconf' 카테고리의 다른 글

GNU 빌드시스템 (1)  (0) 2020.10.24
[autotools] Manual  (0) 2011.10.07
[automake] libtool  (0) 2011.10.07
[autotools] automake, autoconf 사용법  (0) 2011.10.07
[autoconf] Macro 정리 (Canonicalizing)  (0) 2011.10.07