autoconfとautomakeでmakeを実行
make対象となるソースコードは以下のものがあると想定します。
Test.h
Test.cpp
test_main.cpp
普段だとコンパイルする際には
g++ -o test_main.o -c test_main.cpp
g++ -o Test.o -c Test.cpp
gcc -o test test_main.o Test.o
となります。
毎回全部入力するのは面倒なのでMakefileを作成し、makeコマンドで一連の処理を実行できるようにします。
1.Makefile.amの作成
まずはMakefile.amを作成します。
bin_PROGRAMS = test
smtp_SOURCES = Test.h Test.cpp test_main.cpp
2.autoscanの実行
autoscanを実行します。
$autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
- Makefile.am
- Test.cpp
- Test.h
- autoscan.log
- configure.scan
- test_main.cpp
3.作成されたconfigure.scanを元にconfigure.acを作成
cp configure.scan configure.ac
- Makefile.am
- Test.cpp
- Test.h
- autoscan.log
- configure.ac
- configure.scan
- test_main.cpp
configure.acにAM_INIT_AUTOMAKEを追記します。
$emacs configure.ac
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.AC_PREREQ(2.59)
AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AM_INIT_AUTOMAKE([foreign]) #ここを追記
AC_CONFIG_SRCDIR([Test.cpp])
AC_CONFIG_HEADER([config.h])# Checks for programs.
AC_PROG_CXX
AC_PROG_CC# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
4.autoheaderの実行
$autoheader
- Makefile.am
- Test.h
- autoscan.log
- configure.ac
- test_main.cpp
- Test.cpp
- autom4te.cache/
- config.h.in
- configure.scan
5.aclocalの実行
aclocal
- Makefile.am
- Test.h
- autom4te.cache/
- config.h.in
- configure.scan
- Test.cpp
- aclocal.m4
- autoscan.log
- configure.ac
- test_main.cpp
6.automakeの実行
automake -ac
- Makefile.am
- Test.h
- autoscan.log
- configure.scan
- missing
- Makefile.in
- aclocal.m4
- config.h.in
- depcomp
- test_main.cpp
- Test.cpp
- autom4te.cache/
- configure.ac
- install-sh
7.autoconfの実行
autoconf
- Makefile.am
- Test.h
- autoscan.log
- configure.ac
- install-sh
- Makefile.in
- aclocal.m4
- config.h.in
- configure.scan
- missing
- Test.cpp
- autom4te.cache/
- configure
- depcomp
- test_main.cpp
8.configure、makeの実行
./configure
make