我有一个生成文件,然后调用另一个生成文件。因为这个makefile调用了更多的makefile来完成这项工作,所以它并没有真正改变。因此,它一直认为该项目是建立和最新的。

dnetdev11 ~ # make
make: `release' is up to date.

如何强制makefile重新构建目标?

clean = $(MAKE) -f ~/xxx/xxx_compile.workspace.mak clean


build = svn up ~/xxx                                                       \
        $(clean)                                                                \
        ~/cbp2mak/cbp2mak -C ~/xxx ~/xxx/xxx_compile.workspace        \
        $(MAKE) -f ~/xxx/xxx_compile.workspace.mak $(1)                    \


release:
        $(build )

debug:
        $(build DEBUG=1)

clean:
        $(clean)

install:
        cp ~/xxx/source/xxx_utility/release/xxx_util /usr/local/bin
        cp ~/xxx/source/xxx_utility/release/xxxcore.so /usr/local/lib

注:为保护无辜,删除姓名

最终固定版本:

clean = $(MAKE) -f xxx_compile.workspace.mak clean;


build = svn up;                                         \
        $(clean)                                        \
        ./cbp2mak/cbp2mak -C . xxx_compile.workspace;   \
        $(MAKE) -f xxx_compile.workspace.mak    $(1);   \


.PHONY: release debug clean install

release:
        $(call build,)

debug:
        $(call build,DEBUG=1)

clean:
        $(clean)

install:
        cp ./source/xxx_utillity/release/xxx_util /usr/bin
        cp ./dlls/Release/xxxcore.so /usr/lib

当前回答

这种简单的技术将允许makefile在不需要强制时正常运行。在makefile的末尾创建一个名为force的新目标。强制目标将触及默认目标所依赖的文件。在下面的例子中,我添加了touch myprogram.cpp。我还添加了一个要做的递归调用。这将导致每次输入make force时都会生成默认目标。

yourProgram: yourProgram.cpp
       g++ -o yourProgram yourProgram.cpp 

force:
       touch yourProgram.cpp
       make

其他回答

你可以宣布一个或多个目标是假的。

A phony target is one that is not really the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request. There are two reasons to use a phony target: to avoid a conflict with a file of the same name, and to improve performance. ... A phony target should not be a prerequisite of a real target file; if it is, its recipe will be run every time make goes to update that file. As long as a phony target is never a prerequisite of a real target, the phony target recipe will be executed only when the phony target is a specified goal

在我的Linux系统(Centos 6.2)上,当规则确实创建了一个匹配目标的文件时,在声明目标. phony和在FORCE上创建一个伪依赖项之间有一个显著的区别。当每次都必须重新生成文件时,两者都需要 文件上的伪依赖FORCE,以及伪依赖的. phony。

错误的:

date > $@

正确的:

FORCE
    date > $@
FORCE:
    .PHONY: FORCE

这实际上取决于目标是什么。如果它是一个伪目标(即目标与文件无关),你应该将它声明为. phony。

然而,如果目标不是伪目标,而只是出于某种原因想要重新构建它(例如当你使用__TIME__预处理宏时),你应该使用回答中描述的FORCE方案。

make的-B开关,其长形式为——always-make,告诉make忽略时间戳并使指定的目标。这可能会违背使用make的目的,但它可能正是您所需要的。

我试过了,对我很有效

将这些行添加到Makefile中

clean:
    rm *.o output

new: clean
    $(MAKE)     #use variable $(MAKE) instead of make to get recursive make calls

保存,然后调用

make new 

它会重新编译所有东西

发生了什么事?

1)“新”就是干净。 'clean' do 'rm'删除所有扩展名为'.o'的目标文件。

2)'new'调用'make'。 'make'看到没有'。O '文件,因此它创建了所有的'。o '了。然后链接器将所有.o文件链接到一个可执行输出中

祝你好运