Chinaunix首页 | 论坛 | 博客
  • 博客访问: 659069
  • 博文数量: 186
  • 博客积分: 1875
  • 博客等级: 上尉
  • 技术积分: 2117
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-23 23:21
个人简介

有时候,就是想窥视一下不知道的东东,因为好奇!

文章分类

全部博文(186)

文章存档

2024年(2)

2023年(3)

2020年(1)

2019年(1)

2018年(1)

2017年(2)

2016年(69)

2015年(53)

2014年(14)

2013年(1)

2012年(5)

2011年(25)

2010年(9)

分类: LINUX

2016-04-13 23:05:35

  用autoscan/aclocal/autoconf/automake建立Makefile的过程. 再次折腾过的, 记录备忘
一.环境
 
二.用到几个工具或命令
 a. autoscan
 b. aclocal
 c. autoconf
 d. automake
 还有编译工程用到
 e. configure
 f. make
三. 全部文件
 a. 全部文件目录结构
 
  共9个目录, 27个文件
 至少有一个文件没用到

 b. 文件内容
    1. main.c

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "pdef.h"

  5. int main(int argc, char* argv[], char* env[])
  6. {
  7.     int    i;
  8.     int    num;
  9.     int    arr[] = {3, 7, 1, 4, 9, 6, 2, 8, 5};

  10.     for(i = 0; i < TABLE_SIZES(arr); i++)
  11.         printf("%4d", arr[i]);
  12.     printf("\n");

  13.     sort_app(arr, TABLE_SIZES(arr));

  14.     for(i = 0; i < TABLE_SIZES(arr); i++)
  15.         printf("%4d", arr[i]);
  16.     
  17.     printf("\n");
  18.     
  19.     return 0;
  20. }
  2. Makefile.am

点击(此处)折叠或打开

  1. AUTOMAKE_OPTIONS=foreign

  2. SUBDIRS=src include
  3. CURRENTPATH=$(shell /bin/pwd)
  4. INCLUDES=-I$(CURRENTPATH)/include/core/dsalg \
  5. -I$(CURRENTPATH)/include/core/global \
  6. -I$(CURRENTPATH)/include/app
  7. export INCLUDES

  8. LDFLAGS=-L$(CURRENTPATH)/src/core/dsalg \
  9. -L$(CURRENTPATH)/src/app

  10. LIBS+=-lapp -ldsalg
  11. export LIBS

  12. bin_PROGRAMS=main

  13. main_SOURCES=main.c
  14. #main_LDADD=$(CURRENTPATH)/src/core/dsalg/libdsalg.a $(CURRENTPATH)/src/app/libapp.a
  3. include/Makefile.am

点击(此处)折叠或打开

  1. SUBDIRS=core app
  4. include/app/Makefile.am

点击(此处)折叠或打开

  1. EXTRA_DIST=search_app.h sort_app.h
  5. include/app/search_app.h

点击(此处)折叠或打开

  1. #ifndef APPSEARCH_H
  2. #define APPSEARCH_H
  3. //int sch_compint(int* ,int*);
  4. int search_app(int arr[],int, int);
  5. #endif
  6. include/app/sort_app.h

点击(此处)折叠或打开

  1. #ifndef SORT_APP_H
  2. #define SORT_APP_H
  3. int sort_app(int arr[],int size);
  4. #endif
  7. include/app/stack_app.h
      空
 8. include/core/Makefile.am

点击(此处)折叠或打开

  1. SUBDIRS=dsalg global
  9. include/core/sort.h

点击(此处)折叠或打开

  1. #ifndef SORT_H
  2. #define SORT_H

  3. //排序元素类型定义
  4. typedef void* srt_elm_t;

  5. //排序元素比较操作定义
  6. typedef int (*fncomp_t)(const srt_elm_t, const srt_elm_t);


  7. /*******************
  8. 数组形式插入排序
  9. arr[]待排序数组
  10. n数组元素个数
  11. ********************/
  12. void insert_sort_a(srt_elm_t arr[], int n);

  13. #endif
  10. include/core/dsalg/Makefile.am

点击(此处)折叠或打开

  1. EXTRA_DIST=search.h sort.h list.h stack.h
  11. include/core/dsalg/list.h

点击(此处)折叠或打开

  1. #ifndef LIST_H
  2. #define LIST_H

  3. #endif
  12.  include/core/dsalg/search.h

点击(此处)折叠或打开

  1. #ifndef SEARCH_H
  2. #define SEARCH_H

  3. typedef int sch_elm_t;
  4. typedef int (*fncomp_sch_t)(const void*,const void*);

  5. int sch_compint(sch_elm_t *a, sch_elm_t *b);
  6. int linear_search(sch_elm_t tbl[],int n,sch_elm_t elm,fncomp_sch_t comp);
  7. int binary_search(sch_elm_t tbl[],int n,sch_elm_t elm,fncomp_sch_t comp);


  8. //int    seq_search(int *,int,int);
  9. //int    seq_rsearch(int *,int,int);
  10. #endif
  13.  include/core/dsalg/sort.h

点击(此处)折叠或打开

  1. #ifndef SORT_H
  2. #define SORT_H

  3. typedef    int    srt_elm_t;
  4. typedef int    (*fncmp_srt_t)(srt_elm_t *,srt_elm_t *);

  5. int    sort_compint(srt_elm_t *a, srt_elm_t *b);
  6. void    insert_sort(srt_elm_t tbl[],int n,fncmp_srt_t comp);

  7. #endif
14. include/core/dsalg/stack.h

点击(此处)折叠或打开

  1. #ifndef STACK_H
  2. #define STACK_H
  3. #define STCKSIZE 100
  4. typedef int stck_elm_t;
  5. typedef struct stck_cdt_t{
  6. int top;
  7. stck_elm_t buf[STCKSIZE];
  8. }stck_cdt_t;
  9. typedef struct stck_cdt_t* stck_adt_t;
  10. stck_adt_t NewStack(void);
  11. void DeletStack(stck_adt_t stack);
  12. void Push(stck_adt_t stack,stck_elm_t elm);
  13. stck_elm_t Pop(stck_adt_t stack);
  14. inline ubool StackIsEmpt(stck_adt_t stack);
  15. inline ubool StackIsFull(stck_adt_t stack);
  16. inline int StackDepth(stck_adt_t stack);
  17. inline stck_elm_t StackTop(stck_adt_t stack);
  18. #endif
  15. include/core/global/Makefile.am

点击(此处)折叠或打开

  1. EXTRA_DIST=pdef.h
  16. include/core/global/pdef.h

点击(此处)折叠或打开

  1. #ifndef _PDEF_H_
  2. #define _PDEF_H_
  3. #include
  4. typedef char int8;
  5. typedef short int16;
  6. typedef long int32;
  7. typedef unsigned char uint8;
  8. typedef unsigned short uint16;
  9. typedef unsigned long uint32;
  10. typedef float float32;
  11. typedef double double64;
  12. typedef unsigned long ubool;
  13. #ifndef FALSE
  14. #define FALSE 0x00
  15. #define TRUE 0x01
  16. #endif
  17. #define TABLE_SIZES(tbl) (sizeof(tbl) / sizeof(tbl[0]))
  18. #ifndef NDEBUG
  19. #define PTrace(fmt, arg...) (printf("%s--%d: " fmt, __FILE__, __LINE__, ##arg))
  20. #else
  21. #define PTrace(fmt, arg...)
  22. #endif
  23. #endif
  17. src/Makefile.am

点击(此处)折叠或打开

  1. SUBDIRS=core app
  18. src/app/Makefile.am

点击(此处)折叠或打开

  1. noinst_LIBRARIES=libapp.a
  2. libapp_a_SOURCES=search_app.c sort_app.c
  19. src/app/search.c

点击(此处)折叠或打开

  1. #include "search.h"
  2. #include "search_app.h"
  3. int search_app(int arr[],int size, int key)
  4. {
  5. return binary_search(arr,size,key,sch_compint);
  6. //return linear_search(arr,size,key,compint);
  7. }
  20. src/app/sort_app.c

点击(此处)折叠或打开

  1. #include "sort_app.h"

  2. static int sort_compint(int *a, int *b)
  3. {
  4.     return (*a-*b);
  5. }

  6. int sort_app(int arr[],int size)
  7. {
  8.     return insert_sort(arr,size,sort_compint);
  9. }
  21. src/app/stack_app.c
     空
 22. src/core/Makefile.am

点击(此处)折叠或打开

  1. SUBDIRS=dsalg
  23. src/core/dsalg/Makefile.am

点击(此处)折叠或打开

  1. noinst_LIBRARIES=libdsalg.a
  2. libdsalg_a_SOURCES=search.c sort.c list.c stack.c
  24. src/core/dsalg/list.c
   空
 25. src/core/dsalg/search.c

点击(此处)折叠或打开

  1. #include "search.h"

  2. int    sch_compint(sch_elm_t *a, sch_elm_t *b)
  3. {
  4.     return (*a-*b);
  5. }

  6. int linear_search(sch_elm_t tbl[],int n,sch_elm_t elm,fncomp_sch_t comp)
  7. {
  8.     int    i;

  9.     for(i=0;i<n;i++)
  10.         if(0==comp(&tbl[i],&elm))
  11.             return    i;
  12.     return    -1;
  13. }

  14. int binary_search(sch_elm_t tbl[],int n,sch_elm_t elm,fncomp_sch_t comp)
  15. {
  16.     int    min=0;
  17.     int    max=n;
  18.     int    mid;
  19.     int    ret;

  20.     while(min<=max)
  21.     {
  22.         mid=(int)(min+max)/2;
  23.         ret=comp(&tbl[mid],&elm);

  24.         if(0==ret)
  25.             return    mid;
  26.         else if(0>ret)
  27.             min=mid+1;
  28.         else
  29.             max=mid-1;
  30.     }        
  31.     return    -1;
  32. }
  26. src/core/dsalg/sort.c

点击(此处)折叠或打开

  1. #include "sort.h"

  2. int    sort_compint(srt_elm_t *a,srt_elm_t *b)
  3. {
  4.     return    (*a-*b);
  5. }

  6. void insert_sort(srt_elm_t tbl[],int n,fncmp_srt_t comp)
  7. {
  8.     int        i,j;
  9.     srt_elm_t    tmp;    

  10.     for(i=1;i<n;i++)
  11.     {
  12.         tmp=tbl[i];
  13.         for(j=i-1;j>=0;j--)
  14.         {
  15.             //if(comp(&tmp,&tbl[j])<0)    //if(tmp<tbl[j])
  16.             if(tmp<tbl[j])
  17.                 tbl[j+1]=tbl[j];
  18.             else
  19.                 break;
  20.         }
  21.         tbl[j+1]=tmp;
  22.     }
  23. }

  24. /*
  25. int    bubble_sort(srt_elm_t tbl[],int n,fncomp_srt_t comp)
  26. {
  27.     int    i;
  28.     
  29.     for(i=0;i<n-1;i++)
  30.     {
  31.         if(comp(tbl[i]),tbl[i+1]>0)
  32.         {
  33.         }
  34.     }
  35. }

  36. int    bubble(srt_elm_t tbl[],int n,fncomp_srt_t comp)
  37. {

  38.     for(i=0;i<n-1;i++)
  39.     {
  40.         
  41.     }
  42. }
  43. //select sort
  44. void    select_sort(srt_elm_t tbl[],int n,fncomp_srt_t comp)
  45. {
  46.     
  47. }

  48. static    int myselect(srt_elm_t tbl[],int n,fncomp_srt_t comp)
  49. {
  50. }
  51. //quick sort
  52. static    int split_first(srt_elm_t tbl[], int n, fncomp_srt_t comp)
  53. {
  54.     int    i=0,j=n;
  55.     
  56.     while(i<j)
  57.     {
  58.         while((i<n)&&(comp(&tbl[++i],&tbl[0])<0));
  59.         while(()&&(comp(&tbl[],&tbl[])));
  60.         if(i<j)
  61.             SWAP(tbl[i],tbl[j]);
  62.     }
  63. }


  64. void    quick_sort(srt_elm_t tbl[],int n, fncomp_srt_t comp)
  65. {
  66.     int pos=0;
  67.     
  68.     pos=split_first(tbl,n,comp)
  69.     
  70.     if(pos>1)
  71.         quick_sort(tbl,pos,comp);
  72.     if(pos<n-2)
  73.         quick_sort(&tbl[pos+1],n-1-pos,comp)
  74. }
  75. //merge sort
  76. static    void merge(srt_elm_t tbl[],int n, fncomp_srt_t comp)
  77. {
  78.     int    i=0,j=half;
  79.     int    k=0;
  80.     
  81.     srt_elm_t *pbuf=NULL;

  82.     pbuf=calloc(n,sizeof(srt_elm_t));
  83.     if(NULL!=pbuf)
  84.     {
  85.         
  86.     }

  87.     free(pbuf);
  88. }

  89. void    merge_sort(srt_elm_t tbl[],int n,fncomp_srt_t comp)
  90. {

  91. }
  92. */
  27. src/core/dsalg/stack.c

点击(此处)折叠或打开

  1. #include "pdef.h"
  2. #include "stack.h"

  3. //Creat new stack
  4. stck_adt_t    NewStack(void)
  5. {
  6.     stck_cdt_t *p;

  7.     p=malloc(sizeof(stck_cdt_t));
  8.     return    p;
  9. }
  10. //Delete stack
  11. void    DeletStack(stck_adt_t stack)
  12. {    
  13.     if(NULL!=stack)
  14.         free(stack);
  15. }
  16. //Push elm into stack
  17. void    Push(stck_adt_t stack,stck_elm_t elm)
  18. {
  19.     stack->buf[stack->top]=elm;
  20.     stack->top++;
  21. }
  22. //
  23. stck_elm_t    Pop(stck_adt_t stack)
  24. {
  25.     stack->top--;
  26.     return stack->buf[stack->top];

  27. }

  28. inline    ubool    StackIsEmpt(stck_adt_t stack)
  29. {    
  30.     return    (0==stack->top);
  31. }

  32. inline    ubool    StackIsFull(stck_adt_t stack)
  33. {
  34.     return    (stack->top==(STCKSIZE-1));
  35. }

  36. inline    int    StackDepth(stck_adt_t stack)
  37. {
  38.     return    stack->top;
  39. }
  40. inline    stck_elm_t    StackTop(stck_adt_t stack)
  41. {
  42.     return stack->buf[stack->top];
  43. }
共27个文件. 每个目录及子目录下均有Makefile.am文件.  是构建Makefile的关键

待续.
阅读(1198) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~