Linuxでmakefileを自動的に生成するツール:automake,autoconfでmakefileを生成する一般的なプロセス
Linuxでmakefileを自動的に生成するツール:automake,autoconfでmakefileを生成する一般的なプロセス
1.プロジェクトディレクトリと各ディレクトリの下のmakefileを作成する.am.エンジニアリングの名前は、一般的に最終生成アプリケーションの名前と同じです.
wzb@embedded ~]$ mkdir workspace
[wzb@embedded ~]$ cd workspace/
[wzb@embedded workspace]$ ls
[wzb@embedded workspace]$ mkdir testAutoMake
[wzb@embedded workspace]$ ls
testAutoMake
[wzb@embedded workspace]$ cd testAutoMake/
[wzb@embedded testAutoMake]$ ls
[wzb@embedded testAutoMake]$ mkdir src
[wzb@embedded testAutoMake]$ ls
src
[wzb@embedded testAutoMake]$ pwd
/home/wzb/workspace/testAutoMake
[wzb@embedded testAutoMake]$ ls
src
[wzb@embedded testAutoMake]$ vi makefile.am
[wzb@embedded testAutoMake]$ cd src
[wzb@embedded src]$ ls
[wzb@embedded src]$ vi main.c
[wzb@embedded src]$ ls
main.c
[wzb@embedded src]$ vi main.c
[wzb@embedded src]$ clear
[wzb@embedded src]$ ls
main.c
[wzb@embedded src]$ vi makefile.am
[wzb@embedded src]$ clear
[wzb@embedded src]$ ls
main.c makefile.am
[wzb@embedded src]$ cd ..
[wzb@embedded testAutoMake]$ ls
makefile.am src
[wzb@embedded testAutoMake]$ pwd
/home/wzb/workspace/testAutoMake
[wzb@embedded testAutoMake]$ ls -R
.:
makefile.am src
./src:
main.c makefile.am
[wzb@embedded testAutoMake]$
[wzb@embedded testAutoMake]$ pwd
/home/wzb/workspace/testAutoMake
[wzb@embedded testAutoMake]$ ls
makefile.am src
[wzb@embedded testAutoMake]$ cat makefile.am
SUBDIRS=src
[wzb@embedded testAutoMake]$ vi makefile.am
[wzb@embedded testAutoMake]$ cd src
[wzb@embedded src]$ ls
main.c makefile.am
[wzb@embedded src]$ cat main.c
#include <stdio.h>
#include <stdarg.h>
int accumulate(int nr, ...);
int main(int argc, char *argv[]) {
int n = 5;
int result = accumulate(5, 5, 4, 3, 2, 1);
printf("%d,
", result);
printf("test.......makefile ........ok
");
return 0;
}
int accumulate(int nr, ...) {
int i = 0;
int result = 0;
va_list arg ;
va_start(arg, nr);
for(i=0; i<nr; i++) {
result += va_arg(arg, int);
}
va_end(arg);
return result;
}
[wzb@embedded src]$ pwd
/home/wzb/workspace/testAutoMake/src
[wzb@embedded src]$ cat makefile.am
bin_PROGRAMS=testAutoMake
testAutoMake_SOURCES=main.c
[wzb@embedded src]$
2.autoscanコマンドにより、autoconfのテンプレートを作成し、configureを生成する.inファイル.
まず、エンジニアリングディレクトリでautoscanコマンドを実行することにより、autoconfのテンプレートファイルconfigureを生成する.scanファイル、configureと名前を変更します.in.
2つの変更が必要です.
(1). これをinファイルの文:AC_INIT(FULL-PAKAGE-NAME,VERSION,BUG-REPORT-ADDRESS)の
FULL-PaKAGE-NAME:あなたが割り当てた開発パッケージの名前に置き換えます:本プロジェクトのようです:test_AutoMake;
VERSION:開発されたバージョン番号、一般フォーマット:マスターバージョン番号.バージョン番号から.例えば0.1;
BUG-REPORT-ADDRESS:バグを送信するメールアドレス:[email protected].
(2). もう1つ追加します:AM_INIT_AUTOMAKE(testAutoMake,0.1)すなわちAM_INIT_AUTOMAKE(package_name, version);
Automakeを初期化するために使用します.
[wzb@embedded testAutoMake]$ pwd
/home/wzb/workspace/testAutoMake
[wzb@embedded testAutoMake]$ ls
makefile.am src
[wzb@embedded testAutoMake]$ autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
[wzb@embedded testAutoMake]$ ls
autoscan.log configure.scan makefile.am src
[wzb@embedded testAutoMake]$ vi configure.scan
[wzb@embedded testAutoMake]$ vi configure.scan
[wzb@embedded testAutoMake]$ mv configure.scan configure.in
[wzb@embedded testAutoMake]$ ls
autoscan.log configure.in makefile.am src
[wzb@embedded testAutoMake]$ cat configure.in
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADER([config.h])
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
AC_HEADER_STDC
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([makefile
src/makefile])
AC_OUTPUT
[wzb@embedded testAutoMake]$ vi configure.in
[wzb@embedded testAutoMake]$ clear
[wzb@embedded testAutoMake]$ ls
autoscan.log configure.in makefile.am src
[wzb@embedded testAutoMake]$ cat configure.in
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.59)
AC_INIT(testAutoMake, 0.1, [email protected])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE(testAutoMake, 0.1)
# Checks for programs.
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
AC_HEADER_STDC
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([makefile
src/makefile])
AC_OUTPUT
[wzb@embedded testAutoMake]$
3.aclocalを使用してconfigure.in中マクロ展開、alocalを生成する.m 4と一時加速ファイルautom 4 te.cache.
[wzb@embedded testAutoMake]$ pwd
/home/wzb/workspace/testAutoMake
[wzb@embedded testAutoMake]$ ls
autoscan.log configure.in makefile.am src
[wzb@embedded testAutoMake]$ aclocal
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autom4te.cache autoscan.log configure.in makefile.am src
[wzb@embedded testAutoMake]$
[wzb@embedded testAutoMake]$
4.autoheaderでconfigを生成する.h.inファイル.
[wzb@embedded testAutoMake]$ pwd
/home/wzb/workspace/testAutoMake
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autom4te.cache autoscan.log configure.in makefile.am src
[wzb@embedded testAutoMake]$ autoheader
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autoscan.log configure.in src
autom4te.cache config.h.in makefile.am
[wzb@embedded testAutoMake]$
5.ファイル作成:README、NEWS、AUTHERS、ChangeLog.touch README NEWS AUTHORS ChangeLog
[wzb@embedded testAutoMake]$ pwd
/home/wzb/workspace/testAutoMake
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autoscan.log configure.in src
autom4te.cache config.h.in makefile.am
[wzb@embedded testAutoMake]$ touch NEWS README AUTHORS ChangeLog
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autom4te.cache ChangeLog configure.in NEWS src
AUTHORS autoscan.log config.h.in makefile.am README
[wzb@embedded testAutoMake]$ vi ChangeLog
[wzb@embedded testAutoMake]$ cat ChangeLog
2012-04-07 Earl [email protected]
* Created
[wzb@embedded testAutoMake]$
6.automake-aコマンドを実行してmakefileを生成する.inファイルその他関連ファイルinstall-sh,missing,depcomp,INSTALL,COPYINGなど.
[wzb@embedded testAutoMake]$ pwd
/home/wzb/workspace/testAutoMake
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autom4te.cache ChangeLog configure.in NEWS src
AUTHORS autoscan.log config.h.in makefile.am README
[wzb@embedded testAutoMake]$ automake -a
configure.in: installing `./install-sh'
configure.in: installing `./missing'
src/makefile.am: installing `./depcomp'
makefile.am: installing `./INSTALL'
makefile.am: installing `./COPYING'
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autoscan.log configure.in INSTALL makefile.in README
AUTHORS ChangeLog COPYING install-sh missing src
autom4te.cache config.h.in depcomp makefile.am NEWS
[wzb@embedded testAutoMake]$
7.autoconfコマンドを実行し、configureスクリプトを生成します.
[wzb@embedded testAutoMake]$ pwd
/home/wzb/workspace/testAutoMake
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autoscan.log configure.in INSTALL makefile.in README
AUTHORS ChangeLog COPYING install-sh missing src
autom4te.cache config.h.in depcomp makefile.am NEWS
[wzb@embedded testAutoMake]$ autoconf
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autoscan.log configure depcomp makefile.am NEWS
AUTHORS ChangeLog configure.in INSTALL makefile.in README
autom4te.cache config.h.in COPYING install-sh missing src
[wzb@embedded testAutoMake]$
8.実行./configureはmakefileファイルを生成します.
configureスクリプトの2つのパラメータ、-prefixはbinディレクトリの親ディレクトリを指定します.もう1つの-hostはプロセッサアーキテクチャを指定し、クロスコンパイル環境の構築に役立ちます.
[wzb@embedded testAutoMake]$ pwd
/home/wzb/workspace/testAutoMake
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autoscan.log configure depcomp makefile.am NEWS
AUTHORS ChangeLog configure.in INSTALL makefile.in README
autom4te.cache config.h.in COPYING install-sh missing src
[wzb@embedded testAutoMake]$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for egrep... grep -E
checking for ANSI C header files... yes
configure: creating ./config.status
config.status: creating makefile
config.status: creating src/makefile
config.status: creating config.h
config.status: executing depfiles commands
[wzb@embedded testAutoMake]$ ls
aclocal.m4 ChangeLog config.status depcomp makefile.am README
AUTHORS config.h configure INSTALL makefile.in src
autom4te.cache config.h.in configure.in install-sh missing stamp-h1
autoscan.log config.log COPYING makefile NEWS
[wzb@embedded testAutoMake]$
9.次の手順は、基本的にソースコードからアプリケーションをコンパイルしてインストールする手順と似ています.
まず、./configure-prefix binディレクトリが存在する親ディレクトリ(絶対パス)
続いてmake;コンパイル
最後にmake install;binディレクトリに実行可能なプログラムテストの生成を見つけます.
[wzb@embedded testAutoMake]$ pwd
/home/wzb/workspace/testAutoMake
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autom4te.cache ChangeLog config.h.in config.status configure.in depcomp install-sh makefile.am missing README stamp-h1
AUTHORS autoscan.log config.h config.log configure COPYING INSTALL makefile makefile.in NEWS src
[wzb@embedded testAutoMake]$ ./configure -prefix /home/wzb/w
workspace/ wzb/
[wzb@embedded testAutoMake]$ ./configure -prefix /home/wzb/workspace/testAutoMake/
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for egrep... grep -E
checking for ANSI C header files... yes
configure: creating ./config.status
config.status: creating makefile
config.status: creating src/makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
[wzb@embedded testAutoMake]$ make
make all-recursive
make[1]: Entering directory `/home/wzb/workspace/testAutoMake'
Making all in src
make[2]: Entering directory `/home/wzb/workspace/testAutoMake/src'
if gcc -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -MT main.o -MD -MP -MF ".deps/main.Tpo" -c -o main.o main.c; \
then mv -f ".deps/main.Tpo" ".deps/main.Po"; else rm -f ".deps/main.Tpo"; exit 1; fi
gcc -g -O2 -o testAutoMake main.o
make[2]: Leaving directory `/home/wzb/workspace/testAutoMake/src'
make[2]: Entering directory `/home/wzb/workspace/testAutoMake'
make[2]: Leaving directory `/home/wzb/workspace/testAutoMake'
make[1]: Leaving directory `/home/wzb/workspace/testAutoMake'
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autom4te.cache ChangeLog config.h.in config.status configure.in depcomp install-sh makefile.am missing README stamp-h1
AUTHORS autoscan.log config.h config.log configure COPYING INSTALL makefile makefile.in NEWS src
[wzb@embedded testAutoMake]$ make install
Making install in src
make[1]: Entering directory `/home/wzb/workspace/testAutoMake/src'
make[2]: Entering directory `/home/wzb/workspace/testAutoMake/src'
test -z "/home/wzb/workspace/testAutoMake//bin" || mkdir -p -- "/home/wzb/workspace/testAutoMake//bin"
/usr/bin/install -c 'testAutoMake' '/home/wzb/workspace/testAutoMake//bin/testAutoMake'
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/wzb/workspace/testAutoMake/src'
make[1]: Leaving directory `/home/wzb/workspace/testAutoMake/src'
make[1]: Entering directory `/home/wzb/workspace/testAutoMake'
make[2]: Entering directory `/home/wzb/workspace/testAutoMake'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/wzb/workspace/testAutoMake'
make[1]: Leaving directory `/home/wzb/workspace/testAutoMake'
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autoscan.log config.h config.status COPYING install-sh makefile.in README
AUTHORS bin config.h.in configure depcomp makefile missing src
autom4te.cache ChangeLog config.log configure.in INSTALL makefile.am NEWS stamp-h1
[wzb@embedded testAutoMake]$ ./bin/testAutoMake
15,
test.......makefile ........ok
[wzb@embedded testAutoMake]$
10.プログラムが安定すると、make distをコマンドすることで、エンジニアリングのパブリケーションファイルを生成できます.(make distcheckコマンドもあります)
[wzb@embedded testAutoMake]$ pwd
/home/wzb/workspace/testAutoMake
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autoscan.log config.h config.status COPYING install-sh makefile.in README
AUTHORS bin config.h.in configure depcomp makefile missing src
autom4te.cache ChangeLog config.log configure.in INSTALL makefile.am NEWS stamp-h1
[wzb@embedded testAutoMake]$ make dist
{ test ! -d testAutoMake-0.1 || { find testAutoMake-0.1 -type d ! -perm -200 -exec chmod u+w {} ';' && rm -fr testAutoMake-0.1; }; }
mkdir testAutoMake-0.1
list='src'; for subdir in $list; do \
if test "$subdir" = .; then :; else \
test -d "testAutoMake-0.1/$subdir" \
|| mkdir -p -- "testAutoMake-0.1/$subdir" \
|| exit 1; \
distdir=`CDPATH="${ZSH_VERSION+.}:" && cd testAutoMake-0.1 && pwd`; \
top_distdir=`CDPATH="${ZSH_VERSION+.}:" && cd testAutoMake-0.1 && pwd`; \
(cd $subdir && \
make \
top_distdir="$top_distdir" \
distdir="$distdir/$subdir" \
distdir) \
|| exit 1; \
fi; \
done
make[1]: Entering directory `/home/wzb/workspace/testAutoMake/src'
make[1]: Leaving directory `/home/wzb/workspace/testAutoMake/src'
find testAutoMake-0.1 -type d ! -perm -755 -exec chmod a+rwx,go+rx {} \; -o \
! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
! -type d ! -perm -400 -exec chmod a+r {} \; -o \
! -type d ! -perm -444 -exec /bin/sh /home/wzb/workspace/testAutoMake/install-sh -c -m a+r {} {} \; \
|| chmod -R a+r testAutoMake-0.1
tardir=testAutoMake-0.1 && /bin/sh /home/wzb/workspace/testAutoMake/missing --run tar chof - "$tardir" | GZIP=--best gzip -c >testAutoMake-0.1.tar.gz
{ test ! -d testAutoMake-0.1 || { find testAutoMake-0.1 -type d ! -perm -200 -exec chmod u+w {} ';' && rm -fr testAutoMake-0.1; }; }
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autoscan.log config.h config.status COPYING install-sh makefile.in README testAutoMake-0.1.tar.gz
AUTHORS bin config.h.in configure depcomp makefile missing src
autom4te.cache ChangeLog config.log configure.in INSTALL makefile.am NEWS stamp-h1
[wzb@embedded testAutoMake]$ clear
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autoscan.log config.h config.status COPYING install-sh makefile.in README testAutoMake-0.1.tar.gz
AUTHORS bin config.h.in configure depcomp makefile missing src
autom4te.cache ChangeLog config.log configure.in INSTALL makefile.am NEWS stamp-h1
[wzb@embedded testAutoMake]$ clear
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autoscan.log config.h config.status COPYING install-sh makefile.in README testAutoMake-0.1.tar.gz
AUTHORS bin config.h.in configure depcomp makefile missing src
autom4te.cache ChangeLog config.log configure.in INSTALL makefile.am NEWS stamp-h1
[wzb@embedded testAutoMake]$ vi ChangeLog
[wzb@embedded testAutoMake]$ clear
[wzb@embedded testAutoMake]$ ls
aclocal.m4 autoscan.log config.h config.status COPYING install-sh makefile.in README testAutoMake-0.1.tar.gz
AUTHORS bin config.h.in configure depcomp makefile missing src
autom4te.cache ChangeLog config.log configure.in INSTALL makefile.am NEWS stamp-h1
[wzb@embedded testAutoMake]$ vi configure.in
以上はautomakeを用いてmakefileを生成する全過程であり、
なぜかと思うと、ソースファイルをインストールするときは、まず./configure -prefix ... , 次にmake、次にmake install.よくわかりました...