文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Use makefile to manage large-scale project

Use makefile to manage large-scale project

时间:2009-08-08  来源:creatory

##Contents structure:
Calcu-1.0 ----- config.mk
          ----- makefile
          ----- README
          ----- header ------------------------- add_minus.h
                       ------------------------- divide_multi.h
          ----- source ----- makefile
                       ----- add_minus.c
                       ----- divide_multi.c
                       ----- calcu.c
##Content of files:
##config.mk
#General configure file for calcu
#You can setup which compiler you want to use.
#and some other control options.

#version,do not change
VERSION=1.0

#which compiler you what to use
CC=gcc

#the final ELF execute file name
FINAL=calcu

#optimize option
OPTIMIZE= -O2

#contanis source files directory
SRC=./source

#which directory you want to install this tool
DEST=/usr/local/bin

##makefile
include config.mk
all:
    cd $(SRC) && $(MAKE)
.phony clean:
clean:
    cd $(SRC) && $(MAKE) clean
.phony install:
install:
    cd $(SRC) && $(MAKE) install
.phony uninstall:
uninstall:
    cd $(SRC) && $(MAKE) uninstall

   
##README

                    Calcu V1.0 Reference

Calcu stands for Calculator,a small tools for your calculation.
Install it on default is very easy,type the following in the current directory,
[make]
[make install]
before doing this,be sure you've enough permissions.
The only way to hold all permissions on a system,change to root using su command.
If you want to control the install progress,please modify the config.mk file in this directory.
The commentary explains carefully to you.

Uninstall it:
Type the following command in a terminal in this directory
[make uninstall]

Caution:
    when you meet some mistakes,you've to recompile it using [make] command.Before doing that,please execute [make clean] to clean the temporary files.

Bugs-Report:[email protected]
Blog:http://creatory.cublog.cn
At Harbour Education in Beijing,Aug 6th,2009

//header/add_minus.h
//add_minus.h
//header file for add and minus function

int add(int i,int j);
int minus(int i,int j);

//header/divide_multi.h
//divide_mutli.h
//header  file for divide and multi function

int divide(int i,int j);
int multi(int i,int j);

//source/add_minus.c
//add_minus.c
//implement file for add and minus function
#include "../header/add_minus.h"
int add(int i,int j){
    return i+j;
}

int minus(int i,int j){
    return i-j;
}

//source/divide_multi.c
//divide_multi.c
//implement for divide and multi function
#include "../header/divide_multi.h"
int divide(int i,int j){
    return i/j;
}

int multi(int i,int j){
    return i*j;
}

//source/calcu.c
#include <stdio.h>
//#include "../header/add_minus.h"
//#include "../header/divide_multi.h"

/*extern int add(int,int);
extern int minus(int ,int);
extern int multi(int,int);
extern int divide(int,int);
*/
int main(void){
        int i,j;
        i=20;
        j=10;
        printf("i+j=%d\n",add(i,j));
        printf("i-j=%d\n",minus(i,j));
        printf("i*j=%d\n",multi(i,j));
        printf("i/j=%d\n",divide(i,j));
        return 0;
}

#source/makefile
include ../config.mk
$(FINAL):calcu.o add_minus.o divide_multi.o
    $(CC) $(OPTIMIZE)  $^  -o $@
    @echo  "Compile finished."
    @echo  "Now type 'make install' to install it."
calcu.o:calcu.c
    $(CC) $(OPTIMIZE) -c $^ -o $@
add_minus.o:add_minus.c
    $(CC) $(OPTIMIZE) -c $^ -o $@
divide_multi.o:divide_multi.c
    $(CC) $(OPTIMIZE) -c $^ -o $@
.phony clean:
clean:
    @echo "You want to clean the temp files.Please wait..."
    rm -rfv *.o $(FINAL)
    @echo "Clean finished."
.phony install:
install:
    @echo "installing..."
    cp $(FINAL) $(DEST)/$(FINAL)
    @echo "install finished."
.phony uninstall:
uninstall:
    @echo "uninstalling..."
    rm -f $(DEST)/$(FINAL)
    $(MAKE) clean
    @echo "uninstall finished."

Finally,use "tar" and "bzip2" to make a package:
tar cvfj Calcu-1.0.tar.bz2 Calcu-1.0
this action will generate a file named "Calcu-1.0.tar.bz2" in current directory.

author:[email protected]
modify time:08/08/2009 training time:08/06/2009
place:ZPark,Beijing,China
相关阅读 更多 +
排行榜 更多 +
动物大战僵尸I

动物大战僵尸I

飞行射击 下载
龙兽争霸无限零件图纸

龙兽争霸无限零件图纸

飞行射击 下载
金属战士2最新版

金属战士2最新版

飞行射击 下载