8步运用automake开源发布自己的软件

都说自己写Makefile麻烦,而且在不同体系结构下为了移植性写出的Makefile完全没法读懂,所以好像目前大牛都开始用automake产生Makefile了,这里总结一下自己初步学习的经验。

首先,我只有一个文件,testtcmalloc.c

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <pthread.h>
#define MAX_COUNT 1000*1000
void fun(int i)
{
        char* ptr = (char*)malloc(i);
         free(ptr);
}

void* fun_thread(void*)
{
         int i = 0;
         int j = 1;
        while(i++<MAX_COUNT)
        {
                   j ++;
                   fun(j);
                   if ( j>1024 )
                        j = 1;
        }
}

#define MSECOND 1000000
int main()
{
         struct timeval tpstart,tpend;
         float timeuse;
         gettimeofday(&tpstart,NULL);
         pthread_t _deliver_t;
         pthread_create(&_deliver_t, NULL, fun_thread, NULL);
         int i = 0;
         int j = 1;
         while(i++<MAX_COUNT)
         {
                   j ++;
                   fun(i);
                   if ( j > 1024 )
                            j = 1;
                  //usleep(1);
         }

       gettimeofday(&tpend,NULL);
      timeuse=MSECOND*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
         timeuse/=MSECOND;
         printf("Used Time:%f\n", timeuse);
         return 0;
}

 

总共8步完成。

step1: autoscan

[root@localhost test1]# pwd
/home/zhulele/fedora18/gadgit/src/test1
[root@localhost test1]# ll
total 4
-rw-r--r-- 1 root root 1244 Jun  3 10:04 testtcmalloc.c
[root@localhost test1]# autoscan
[root@localhost test1]# ls
autoscan.log  configure.scan  testtcmalloc.c
[root@localhost test1]# 

step 2:mv

[root@localhost test1]# mv configure.scan configure.in
[root@localhost test1]# ls
autoscan.log  configure.in  testtcmalloc.c

step 3:vim configure.in

添加两行,一个是AM_INIT_AUTOMAKE(PACKAGE,VERSION)
另外在output加上Makefile

  1 #                                               -*- Autoconf -*-
  2 # Process this file with autoconf to produce a configure script.
  3 
  4 AC_PREREQ([2.69])
  5 AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
  6 AC_CONFIG_SRCDIR([testtcmalloc.c])
  7 AC_CONFIG_HEADERS([config.h])
  8 # I add something here!!!
  9 AM_INIT_AUTOMAKE(testtcmalloc,1.0)
 10 
 11 # Checks for programs.
 12 AC_PROG_CC
 13 
 14 # Checks for libraries.
 15 
 16 # Checks for header files. 
 17 AC_CHECK_HEADERS([stdlib.h sys/time.h unistd.h])
 18 
 19 # Checks for typedefs, structures, and compiler characteristics.
 20 
 21 # Checks for library functions.
 22 AC_FUNC_MALLOC
 23 AC_CHECK_FUNCS([gettimeofday])
 24 # I add "(Makefile)"
 25 AC_OUTPUT(Makefile)


step 4: aclocal

[root@localhost test1]# vim configure.in 
[root@localhost test1]# aclocal
[root@localhost test1]# ls
aclocal.m4  autom4te.cache  autoscan.log  configure.in  testtcmalloc.c

step 5: autoconf

[root@localhost test1]# autoconf
[root@localhost test1]# ls
aclocal.m4  autom4te.cache  autoscan.log  configure  configure.in  testtcmalloc.c
step 6: 自己编写Makefile.am

  1 bin_PROGRAMS = testtcmalloc
  2      testtcmalloc_SOURCES = testtcmalloc.c
  3      testtcmalloc_CFLAGS = -lpthread -ltcmalloc


step7: autoheader

step 8: automake --add-missing



 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值