Autotools - WindyHana's Solanara

목차

개요

설치

사용방법

  1. 디렉토리 및 소스파일

    root@wl ~/autotools # mkdir src
    root@wl ~/autotools/src # cat helloworld.c
    #include "helloworld.h"
    #include <stdio.h>
    #include <time.h>
    
    void print_helloworld() {
        time_t today = time(NULL);
        struct tm* t = localtime(&today);
        char buf[100];
        strftime(buf, sizeof(buf), "%Y-%m-%d", t);
    
        printf("Hello, World! %s\n", buf);
    }
    root@wl ~/autotools/src # cat helloworld.h
    #ifndef helloworld_h
    #define helloworld_h
    
    void print_helloworld();
    
    #endif
    root@wl ~/autotools/src # cat main.c
    #include "helloworld.h"
    
    int main() {
    	print_helloworld();
    }
    root@wl ~/autotools/src # ln -s helloworld.c libhelloworld.c
    
    컴파일은 아래와 같이 할 수 있다. 테스트한 후 helloworld 는 삭제한다.
    root@wl ~/autotools/src # cc -o helloworld main.c helloworld.c
    
  2. Makefile.am 작성

    root@wl ~/autotools # vi Makefile.am
    AUTOMAKE_OPTIONS = foreign
    SUBDIRS = src
    ACLOCAL_AMFLAGS = -I m4
    root@wl ~/autotools # vi src/Makefile.am
    ACLOCAL_AMFLAGS = -I m4
    AM_CFLAGS = -O3
    AM_LDFLAGS =
    bin_PROGRAMS = helloworld
    sbin_PROGRAMS = helloworld
    helloworld_SOURCES = helloworld.c helloworld.h main.c
    lib_LTLIBRARIES = libhelloworld.la
    libhelloworld_la_SOURCES = libhelloworld.c helloworld.h
    libhelloworld_la_LDFLAGS = -version-info $(LIBHELLOWORLD_LIBRARY_VERSION) -release $(LIBHELLOWORLD_RELEASE_VERSION)
    
    여기까지 하면 아래와 같이 파일이 있어야 한다. 이 파일들은 http://www.solanara.net/downloads/autotools.tar.gz 에서 받을 수 있다.
    root@wl ~/autotools # find .
    ./
    ./Makefile.am
    ./src
    ./src/helloworld.c
    ./src/main.c
    ./src/helloworld.h
    ./src/libhelloworld.c
    ./src/Makefile.am
    
  3. configure.ac 파일 생성

    configure.ac 는 어떤 것을 체크해야 하는지 알려준다. 이 스크립트 안에서 각종 테스트를 수행한다. 컴파일러로 gcc와 cc 중 어떤것을 사용하는지 알아내서 컴파일 플래그를 다르게 주거나, 컴파일에 반드시 필요한 라이브러리가 있는 경우, 이 파일에 관련 설정을 넣어줘야 한다. 만약 시스템에 2GB이상 파일을 지원하는지 알려면 이 파일에 [AC_SYS_LARGEFILE]매크로를 넣어주면 된다. 미리 정의된 테스트의 목록은 Autoconf - 5 Existing Tests을 참고하자.
    root@wl ~/autotools # autoscan 1)
    root@wl ~/autotools # mv configure.scan configure.ac
    root@wl ~/autotools # vi configure.ac
    AC_INIT(helloworld, 1.0, admin@solanara.net) 2)
    AM_INIT_AUTOMAKE
    
    AM_PROG_LIBTOOL
    
    LIBHELLOWORLD_RELEASE_VERSION=1
    LIBHELLOWORLD_LIBRARY_VERSION=1:0:0
    AC_SUBST(LIBHELLOWORLD_RELEASE_VERSION)
    AC_SUBST(LIBHELLOWORLD_LIBRARY_VERSION)
    
    AC_CONFIG_MACRO_DIR([m4])
    
    1) configure.scan, autoscan.log 파일이 생성된다. autoscan.log 파일은 지워도 된다.
    2) AC_INIT 부분을 수정한다. 나머지는 AC_OUTPUT 위의 적당한 위치에 추가한다.
  4. configure 파일 및 configure 에 필요한 파일 생성

    root@wl ~/autotools # autoheader 1)
    root@wl ~/autotools # libtoolize 2)
    libtoolize: putting auxiliary files in `.'.
    libtoolize: linking file `./ltmain.sh'
    libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
    libtoolize: linking file `m4/libtool.m4'
    libtoolize: linking file `m4/ltoptions.m4'
    libtoolize: linking file `m4/ltsugar.m4'
    libtoolize: linking file `m4/ltversion.m4'
    libtoolize: linking file `m4/lt~obsolete.m4'
    root@wl ~/autotools # aclocal 3)
    root@wl ~/autotools # automake --add-missing 4)
    configure.ac:12: installing `./config.guess'
    configure.ac:12: installing `./config.sub'
    configure.ac:6: installing `./install-sh'
    configure.ac:6: installing `./missing'
    src/Makefile.am: installing `./depcomp'
    root@wl ~/autotools # autoconf 5)
    
    1) autom4te.cache 디렉토리와, config.h.in 파일을 생성한다.
    2) m4 디렉토리를 생성하고, ltmain.sh 파일을 링크한다.
    3) aclocal.m4 파일을 생성한다.
    4) Makefile.in 파일을 생성하고, config.guess, config.sub, install-sh, missing, depcomp를 링크한다.
    5) configure 파일을 생성한다.
  5. 테스트

    root@wl ~/autotools # ./configure --prefix=/usr/local/hw
    root@wl ~/autotools # make
    root@wl ~/autotools # make install
    root@wl ~/autotools # cd /usr/local/hw
    root@wl /usr/local/hw # find .
    .
    ./bin
    ./bin/helloworld
    ./lib
    ./lib/libhelloworld-1.so.1.0.0
    ./lib/libhelloworld.a
    ./lib/libhelloworld-1.so.1
    ./lib/libhelloworld.la
    ./lib/libhelloworld.so
    ./sbin
    ./sbin/helloworld
    root@wl /usr/local/hw # ./bin/helloworld
    Hello, World! 2010-04-24
    
  6. 배포본 만들기

    root@wl ~/autotools # make dist-gzip
    root@wl ~/autotools # ls -al *.tar.gz
    -rw-r--r--   1 root     root      270534  4월 24일  08:52 helloworld-1.0.tar.gz
    root@wl ~/autotools # 
    

diff, patch

Twitter RSS IconTexto 올바른 XHTML 1.0 Transitional 입니다 올바른 CSS입니다!