mac OS上的Makefile命令显示输出错误

时间:2014-01-08 11:33:28

标签: linux macos makefile gnu-make

我是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

在mac OS上执行的命令与链接器错误类似,因为找不到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,但它们都是空的。

1 个答案:

答案 0 :(得分:2)

您永远不会将变量OSNAMEGFLIB_MODEL设置为此makefile中的任何值,因此它们都是空的。因此,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