Eclipse CDT MinGW - 跳过规则,没有这样的文件或目录错误

时间:2012-07-17 10:39:41

标签: makefile mingw

我正在尝试为项目创建调试和发布配置,而我无法弄清楚出了什么问题。

出于某种原因,当我'make debug'时,跳过'all'的依赖关系,给我一些来自g ++的错误(没有这样的文件或目录)。甚至更奇怪的是,如果我“全力以赴”,一切都运转正常。

这是makefile:

SHELL=/bin/sh
CXX=g++
LIBS=-LE:\Software\StrategyEngine\Release -llibdebug
CFLAGS=-Wall -O3 -IE:\Software\StrategyEngine\include

BDIR=Build\Release

debug: CFLAGS+=-g -DDEBUG
debug: LIBS=-LE:\Software\StrategyEngine\Debug -llibdebug
debug: BDIR=Build\Debug

OBJS= $(BDIR)\blocksort.o  \
      #... more object files
      $(BDIR)\CompressionStream.o

debug: all

all: $(OBJS) 
    $(CXX) $(LIBS) -shared -o $(BDIR)\libbz2.dll $(OBJS)
    $(CXX) $(LIBS) $(CFLAGS) -o $(BDIR)\bzip2-shared bzip2.cpp $(BDIR)\libbz2.dll

$(BDIR)\blocksort.o: blocksort.cpp
    $(CXX) $(CFLAGS) -c blocksort.cpp -o $(BDIR)\blocksort.o
#.... more rules for each object file defined in OBJS

clean: 
    rm -f Build\debug\* Build\release\*

为什么会这样?我在makefile中找不到任何错误。

我正在使用mingw编译器套件(制作版本3.81),在Windows 7上运行。

1 个答案:

答案 0 :(得分:2)

makefile中的目标文件位置BDIR不会因构建模式而改变。

我建议重构脚本如下:

SHELL=/bin/sh
CXX=g++

BUILD := debug # default mode

CFLAGS.release := -Wall -O3 -IE:/Software/StrategyEngine/include -D_NDEBUG
CFLAGS.debug   := -Wall -g  -IE:/Software/StrategyEngine/include -DDEBUG
LIBS.release := -LE:/Software/StrategyEngine/Release -llibdebug
LIBS.debug   := -LE:/Software/StrategyEngine/Debug -llibdebug
BDIR.release := Build/Release
BDIR.debug   := Build/Debug

CFLAGS := ${CFLAGS.${BUILD}}
LIBS := ${LIBS.${BUILD}}
BDIR := ${BDIR.${BUILD}}

OBJS= $(BDIR)/blocksort.o  /
      #... more object files
      $(BDIR)/CompressionStream.o

all: $(OBJS)
    $(CXX) $(LIBS) -shared -o $(BDIR)/libbz2.dll $(OBJS)
    $(CXX) $(LIBS) $(CFLAGS) -o $(BDIR)/bzip2-shared bzip2.cpp $(BDIR)/libbz2.dll

$(BDIR)/blocksort.o: blocksort.cpp
    $(CXX) $(CFLAGS) -c blocksort.cpp -o $(BDIR)/blocksort.o
#.... more rules for each object file defined in OBJS

clean:
    rm -f Build/debug/* Build/release/*

.PHONY: all clean 

并使用它:

make BUILD=debug
make BUILD=release