0

If I have a Makefile as follows

server : network.o storage.o logic.o
    ld network.o storage.o logic.o -o server

network.o : network.c netdefs.h
    cc -c -o network.o network.c

storage.o : storage.c defs.h
    cc -c -o storage.o storage.c

logic.o : logic.c defs.h
    cc -c -o logic.o logic.c

.PHONY : promote clean reallyclean

promote : server
    cp server /staging/new_servers

clean : 
    rm -f *.o

reallyclean : clean
    rm -f server

And I do the following sequence of commands

make server # builds ther server from source
make clean  # tidies up the .o files
make promote # send the built server to the staging area

make, not unsurprisingly, re-builds the server from scratch, as the .o files are dependencies of server and are missing.

I do want this to happen if the server file itself is not there (there'd be nothing to promote otherwise) but if there is a server and no .o files then I want make to assume that the server is up-to-date and to promote it.

Is this achievable?

4

1 回答 1

0

啊,明白了!

使用 .SECONDARY 或 .INTERMEDIATE 标记所有我想忽略的中间体,例如添加:

.SECONDARY : network.o storage.o logic.o

(我已经尝试过这些,但在我的实际解决方案中,我有一个被忽略的中间体依赖于一个非忽略的中间体,所以 make 仍在重建所谓的被忽略的中间体,因此重建了服务器。)

于 2013-01-29T16:55:18.127 回答