利用 autoconf 和 automake 自動生成Makefile

利用 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還在研究。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章