开发者

How to use different values for CC depending on goal in gnumake

I have one code base that I'd like to use to make two different "goals" One required that I compile with g++ (we use gtest for a unit test target), the other needs gcc4 our deleivered code is ANSI C.

I'm trying to use the target specific variables of gnu make to acheive this

so I have

unit_test_target: CC=g++
unit_test_target: unit_test_pre-reqs
    recipe

and

lab_target:CC=gcc开发者_运维问答4
lab_target: lab_pre_reqs
    recipe

The CC variable does not seem to get used in making the pre-reqs which I have found an explanation for. But I'm not seeing how to achieve this.

Thanks in advance

Collins

More details...

TESTSUBDIRS = dir1 dir1/testing dir2 dir2/testing

.PHONY: testsubdirs $(TESTSUBDIRS)

testsubdirs : $(TESTSUBDIRS)

$(TESTSUBDIRS) : objdir

$(MAKE) -e -C $@

objdir: $(CSPLATFORMDIR)/makebuilddir

$(CSPLATFORMDIR)/makebuilddir $(BUILDDIR)

LAB4DIRS = dir1 dir2

.PHONY: t100lab4dirs $(LAB4DIRS)

lab4dirs : $(LAB4DIRS)

$(T100LAB4SDIRS) : objdir

$(MAKE) -e -C $@

gtest: CC=g++

gtest: $(CSPLATFORMDIR)/makebuilddir $(TESTSUBDIRS)

$(CSPLATFORMDIR)/makebuilddir $(BUILDDIR)

$(AR) -r $(TARGET) $(OBJS)

ls -l $(TARGET)

g++ -I$(BUILDDIR)/.. -I$(BUILDDIR)../../inc -I$(GTESTINC) $(BUILDDIR)/*.o -lpthread $(GTESTDIR)/make/gtest_main.a -o $(BUILDDIR)/gtest

lab_target.a:CC=gcc4

lab_target.a: $(CSPLATFORMDIR)/makebuilddir $(T100LAB4DIRS)

$(CSPLATFORMDIR)/makebuilddir $(BUILDDIR)

$(AR) -r $(TARGET) $(OBJS)

ls -l $(TARGET)


You can use GNU make if conditionals to set variables, but not based on targets. This is normally solved by having the target that needs to use C++ to use $(CXX) as the compiler, and targets that need to use C use$(CC). Then set those separate variables appropriately. I think that's also the best way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜