Chinaunix首页 | 论坛 | 博客
  • 博客访问: 776438
  • 博文数量: 217
  • 博客积分: 2401
  • 博客等级: 大尉
  • 技术积分: 2030
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-16 06:58
个人简介

怎么介绍?

文章分类

全部博文(217)

文章存档

2023年(2)

2022年(3)

2021年(28)

2020年(12)

2019年(5)

2018年(5)

2017年(5)

2016年(3)

2015年(6)

2014年(12)

2013年(16)

2012年(9)

2011年(6)

2010年(15)

2009年(30)

2008年(59)

我的朋友

分类:

2010-06-19 03:42:17

Makefiles - Implicit or Suffix Rules

LeftRight

In earlier examples we either explicitly spelled out how each target is ``made'' from the prerequisites or relied on make magic to do the right thing.

This section looks into how to write and provide suffix rules, which are also called ``implicit rules''.

Writing your own rules frees the Makefile from being intimately dependent on any particular make or platform and can shorten Makefiles for large projects.

Suffix rules are, in a sense, generic rules for converting, say .c files to .o files.

Suffix rules are of the form:

s1s2 :
commands to get s2 from s1
Suffixes can be any string of characters, and by convention usually include a ``dot'' (.), but does not require it. The allowed suffixes are given by the .SUFFIXES fake target.

The following is a reworking of an earlier example with helpful comments:



CC = gcc
CFLAGS = -g
LD = $(CC)
LDFLAGS =
RM = rm

EXE = mainx
SRCS = main.c sub1.c sub2.c sub3.c
OBJS = ${SRCS:.c=.o}

# clear out all suffixes
.SUFFIXES:
# list only those we use
.SUFFIXES: .o .c

# define a suffix rule for .c -> .o
.c.o :
$(CC) $(CFLAGS) -c $<

# default target by convention is ``all''
all : $(EXE)

$(EXE) : $(OBJS)
$(LD) -o $@ $(OBJS)

$(OBJS) : proj.h

clean :
-$(RM) -f $(EXE) $(OBJS)


Strongly recommend that you write your own suffix rules for all those used within the software project. The need for this is demonstrated by the lack of consistency in macro names for the Fortran compiler shown in the last section.

However, if you are only using C and the associated tools (lex, yacc, ar, and ld) then the default macros and suffix rules are probably sufficient since they are fairly standard.

Looking at Predefined Rules and Macros

The following command will list the predefined rules and macros. The option ``-f'' tells make which Makefile to use, in this case /dev/null the empty file. The output is somewhat lengthy so it's a good idea to pipe it into a pager or into a file.
% make -p -f /dev/null
Looking at the predefined suffix rules are useful for composing your own and to observe which macros are used for each compiling tool.
阅读(914) | 评论(0) | 转发(0) |
0

上一篇:real player

下一篇:Makefile 2

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