用autoscan/aclocal/autoconf/automake建立Makefile的过程. 再次折腾过的,
记录备忘
一.环境
二.用到几个工具或命令
a. autoscan
b. aclocal
c. autoconf
d. automake
还有编译工程用到
e. configure
f. make
三. 全部文件
a. 全部文件目录结构
共9个目录, 27个文件
至少有一个文件没用到
b. 文件内容
1. main.c
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
#include "pdef.h"
-
-
int main(int argc, char* argv[], char* env[])
-
{
-
int i;
-
int num;
-
int arr[] = {3, 7, 1, 4, 9, 6, 2, 8, 5};
-
-
for(i = 0; i < TABLE_SIZES(arr); i++)
-
printf("%4d", arr[i]);
-
printf("\n");
-
-
sort_app(arr, TABLE_SIZES(arr));
-
-
for(i = 0; i < TABLE_SIZES(arr); i++)
-
printf("%4d", arr[i]);
-
-
printf("\n");
-
-
return 0;
-
}
2. Makefile.am
-
AUTOMAKE_OPTIONS=foreign
-
-
SUBDIRS=src include
-
CURRENTPATH=$(shell /bin/pwd)
-
INCLUDES=-I$(CURRENTPATH)/include/core/dsalg \
-
-I$(CURRENTPATH)/include/core/global \
-
-I$(CURRENTPATH)/include/app
-
export INCLUDES
-
-
LDFLAGS=-L$(CURRENTPATH)/src/core/dsalg \
-
-L$(CURRENTPATH)/src/app
-
-
LIBS+=-lapp -ldsalg
-
export LIBS
-
-
bin_PROGRAMS=main
-
-
main_SOURCES=main.c
-
#main_LDADD=$(CURRENTPATH)/src/core/dsalg/libdsalg.a $(CURRENTPATH)/src/app/libapp.a
3. include/Makefile.am
4. include/app/Makefile.am
-
EXTRA_DIST=search_app.h sort_app.h
5. include/app/search_app.h
-
#ifndef APPSEARCH_H
-
#define APPSEARCH_H
-
-
//int sch_compint(int* ,int*);
-
int search_app(int arr[],int, int);
-
-
#endif
6.
include/app/sort_app.h
-
#ifndef SORT_APP_H
-
#define SORT_APP_H
-
-
int sort_app(int arr[],int size);
-
-
#endif
7.
include/app/stack_app.h
空
8. include/core/Makefile.am
9.
include/core/sort.h
-
#ifndef SORT_H
-
#define SORT_H
-
-
//排序元素类型定义
-
typedef void* srt_elm_t;
-
-
//排序元素比较操作定义
-
typedef int (*fncomp_t)(const srt_elm_t, const srt_elm_t);
-
-
-
/*******************
-
数组形式插入排序
-
arr[]待排序数组
-
n数组元素个数
-
********************/
-
void insert_sort_a(srt_elm_t arr[], int n);
-
-
#endif
10. include/core/dsalg/Makefile.am
-
EXTRA_DIST=search.h sort.h list.h stack.h
11.
include/core/dsalg/list.h
-
#ifndef LIST_H
-
#define LIST_H
-
-
#endif
12.
include/core/dsalg/search.h
-
#ifndef SEARCH_H
-
#define SEARCH_H
-
-
typedef int sch_elm_t;
-
typedef int (*fncomp_sch_t)(const void*,const void*);
-
-
int sch_compint(sch_elm_t *a, sch_elm_t *b);
-
int linear_search(sch_elm_t tbl[],int n,sch_elm_t elm,fncomp_sch_t comp);
-
int binary_search(sch_elm_t tbl[],int n,sch_elm_t elm,fncomp_sch_t comp);
-
-
-
//int seq_search(int *,int,int);
-
//int seq_rsearch(int *,int,int);
-
#endif
13.
include/core/dsalg/sort.h
-
#ifndef SORT_H
-
#define SORT_H
-
-
typedef int srt_elm_t;
-
typedef int (*fncmp_srt_t)(srt_elm_t *,srt_elm_t *);
-
-
int sort_compint(srt_elm_t *a, srt_elm_t *b);
-
void insert_sort(srt_elm_t tbl[],int n,fncmp_srt_t comp);
-
-
#endif
14.
include/core/dsalg/stack.h
-
#ifndef STACK_H
-
#define STACK_H
-
-
#define STCKSIZE 100
-
-
typedef int stck_elm_t;
-
typedef struct stck_cdt_t{
-
int top;
-
stck_elm_t buf[STCKSIZE];
-
}stck_cdt_t;
-
-
typedef struct stck_cdt_t* stck_adt_t;
-
-
stck_adt_t NewStack(void);
-
void DeletStack(stck_adt_t stack);
-
void Push(stck_adt_t stack,stck_elm_t elm);
-
stck_elm_t Pop(stck_adt_t stack);
-
-
inline ubool StackIsEmpt(stck_adt_t stack);
-
inline ubool StackIsFull(stck_adt_t stack);
-
-
inline int StackDepth(stck_adt_t stack);
-
inline stck_elm_t StackTop(stck_adt_t stack);
-
-
#endif
15. include/core/global/Makefile.am
16. include/core/global/pdef.h
-
#ifndef _PDEF_H_
-
#define _PDEF_H_
-
-
#include
-
-
typedef char int8;
-
typedef short int16;
-
typedef long int32;
-
typedef unsigned char uint8;
-
typedef unsigned short uint16;
-
typedef unsigned long uint32;
-
typedef float float32;
-
typedef double double64;
-
typedef unsigned long ubool;
-
-
#ifndef FALSE
-
#define FALSE 0x00
-
#define TRUE 0x01
-
#endif
-
-
#define TABLE_SIZES(tbl) (sizeof(tbl) / sizeof(tbl[0]))
-
-
#ifndef NDEBUG
-
#define PTrace(fmt, arg...) (printf("%s--%d: " fmt, __FILE__, __LINE__, ##arg))
-
#else
-
#define PTrace(fmt, arg...)
-
#endif
-
-
#endif
17. src/Makefile.am
18. src/app/Makefile.am
-
noinst_LIBRARIES=libapp.a
-
libapp_a_SOURCES=search_app.c sort_app.c
19. src/app/search.c
-
#include "search.h"
-
#include "search_app.h"
-
-
int search_app(int arr[],int size, int key)
-
{
-
return binary_search(arr,size,key,sch_compint);
-
//return linear_search(arr,size,key,compint);
-
}
20. src/app/sort_app.c
-
#include "sort_app.h"
-
-
static int sort_compint(int *a, int *b)
-
{
-
return (*a-*b);
-
}
-
-
int sort_app(int arr[],int size)
-
{
-
return insert_sort(arr,size,sort_compint);
-
}
21. src/app/stack_app.c
空
22. src/core/Makefile.am
23. src/core/dsalg/Makefile.am
-
noinst_LIBRARIES=libdsalg.a
-
libdsalg_a_SOURCES=search.c sort.c list.c stack.c
24. src/core/dsalg/list.c
空
25. src/core/dsalg/search.c
-
#include "search.h"
-
-
int sch_compint(sch_elm_t *a, sch_elm_t *b)
-
{
-
return (*a-*b);
-
}
-
-
int linear_search(sch_elm_t tbl[],int n,sch_elm_t elm,fncomp_sch_t comp)
-
{
-
int i;
-
-
for(i=0;i<n;i++)
-
if(0==comp(&tbl[i],&elm))
-
return i;
-
return -1;
-
}
-
-
int binary_search(sch_elm_t tbl[],int n,sch_elm_t elm,fncomp_sch_t comp)
-
{
-
int min=0;
-
int max=n;
-
int mid;
-
int ret;
-
-
while(min<=max)
-
{
-
mid=(int)(min+max)/2;
-
ret=comp(&tbl[mid],&elm);
-
-
if(0==ret)
-
return mid;
-
else if(0>ret)
-
min=mid+1;
-
else
-
max=mid-1;
-
}
-
return -1;
-
}
26. src/core/dsalg/sort.c
-
#include "sort.h"
-
-
int sort_compint(srt_elm_t *a,srt_elm_t *b)
-
{
-
return (*a-*b);
-
}
-
-
void insert_sort(srt_elm_t tbl[],int n,fncmp_srt_t comp)
-
{
-
int i,j;
-
srt_elm_t tmp;
-
-
for(i=1;i<n;i++)
-
{
-
tmp=tbl[i];
-
for(j=i-1;j>=0;j--)
-
{
-
//if(comp(&tmp,&tbl[j])<0) //if(tmp<tbl[j])
-
if(tmp<tbl[j])
-
tbl[j+1]=tbl[j];
-
else
-
break;
-
}
-
tbl[j+1]=tmp;
-
}
-
}
-
-
/*
-
int bubble_sort(srt_elm_t tbl[],int n,fncomp_srt_t comp)
-
{
-
int i;
-
-
for(i=0;i<n-1;i++)
-
{
-
if(comp(tbl[i]),tbl[i+1]>0)
-
{
-
}
-
}
-
}
-
-
int bubble(srt_elm_t tbl[],int n,fncomp_srt_t comp)
-
{
-
-
for(i=0;i<n-1;i++)
-
{
-
-
}
-
}
-
//select sort
-
void select_sort(srt_elm_t tbl[],int n,fncomp_srt_t comp)
-
{
-
-
}
-
-
static int myselect(srt_elm_t tbl[],int n,fncomp_srt_t comp)
-
{
-
}
-
//quick sort
-
static int split_first(srt_elm_t tbl[], int n, fncomp_srt_t comp)
-
{
-
int i=0,j=n;
-
-
while(i<j)
-
{
-
while((i<n)&&(comp(&tbl[++i],&tbl[0])<0));
-
while(()&&(comp(&tbl[],&tbl[])));
-
if(i<j)
-
SWAP(tbl[i],tbl[j]);
-
}
-
}
-
-
-
void quick_sort(srt_elm_t tbl[],int n, fncomp_srt_t comp)
-
{
-
int pos=0;
-
-
pos=split_first(tbl,n,comp)
-
-
if(pos>1)
-
quick_sort(tbl,pos,comp);
-
if(pos<n-2)
-
quick_sort(&tbl[pos+1],n-1-pos,comp)
-
}
-
//merge sort
-
static void merge(srt_elm_t tbl[],int n, fncomp_srt_t comp)
-
{
-
int i=0,j=half;
-
int k=0;
-
-
srt_elm_t *pbuf=NULL;
-
-
pbuf=calloc(n,sizeof(srt_elm_t));
-
if(NULL!=pbuf)
-
{
-
-
}
-
-
free(pbuf);
-
}
-
-
void merge_sort(srt_elm_t tbl[],int n,fncomp_srt_t comp)
-
{
-
-
}
-
*/
27. src/core/dsalg/stack.c
-
#include "pdef.h"
-
#include "stack.h"
-
-
//Creat new stack
-
stck_adt_t NewStack(void)
-
{
-
stck_cdt_t *p;
-
-
p=malloc(sizeof(stck_cdt_t));
-
return p;
-
}
-
//Delete stack
-
void DeletStack(stck_adt_t stack)
-
{
-
if(NULL!=stack)
-
free(stack);
-
}
-
//Push elm into stack
-
void Push(stck_adt_t stack,stck_elm_t elm)
-
{
-
stack->buf[stack->top]=elm;
-
stack->top++;
-
}
-
//
-
stck_elm_t Pop(stck_adt_t stack)
-
{
-
stack->top--;
-
return stack->buf[stack->top];
-
-
}
-
-
inline ubool StackIsEmpt(stck_adt_t stack)
-
{
-
return (0==stack->top);
-
}
-
-
inline ubool StackIsFull(stck_adt_t stack)
-
{
-
return (stack->top==(STCKSIZE-1));
-
}
-
-
inline int StackDepth(stck_adt_t stack)
-
{
-
return stack->top;
-
}
-
inline stck_elm_t StackTop(stck_adt_t stack)
-
{
-
return stack->buf[stack->top];
-
}
共27个文件. 每个目录及子目录下均有Makefile.am文件. 是构建Makefile的关键
待续.
阅读(1288) | 评论(0) | 转发(0) |