免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1089 | 回复: 0
打印 上一主题 下一主题

automake编译实例 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-10-09 15:08 |只看该作者 |倒序浏览
一,编译环境准备
apt-get install util-linux
apt-get install gcc g++ make
apt-get install autoconf automake
apt-get install libtool
libtoolize --automake --copy --debug --force   #配置libtool
二,代码
cat main.c
#include
#include
#include "test.h"
int main(int argc, char **argv)
{
    ot_printf(argv[1]);
    return 0;
}
======================================
cat test.h
#ifndef __TEST_H__
#define __TEST_H__
void ot_printf(const char* str);
#endif
======================================
cat test.c
#include
#include
#include "test.h"
void ot_printf(const char* str)
{
  printf("syslog: %s\n",str);
}
三,编译过程
====================================
1.准备好源文件
     hello.c myfun.c myfun.h
2.autoscan生成configure.scan
3.将confgure.scan更名为configure.in
4.修改configure.in
      修改 AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
       =>AC_INIT(ot_test,1.0,support@itibia.com)
       增加一行AM_INIT_AUTOMAKE
      见2.configure.in
5.运行aclocal
6.运行autoconf
7.编辑Makefile.am
AUTOMAKE_OPTIONS=foreign                   非gnu标准     
bin_PROGRAMS=auto_test                          输出可执行文件名称
auto_test_SOURCES=hello.c myfun.c        所有源文件
见3.Makefile.am(手动创建)
8.运行autoheader
9.运行automake --add-missing
10.运行./configure
11.运行make编译
make all
不加任何 target,默认就是 all,作用是编译软件
make install
安装软件包,如果安装到系统目录,需要 root 权限
make clean
清除编译产生的目标文件
make distclean
可以同时清除编译的结果和 configure 输出的文件
make tags
生成 etags 使用的 TAGS 文件
make dist
生成软件发布包,为 tar.gz 格式的压缩包,文件名由软件包名和版本组成。
====================================
四,中间过程
4.1 configure.in
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.63])
AC_INIT(ot_test, 1.0, support@itibia.com)
AC_CONFIG_AUX_DIR([build])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_CONFIG_SRCDIR([main.c])
AC_CONFIG_HEADERS([config.h])
AC_PREFIX_DEFAULT([/usr/local/emanagesv])
# Checks for programs.
AC_PROG_CXX
AC_PROG_CC(gcc g++)
AC_PROG_MAKE_SET
AC_PROG_CPP
AC_PROG_LIBTOOL
# Checks for libraries.
# Checks for header files.
AC_CHECK_HEADERS([stdin.h stdlib.h])
# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_TYPE_UID_T
AC_C_INLINE
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_STRUCT_TM
# Checks for library functions.
AC_FUNC_ALLOCA
AC_FUNC_CHOWN
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_FORK
AC_PROG_GCC_TRADITIONAL
#comment it to prevent autoconf
AC_CONFIG_FILES([Makefile])
#save user-provided flags
#--with-mysql-include
#--with-mysql-lib
#restore user-provided flags
#with-build-mode
AC_OUTPUT
4.2 Makefile.am
CURRENTPATH=.
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS=ot_test
ot_test_SOURCES=main.c test.c


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/104357/showart_2066346.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP