[英]Makefile operations for each target
I want to write a makefile to process multiple targets with same operations. 我想编写一个makefile来用相同的操作处理多个目标。 For example, for one target called "quick_sort", my makefile starts as follows: 例如,对于一个名为“ quick_sort”的目标,我的makefile的启动过程如下:
TARGET = trapz
WRAPPER = $(TARGET)_wrap.cxx
SRC = $(TARGET).cc
MATRIXOBJ = vector.o vector_wrap.o matrix.o matrix_wrap.o matrix3d.o matrix3d_wrap.o
OBJ = $(SRC:.cc=.o) $(WRAPPER:.cxx=.o) $(MATRIXOBJ)
CXX = g++
CXXFLAGS = -O3 -fPIC
INTERFACE = $(TARGET).i
SWIGOPT =
SWIG = swig
PYLIB = -I/usr/include/python2.7
SO = so
python_cpp: $(TARGET).i
$(SWIG) -c++ -python $(INTERFACE)
$(CXX) $(CXXFLAGS) -c $(SRC)
$(CXX) $(CXXFLAGS) -c $(WRAPPER) $(PYLIB)
$(CXX) -shared $(OBJ) -o _$(TARGET).$(SO)
python_clean:
rm -f *_wrap* *.o *~ *$(SO) mypython *.pyc .~* core
But if I want to add multiple targets: 但是,如果我想添加多个目标:
TARGET = quick_sort bubble_sort standard_sort
WRAPPER = $(TARGET)_wrap.cxx
SRC = $(TARGET).cc
MATRIXOBJ = vector.o vector_wrap.o matrix.o matrix_wrap.o matrix3d.o matrix3d_wrap.o
OBJ = $(SRC:.cc=.o) $(WRAPPER:.cxx=.o) $(MATRIXOBJ)
It doesn't work. 没用 How can I generate all my executables without creating makefiles for each of my targets? 如何在不为每个目标创建makefile的情况下生成所有可执行文件?
TARGET := quick_sort bubble_sort standard_sort
MATRIXOBJ := vector.o vector_wrap.o matrix.o matrix_wrap.o matrix3d.o matrix3d_wrap.o
CXX := g++
CXXFLAGS := -O3 -fPIC
.PHONY: all $(TARGET)
all: $(TARGET)
$(TARGET): %: _%.so
_%.so: %_wrap.o %.o $(MATRIXOBJ) Makefile
$(CXX) -shared $(filter %.o, $^) -o $@
%_wrap.cxx: %.i Makefile
swig -c++ -python $<
%.o: %.cxx Makefile
$(CXX) $(CXXFLAGS) -c $< -I/usr/include/python2.7
%.o: %.cc Makefile
$(CXX) $(CXXFLAGS) -c $<
I added some good practices here. 我在这里添加了一些好的做法。 If you want a summary of good practices, read the "Ten Commandments" in my answer here: makefile enforce library dependency ordering 如果您想总结一个好的实践,请在我的答案中阅读“十诫”: makefile强制执行库依赖项排序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.