利用 autoconf 和 automake 自动生成Makefile
想起来自己写的一些代码,不想用IDE,还不会写makefile。所以:
工具
autoconf automake # 没错就是在编译 Protocol Buffer 时安装的那几个
生成流程图一览
具体步骤
$ cd SRC_DIR
$ autoscan
$ emacs configure.scan
$ mv configure.scan configure.ac
$ emacs makefile.am
$ aclocal
$ autoconf
$ automake --add-missing
$ ./configure
真实测试案例
$ ll
total 168
drwxr-xr-x 14 huangchenglin staff 476B May 16 23:16 .
drwxr-xr-x 18 huangchenglin staff 612B May 16 22:25 ..
-rw-r--r--@ 1 huangchenglin staff 6.0K May 16 23:16 .DS_Store
-rw-r--r-- 1 huangchenglin staff 20K Dec 20 17:18 CNN.hpp
-rw-r--r-- 1 huangchenglin staff 4.6K Dec 20 20:12 Dataset.hpp
-rw-r--r-- 1 huangchenglin staff 8.2K Dec 20 01:47 Layer.hpp
-rw-r--r-- 1 huangchenglin staff 296B Dec 19 23:50 Log.hpp
-rw-r--r-- 1 huangchenglin staff 326B Dec 14 13:00 MyException.hpp
-rw-r--r-- 1 huangchenglin staff 1.1K Dec 17 09:31 Size.hpp
-rw-r--r-- 1 huangchenglin staff 7.9K May 16 22:57 basic.h
-rw-r--r-- 1 huangchenglin staff 460B May 16 22:47 configure.ac
drwxr-xr-x 10 huangchenglin staff 340B Dec 20 14:12 dataset
-rw-r--r-- 1 huangchenglin staff 816B Dec 20 16:54 main.cpp
-rw-r--r-- 1 huangchenglin staff 134B May 16 22:54 makefile.am
$ aclocal
$ autoconf
$ automake --add-missing
configure.ac:6: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
configure.ac:6: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.ac:9: installing './compile'
configure.ac:6: installing './install-sh'
configure.ac:6: installing './missing'
Makefile.am: installing './depcomp'
$ ./configure
... # 一堆 checking 信息
$ make
... # 编译输出信息
$ ./cnn
cnn build successfully...
2051 60000 28 28
trainset build successfully...
0th iter epochsNum: 1200
附测试用的 configure.ac 和 makefile.am
##configure.ac
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT(main.cpp)
AM_INIT_AUTOMAKE(cnn, 1.0)
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_HEADER_STDBOOL
# Checks for library functions.
AC_CHECK_FUNCS([sqrt])
AC_OUTPUT(Makefile)
## makefile.am
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=cnn
cnn_SOURCES=main.cpp basic.h CNN.hpp Dataset.hpp Layer.hpp Log.hpp Size.hpp MyException.hpp
备注
makefile.am 配置libs还在研究。