automake
农存
2023-12-01
下面举个例子,说明多目录下的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等