2014-01-08 112 views
0

我是Mac OS新手,想要執行以下makefile程序。這被在Mac OS執行mac OS上的Makefile命令顯示不正確的輸出

GCCBASE = $(GCMDIR)/where/cplusplus/gcc 
SRCS:=$(wildcard *.cpp) program.cpp 
OBJS:=$(SRCS:.cpp=$(OBJDIR).o) 
INCLUDES:=-I. -I$(ADD_INCLUDES)/Auto*.h -I$(ADD_INCLUDES)/program.h 
OUTBASE =$(OUTBASE_EX) 
OUT_ARTIFACT=Program 

ifeq ($(OSNAME),Linux) 
    ifeq ($(GFLIB_MODEL),64bit) 
      CXXEXTRA_FLAGS = -m64 
      GCCDIR = $(GCCBASE)/linux64/4.5.3 
      GCCLIBDIR_W = $(GCCBASE)/linux64/4.5.3/lib64 
      GCCLIBDIR = $(GCCLIBDIR_W)     
      CFLAGS_common += -I$(GCCBASE)/linux64/4.5.3/include 
      OUTDIR = $(OUTBASE)/64 
      CFLAGS_link_libs = -L$(GCCLIBDIR) -lmyLib     
    else 
      CXXEXTRA_FLAGS = -m32 
      GCCDIR = $(GCCBASE)/linux/4.5.3 
      GCCLIBDIR_W = $(GCCBASE)/linux/4.5.3/lib 
      GCCLIBDIR = $(GCCLIBDIR_W) 
      CFLAGS_common += -I$(GCCBASE)/linux/4.5.3/include 
      OUTDIR = $(OUTBASE)/32 
    CFLAGS_link_libs = -L$(GCCLIBDIR) -lmyLib     
endif 
endif 
ifeq ($(OSNAME),Darwin) 
echo "Mac OS" 
    ifeq ($(GFLIB_MODEL),64bit) 
      CXXEXTRA_FLAGS = -m64 
      GCCDIR = $(GCCBASE)/macosx/4.8.1 
      GCCLIBDIR_W = $(GCCBASE)/macosx/4.8.1/lib 
      GCCLIBDIR = $(GCCLIBDIR_W)    
      CFLAGS_common += -I$(GCCBASE)/macosx/4.8.1/include 
      OUTDIR = $(OUTBASE)/64 
      CFLAGS_link_libs = -L$(GCCLIBDIR) -lmyLib     
    else 
      CXXEXTRA_FLAGS = -m32 
      GCCDIR = $(GCCBASE)/macosx/4.8.1 
      GCCLIBDIR_W = $(GCCBASE)/macosx/4.8.1/lib/i386 
      GCCLIBDIR = $(GCCLIBDIR_W) 
      CFLAGS_common += -I$(GCCBASE)/macosx/4.8.1/include 
      OUTDIR = $(OUTBASE)/32 
    CFLAGS_link_libs = -L$(GCCLIBDIR) -lmyLib     
endif 
endif 
all: $(SRCS) 
    echo "Building Program application..." 
    $(CXX) $(CXXEXTRA_FLAGS) $(CFLAGS_common) $(INCLUDES) $^ -o $(OUTDIR)/$(OUT_ARTIFACT) $(CFLAGS_link_libs)   
    rm -f *.[o] *.log core 

命令看起來是這個鏈接錯誤,因爲MYLIB未發現:

[exec] c++ -I. -IAuto*.h -IProgram.h Program.cpp -o /Program 

雖然我期待我的命令是這樣的:

[exec] c++ -m32 -I. -IAuto*.h -IProgram.h Program.cpp -o /Program -LmyPath -lmyLib 

爲什麼我的命令不包括-m32和鏈接庫路徑?

我也試過打印CXXEXTRA_FLAGS和CFLAGS_link_libs,但它們都是空的。

回答

2

您從不將變量OSNAMEGFLIB_MODEL設置爲此生成文件中的任何值,因此它們都是空的。因此,既不OSNAME測試的是真實的,這些值永遠不會在CXXEXTRA_FLAGS設置等

ETA:這是基於您的註釋的例子:

$ cat Makefile 
ifeq ($(OSTYPE),Mac OS X) 
    $(info got mac) 
endif 

all: ; @: 

$ make 

$ make OSTYPE=Mac 

$ make OSTYPE='Mac OS X' 
got mac 
+0

感謝MadScintist:如果我傳遞OSNAME是「Mac OS X」代替「Darwin」,我如何在makefile中比較它。 ifeq($(OSNAME),Darwin)應該換成什麼? – user3082802

+0

顯而易見的'ifeq($(OSNAME),Mac OS X)'不起作用嗎? – MadScientist

+0

不,它不適合我,任何改變空間分隔的詞,可能是? – user3082802

相關問題