您的位置:首页 > 其它

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

2013-06-03 10:17 316 查看
都说自己写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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: