Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7553785
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: LINUX

2011-06-06 15:33:14

######################################

#

# Generic makefile

#

# by George Foot

# email: george.foot@merton.ox.ac.uk

#

# Copyright (c) 1997 George Foot

# All rights reserved.

#

# No warranty, no liability;

# you use this at your own risk.

#

# You are free to modify and

# distribute this without giving

# credit to the original author.

#

######################################

#

# Customizing

#

# Adjust the following if necessary; EXECUTABLE is the target

# executables filename, and LIBS is a list of libraries to link in

# (e.g. alleg, stdcx, iostr, etc). You can override these on makes

# command line of course, if you prefer to do it that way.

# EXECUTABLE为目标的可执行文件名,LIBS为需要连接的程序包列表,可以根据具体的项目对其进行修改。

#

EXECUTABLE := example

LIBS := xxx

# Now alter any implicit rules variables if you like, e.g.:

# 修改隐含规则中宏。

CC := gcc

CFLAGS := -Wall -O2 -MD

# You shouldnt need to change anything below this point.

# 下面内容基本上不需要修改。

# 列出工作目录下所有以“.c”结尾的文件,以空格分隔,将文件列表赋给变量SOURCE

SOURCE := $(wildcard *.c)

# 调用patsubst函数,生成与源文件对应的“.o”文件列表。

OBJS := $(patsubst %.c, %.o, $(SOURCE))

# 调用patsubst函数,生成与源文件对应的“.d”文件列表,关于“.d”文件后面会给出说明。

DEPS := $(patsubst %.o, %.d, $(OBJS))

# DEPS列表进行处理,删除所有已经存在的项目。

# 这里使用的函数为filter-out,该函数使用两个用空格分割的列表作为参数,其功能是删除第2个列表中所有

# 存在于第1列表的项目。

MISSING_DEPS := $(filter-out $(wildcard $(DEPS)), $(DEPS))

MISSING_DEPS_SOURCES := $(wildcard $(patsubst %.d, %.c, $(MISSING_DEPS)))

# 声明伪目标。

.PHONY : everything deps objs clean veryclean rebuild

# 更新可执行程序,并且为每一个源文件生成或更新一个“.o”文件和一个“.d”文件。

everything : $(EXECUTABLE)

# 为每一个源文件生成或更新一个“.d”文件。

deps : $(DEPS)

# 为每一个源文件生成或更新一个一个“.o”文件和一个“.d”文件。

objs : $(OBJS)

# 删除所有“.o”文件和“.d”文件。

# 命令前的“@”符号表示在执行make命令的时候,不显示这条命令。

clean :

    @rm -f *.o

    @rm -f *.d

# 完全删除,首先执行clean,然后再删除可执行文件。

veryclean : clean

    @rm -f $(EXECUTABLE)

# 完全重建,首先执行veryclean,然后执行everything

rebuild : veryclean everything

# Makefile文件中的条件语句。

ifneq ($(MISSING_DEPS),)

$(MISSING_DEPS) :

    @rm -f $(patsubst %.d,%.o,$@)

endif

-include $(DEPS)

# addprefix函数包含两个参数:文件前缀和列表,其功能是给文件列表的每一项添加一个前缀。

$(EXECUTABLE) : $(OBJS)

    gcc -o $(EXECUTABLE) $(OBJS) $(addprefix -l,$(LIBS))

 

阅读(1246) | 评论(0) | 转发(3) |
0

上一篇:make工具

下一篇:单目录通用Makefile

给主人留下些什么吧!~~