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

[autotools] automake, autoconf 사용법

반응형
▣ 원문 출처: http://funkylocker.tistory.com/entry/autotools-automake-autoconf-사용법
 
auttotools 란 코드의 빌드를 관리해 주는 툴로 automake와 autoconf 등 (aclocal, autoscan...) 으로 구성되며, 간단한 프로그램에서 큰 규모의 프로젝트의 소스코드를 간편하게 빌드할 수 있도록 Makefile을 제공하는데에 목적을 두고 있습니다.

(사실 컴포넌트가 몇개 되지 않는 프로그램의 경우는 Makefile을 직접 만드는 경우도 좋겠죠. 하지만 왠지 이렇게 만들어 놓으면 프로그램이 폼난다는.. ^^;;;)

일반적으로 autotools를 이용해서 Makefile을 생성하기 위해서는 Makefile.am과 configure.ac (or configure.in) 이 필요합니다. 확장자 am과 ac에서 알 수 있듯이 automake와 autoconf 의 입력 데이터로 사용됩니다.

Makefile.am은 configure 과정을 통해 Makefile.in 을 생성하고, 최종적으로 Makefile 을 생성하게 됩니다. 프로그램
동작에 대한 구조는 automake, autoconf 의 홈페이지나 이승윤 님이 작성하신 AUTOTOOLS Howto (http://wiki.kldp.org/wiki.php/DocbookSgml/Autotools-KLDP) 를 참고하시면 좋으실 것 같습니다.

그러면 이제 autotools 로 간단한 프로그램을 빌드 해보도록 하겠습니다.


[소스 트리]
 $ tree
 .
|-- Makefile
|-- Makefile.am
|-- Makefile.in
|-- README
|-- TAGS
|-- aclocal.m4
|-- autom4te.cache
|   |-- output.0
|   |-- output.1
|   |-- output.2
|   |-- requests
|   |-- traces.0
|   |-- traces.1
|   `-- traces.2
|-- autoscan.log
|-- config.guess
|-- config.h
|-- config.h.in
|-- config.log
|-- config.status
|-- config.sub
|-- configure
|-- configure.ac
|-- default.mk
|-- depcomp
|-- include
|   |-- common.h
|   |-- sub.h
|   `-- sum.h

|-- install-sh
|-- libtool
|-- ltmain.sh
|-- missing
|-- src
|   |-- Makefile
|   |-- Makefile.am
|   |-- Makefile.in
|   |-- main.c
|   |-- sum.c
|   `--  sub.c
`-- stamp-h1

해당 트리에서 유저가 만들어야 하는 파일은 위에 빨간색으로 표시된 것입니다. 이중 소스코드도 당연히 유저 몫입니다.

그럼 Makefile.am 을 먼저 살펴보도록 하겠습니다.


[Makefile.am]
 SUBDIRS = src



[src/Makefile.am]
 bin_PROGRAMS = calulator
 test_SOURCES = main.c \
                          sum.c \
                          sub.c


configure.ac는 기본 폼을 자동으로 만들어주는 autoscan을 이용하도록 합니다. 해당 툴을 이용하면 기본적인 체크 부분에 대한 매크로가 생성됩니다.

[autoscan]
 $ autoscan
 $ cat configure.scan



configure.scan 파일이 생성되면 해당 파일을 에디터로 열어 수정해준뒤 configure.ac로 변경하시면 됩니다. 저는 별도로 추가적인 체크 내용은 넣지 않도록 하겠습니다.

[configure.scan]

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

AC_PREREQ([2.63])

# 변경
# AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AC_INIT([calculator], [0.0.1], [calculator@test.com])


# 꼭 추가 (Makefile 생성)
AM_INIT_AUTOMAKE([-Wall -Werror foreign])

AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC

# Checks for libraries.
# FIXME: Replace `main' with a function in `-lc':
AC_CHECK_LIB([c], [main])

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_CONFIG_FILES([Makefile
                 src/Makefile])
AC_OUTPUT



[파일명 변경]
 $ mv configure.scan configure.ac

configure.ac 파일 작성이 완료 되었으면 이제 configure.ac 와 Makefile.am 파일을 바탕으로 configure 파일을 생성하도록 합니다.

[configure 생성]
 $ autoreconf --install


이후 동작은 일반적인 설치 과정과 동일합니다.

[컴파일]
 $ ./configure --prefix=/usr/local/calculator
 $ make
 $ make install


 
반응형

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

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