automake使用说明

automake

Automake is a tool for automatically generating Makefile.in files
compliant with the GNU Coding Standards. Automake requires the use of Autoconf.
复制代码

目前automake支持三种目录层次:flat、shallow和deep。

  1. flat指的是所有文件都位于同一个目录中。 就是所有源文件、头文件以及其他库文件都位于当前目录中,且没有子目录。Termutils就是这一类。

  2. shallow指的是主要的源代码都储存在顶层目录,其他各个部分则储存在子目录中。 就是主要源文件在当前目录中,而其它一些实现各部分功能的源文件位于各自不同的目录。automake本身就是这一类。

  3. deep指的是所有源代码都被储存在子目录中;顶层目录主要包含配置信息。 就是所有源文件及自己写的头文件位于当前目录的一个子目录中,而当前目录里没有任何源文件。 GNU cpio和GNU tar就是这一类。

autoconf

Autoconf is an extensible package of M4 macros that produce shell scripts to
automatically configure software source code packages. These scripts can
adapt the packages to many kinds of UNIX-like systems without manual 
user intervention. Autoconf creates a configuration script for a package from
a template file that lists the operating system features that the package can
use, in the form of M4 macro calls.
复制代码

Makefile生成流程图

configure.ac文件

#                                               -*- Autoconf -*-  
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69]) //宏用于声明文件要求的autoconf版本
AC_INIT([ts2017], [v0.1], [fxb_mail@163.com])
AM_INIT_AUTOMAKE()//使用automake自动生成Makefile
AC_CONFIG_SRCDIR([config.h.in])//用于检测源码目录的有效性,任选一个源码文件即可
AC_CONFIG_HEADERS([config.h])//用于生成config.h文件供autoheader使用

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL

AC_PROG_RANLIB  #静态库
AC_PROG_LIBTOOL #使用libtool生成动态库
AC_CONFIG_FILES([Makefile
                 interface_lib/Makefile
                 sample/Makefile
                 zdmsd/Makefile
                 zjlog/Makefile])

AC_CONFIG_SUBDIRS([3rd/libevent/libevent-2.1.8-stable
                   3rd/hardware])
AC_OUTPUT
复制代码

autoreconf命令

autoreconf [options]   autoreconf --force --install
-f, --force
    Remake all configure scripts, even when newer than their template files.
-i, --install
    Add any default files missing from package by copying versions included with autoconf and automake.GNU autoconf tool. Update configure scripts by running autoconf, autoheader, aclocal, automake, and libtoolizein specified directories and subdirectories. This command is seldom invoked manually. It is usually called automatically from other autoconf tools.
复制代码

生成执行文件、静态、动态库

变量说明:
变量名说明
AM_CPPFLAGSAM_CPPFLAGS = -I${top_srcdir}/src
AM_CFLAGSAM_CFLAGS = -I${top_srcdir}/src
$(top_srcdir)工程最顶层目录
$(top_builddir)定义生成目标文件的最上层目录

生成可执行文件:

AUTOMAKE_OPTIONS = foreign subdir-objects
AM_CPPFLAGS     = $(INCLUDEDIR) //编译器的-I参数
bin_PROGRAMS    = zdmsd
zdmsd_SOURCES   = zdmsd.c ../device/device.c
zdmsd_LDADD     = -llog -L$(BUILD_DIR)/zjlog/ \
                  -ludp -L$(BUILD_DIR)/3rd/hardware/device/udp/ \
                  -levent \
                  -L$(BUILD_DIR)/3rd/libevent/libevent-2.1.8-stable \
                  -lpthread 
zdmsd_LDFLAGS   = -Wl,-rpath=../lib 
复制代码

静态库:

AUTOMAKE_OPTIONS=foreign
lib_LIBRARIES=libxxx.a
libxxx_a_SOURCES = xxx.c
libxxx_a_LDADD =  -lz ../lib/libxxx.la  #依赖的库文件
libxxx_a_LDFLAGS =
include_HEADERS =
复制代码

动态库:

AUTOMAKE_OPTIONS=foreign
lib_LTLIBRARIES=libxx.la
libxx_la_SOURCES=xx.c
include_HEADERS=xx.h //make install时会复制到安装目录的include目录中。
在configure.ac中添加AC_PROG_LIBTOOL表示用libtool生成动态库。
注:libtoolize 提供了一种标准的方式来将libtool 支持加入一个软件包,而GNU libtool 是一个通用库支持脚本,
将使用动态库的复杂性隐藏在统一、可移植的接口中。
复制代码

转载于:https://juejin.im/post/5b743051f265da27f534b758

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值