I’m trying to make a module that takes .cpp and .swg files as input and creates a .so file using SWIG. The trouble is, I don’t know much about makefiles, and I’m not quite sure exactly what I’m doing wrong. Here is my makefile:
CXX = g++
SWIG = swig
SWIGFLAGS = -c++ -python
CXXFLAGS = -c -fpic -Wall #for debugging purposes
LDFLAGS = -shared
file_processor.so: %*.o
$(CXX) $(LDFLAGS) $^
%.o: %.cxx %.cpp
$(CXX) $(CXXFLAGS) $? -o $@
%.cxx: %.swg
$(SWIG) $(SWIGFLAGS) $<
When I run this, make says:
make: *** No rule to make target `%*.o', needed by `file_processor.so'. Stop.
What exactly am I doing wrong? Can anyone suggest a better way to accomplish what I’m trying to do?
1) The default rule:
As written, this requires a prerequisite called “%*.o”, which Make can neither find nor build. I think you meant this:
but then Make would pull in all existing
.ofiles — and not worry if any were missing. I recommend:2) The object rule:
This rule won’t apply unless both prerequisites exist, which doesn’t seem to be what you have in mind. You’ll have to split it into two rules:
(Pattern rules don’t work quite the same way as ordinary rules.)
3) Small correction:
Did you mean
file_processor_wrap.swg? The flow doesn’t make sense otherwise, since you’d be buildingfile_processor.cxxbut never using it.