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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值