automake

下面举个例子,说明多目录下的automake的写法

1.编写代码
方便起见, 根目录下建hello文件夹
mkdir /hello
mkdir /hello/src
mkdir /hello/operation

vi /hello/operation/operation.h
vi /hello/operation/operation.c
vi /hello/src/main.c // main里面调用operation的函数

2.生成 configure.in
cd /hello
touch configure.ac
autoscan

这个时候 ls 可见如下
autom4te.cache autoscan.log configure.ac configure.scan operation src
其中的configure.ac是多余的, rm configure.ac
mv configure.scan configure.in

3.编写 /hello/configure.in

# configure.in
AC_PREREQ(2.59)
AC_INIT(configure.in)
AM_INIT_AUTOMAKE(hello, 1.0)

# Checks for programs.
AC_PROG_CC
AC_PROG_RANLIB
# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.
AC_OUTPUT([
Makefile
operation/Makefile
src/Makefile
])
#end of configure.in

这样就可以了.
如果.c文件里面要添加链接库,比如pthead,则添加
AC_CHECK_LIB(pthead, pthread_create)
诸如AC_CHECK....等含义,大致可以由名字看出来,具体的用时再查资料

4. 生成 configure
aclocal
autoconf

5. 写 Makefile.am
5.1 vi /hello/Makefile.am

#/hello/Makefie.am

SUBDIRS = function test1 sub

#end of Makefile.am

5.2 vi /hello/src/Makefile.am

#/hello/src/Makefile.am

bin_PROGRAMS = hello
hello_SOURCES = main.c
hello_LDADD = $(top_builddir)/operation/liboper.a

#end of Makefile.am

5.3 vi /hello/operation/operation.am

#/hello/operation/Makefile.am

noinst_LIBRARIES = liboper.a
liboper_a_SOURCES = operation.c
liboper_a_LIBADD = @LIBOBJS@

#end of Makefile.am

6. 生成 Makefile
cd /hello
automake --add-missing
如果出现 warning ,提示缺文件, touch 出来即可,比如 AUTHOR

7. 编译.运行

./configure
make
./src/hello
8. 其他

make install 安装到bin下,注意前面是 bin_PROGRAMS
make dist 生成tar.gz包
make distclean 清除所有.a .o等
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值