2012-08-14 9 views
14

メイクファイルの一部として、ターゲットのデバッグバージョンまたはリリースバージョンを生成したいと考えています。 makeを実行するときターゲットのコマンドをオーバーライドしてファイルを警告します。

機能的には、すべてが、しかし、私は取得しています警告が取り組んでいる

12 SRC := $(shell echo src/*.cpp) 
13 SRC += $(shell echo $(TEST_ROOT)/*.cpp) 
14 
15 D_OBJECTS = $(SRC:.cpp=.o)  # same objects will need to be built differently 
16 R_OBJECTS = $(SRC:.cpp=.o)  # same objects will need to be built differently 

22 all: $(TARGET) 
23 
25 $(TARGET): $(D_OBJECTS) 
26 $(CC) $(D_OBJECTS) -o $(TARGET) 
27 
28 $(D_OBJECTS) : %.o: %.cpp      # ----- run with debug flags 
29 $(CC) $(COMMON_FLAGS) $(DEBUG_FLAGS) -c $< -o [email protected] 
30 
31 release: $(R_OBJECTS) 
32 $(CC) $(R_OBJECTS) -o $(TARGET) 
33 
34 $(R_OBJECTS) : %.o: %.cpp      # ----- run with release flags 
35 $(CC) $(COMMON_FLAGS) $(RELEASE_FLAGS) -c $< -o [email protected] 

make私はデバッグバージョンを取得

、私 make release私は、リリースバージョンを取得するとき。

しかし、私はまた、取得警告:

この2つの質問では
Makefile:35: warning: overriding commands for target `src/Timer.o' 
Makefile:29: warning: ignoring old commands for target `src/Timer.o' 
Makefile:35: warning: overriding commands for target `test/TimerTest.o' 
Makefile:29: warning: ignoring old commands for target `test/TimerTest.o' 

  1. 警告
  2. を無視する方法は私は正しいことをやっていますか?どのような変更が必要ですか?

答えて

10

これを実行する最も一般的な方法の1つは、リリースオブジェクトとデバッグオブジェクトを別々のサブディレクトリに配置することです。こうすることで、オブジェクトのルールの定義を変更することはできません。オブジェクトの名前が異なるためです。これのようなもの:

D_OBJECTS=$(SRC:%.cpp=debug/%.o) 
R_OBJECTS=$(SRC:%.cpp=release/%.o) 

RTARGET = a.out 
DTARGET = a.out.debug 

all : dirs $(RTARGET) 

debug : dirs $(DTARGET) 

dirs : 
    @mkdir -p debug release 

debug/%.o : %.c 
    $(CC) $(DEBUG_CFLAGS) -o [email protected] -c $< 

release/%.o : %.c 
    $(CC) $(RELEASE_CFLAGS) -o [email protected] -c $< 

$(DTARGET) : $(D_OBJECTS) 
    $(CC) $(DEBUG_CFLAGS) -o [email protected] $(D_OBJECTS) 

$(RTARGET) : $(R_OBJECTS) 
    $(CC) $(RELEASE_CFLAGS) -o [email protected] $(R_OBJECTS) 
+1

あなたは、Makefileを自動生成するnetbeansでこれを行う方法を知っていますか? –

+0

複数のバイナリに同じコードがある場合はライブラリを作成する – baptx

関連する問題