如何强制make始终重建文件 [英] How to force make to always rebuild a file

查看:95
本文介绍了如何强制make始终重建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个version.c文件,其中包含项目的当前版本以及从makefile作为定义(-D编译器选项)传递的其他内容.

I have a version.c file in my project that contains current revision of the project and some other stuff that is passed as a definition (-D compiler option) from makefile.

我知道无论修改日期如何,总是强制使make编译version.c.

I know that to force make to compile version.c always regardless of modification date I can touch version.c.

是否只有makefile实现此目的?如果我写.PHONY : version.o,则目标文件根本无法构建.

Is there a makefile only way to achieve this? If I write .PHONY : version.o the object file doesn't get build at all.

这是我的makefile:

Here is my makefile:

export CC = gcc


export MODULES = $(sort \
     sys \
     cim \
     version \
)

export FILES = $(sort \
             main.c \
             cim.c \
             version.c \
)

VPATH = $(MODULES)

OBJS = $(FILES:.c=.o)

INCLUDES = $(addprefix -I,$(MODULES))

all:$(OBJS)
    $(CC) $(INCLUDES) $(OBJS) -o main.exe


clean:
    rm -rf *.o *.exe

cim.o: cim.c
main.o: main.c cim.o
version.o: version.c

.PHONY: version.o

.c.o :
    $(CC) $(CFLAGS) $(INCLUDES) -c $<

推荐答案

经典方法是:

version.o:   .FORCE

.FORCE:

(您可能会添加.PHONY: .FORCE).假定文件'.FORCE'不存在,所以它始终是'created',所以version.o总是过时,因此version.o总是被编译.

(and you might add .PHONY: .FORCE). The file '.FORCE' is presumed not to exist, so it is always 'created', so version.o is always out of date w.r.t it, so version.o is always compiled.

我不确定将version.o制成伪造文件是否正确;它实际上是一个真实的文件,而不是假的文件.

I'm not sure that making version.o into a phony file is correct; it is actually a real file, not a phony one.

这篇关于如何强制make始终重建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆