带有make的隐式规则中的替代(或管道函数)(以保持源和二进制文件分离)

时间:2018-12-01 20:46:42

标签: c++ c gcc makefile compilation

我试图保留make的隐式规则,同时替换诸如$(SRC:%=$(SRCDIR)/%)之类的源路径,或者通过插入管道功能例如$(addprefix $SRCDIR/,$SRC)

我应该怎么做?

源文件(* cpp * c)位于src/中。

SRCDIR = src
HDRDIR = src/include
DDIR = src/d

.SUFFIXES = .o .cpp .c
.cpp.o:
    g++ -c $(CCFLAGS) $<
.c.o:
    gcc -c $(CFLAGS) $<
%.d: %.cpp
    set -e; $(CC) -MM $(CPPFLAGS) $< \
       | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; [ -s $@ ] || rm -f $@
%.d: %.c
    set -e; gcc -MM $(CPPFLAGS) $< \
       | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; [ -s $@ ] || rm -f $@

TESTHNF_CPP_SRCS = testhnf.cpp timings.cpp LongModular.cpp VeryLong.cpp VeryLongModular.cpp squfof.cpp
C_SRCS = mt19937int.c lip.c
include $(TESTHNF_CPP_SRCS:%.cpp=$(DDIR)/%.d)
include $(C__SRCS:%.c=$(DDIR)/%.d)
TESTHNF_OBJS = $(TESTHNF_CPP_SRCS:%.cpp=$(OBJDIR)/%.o) $(C_SRCS:%.c=$(OBJDIR)/%.o)

testhnf: $(TARGETDIR) $(TARGETDIR)/testhnf
$(TARGETDIR)/testhnf: $(TESTHNF_OBJS)
    $(CC) $(CCFLAGS) -o $(TARGETDIR)/testhnf $(TESTHNF_OBJS) $(LIBS)
cleantesthnf:
    rm -rf $(TARGETDIR)/testhnf $(TESTHNF_OBJS)

0 个答案:

没有答案