root@wl ~/src # wget http://ftp.gnu.org/gnu/m4/m4-1.4.16.tar.bz2 root@wl ~/src # tar xvfj m4-1.4.16.tar.bz2 root@wl ~/src # cd m4-1.4.16 root@wl ~/src/m4-1.4.16 # ./configure root@wl ~/src/m4-1.4.16 # make root@wl ~/src/m4-1.4.16 # make install
root@wl ~ # wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.bz2 root@wl ~ # tar xvfj autoconf-2.68.tar.bz2 root@wl ~ # cd autoconf-2.68 root@wl ~/autoconf-2.68 # ./configure root@wl ~/autoconf-2.68 # make root@wl ~/autoconf-2.68 # make install
root@wl ~ # wget http://ftp.gnu.org/gnu/automake/automake-1.11.1.tar.bz2 root@wl ~ # tar xvfj automake-1.11.1.tar.bz2 root@wl ~ # cd automake-1.11.1 root@wl ~/automake-1.11.1 # ./configure root@wl ~/automake-1.11.1 # make root@wl ~/automake-1.11.1 # make install
root@wl ~ # wget http://ftp.gnu.org/gnu/libtool/libtool-2.4.tar.gz root@wl ~ # tar xvfz libtool-2.4.tar.gz root@wl ~ # cd libtool-2.4 root@wl ~/libtool-2.4 # ./configure root@wl ~/libtool-2.4 # make root@wl ~/libtool-2.4 # make install
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
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
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 파일은 지워도 된다.
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 파일을 생성한다.
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
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 #
root@wl ~ # cat new.c
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello, World!\n");
}
root@wl ~ # cat old.c
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello, World!");
}
root@wl ~ # cp old.c helloworld.c
root@wl ~ # diff -u old.c new.c > patch.diff 1)
root@wl ~ # cat patch.diff
--- old.c Thu Jul 22 18:14:31 2010
+++ new.c Thu Jul 22 18:14:23 2010
@@ -1,5 +1,5 @@
#include <stdio.h>
int main(int argc, char *argv[]) {
- printf("Hello, World!");
+ printf("Hello, World!\n");
}
root@wl ~ # patch -b -i patch.diff helloworld.c 2)
통합된 문맥 diff처럼 보입니다.
완료
root@wl ~ # ls -l
-rw-r--r-- 1 windy staff 85 7월 22일 18:19 helloworld.c
-rw-r--r-- 1 windy staff 83 7월 22일 18:18 helloworld.c.orig
-rw-r--r-- 1 windy staff 85 7월 22일 18:14 new.c
-rw-r--r-- 1 windy staff 83 7월 22일 18:14 old.c
-rw-r--r-- 1 windy staff 203 7월 22일 18:15 patch.diff
root@wl ~ # cat helloworld.c
#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello, World!\n");
}
root@wl ~ #
1) old.c 와 new.c 의 차이를 나타내는 파일을 생성해 patch.diff 로 저장한다. -u 는 출력 형식을 지정하는 것으로 Unified Context형식을 의미한다.root@wl ~ # diff old.c new.c
4c4
< printf("Hello, World!");
---
> printf("Hello, World!\n");
root@wl ~ # diff -c old.c new.c
*** old.c Thu Jul 22 18:14:31 2010
--- new.c Thu Jul 22 18:14:23 2010
***************
*** 1,5 ****
#include <stdio.h>
int main(int argc, char *argv[]) {
! printf("Hello, World!");
}
--- 1,5 ----
#include <stdio.h>
int main(int argc, char *argv[]) {
! printf("Hello, World!\n");
}
root@wl ~ # diff -u old.c new.c
*** old.c Thu Jul 22 18:14:31 2010
--- new.c Thu Jul 22 18:14:23 2010
@@ -1,5 +1,5 @@
#include <stdio.h>
int main(int argc, char *argv[]) {
- printf("Hello, World!");
+ printf("Hello, World!\n");
}
|
|
Copyright © 2004-2012 Jo HoSeok. All rights reserved. |