BPL BPL - 1 year ago 93
C++ Question

How to rebuild project after SWIG files changed?

Given the below makefile:

TARGET = _example.pyd
OFILES = example.obj example_wrap.obj

CC = cl
CXX = cl
LINK = link
CPPFLAGS = -DNDEBUG -DUNICODE -DWIN32 -I. -Id:\virtual_envs\py351\include
CFLAGS = -nologo -Zm200 -Zc:wchar_t- -FS -Zc:strictStrings -O2 -MD -W3 -w44456 -w44457 -w44458
CXXFLAGS = -nologo -Zm200 -Zc:wchar_t- -FS -Zc:strictStrings -D_HAS_EXCEPTIONS=0 -O2 -MD -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577
LIBS = /LIBPATH:d:\virtual_envs\py351\libs python35.lib
.SUFFIXES: .c .cpp .cc .cxx .C

$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -Fo @<<

$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -Fo @<<

$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -Fo @<<

$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -Fo @<<

$(CC) -c $(CFLAGS) $(CPPFLAGS) -Fo @<<

all: $(TARGET)


mt -nologo -manifest $(TARGET).manifest -outputresource:$(TARGET);2

install: $(TARGET)
@if not exist d:\virtual_envs\py351\Lib\site-packages mkdir d:\virtual_envs\py351\Lib\site-packages
copy /y $(TARGET) d:\virtual_envs\py351\Lib\site-packages\$(TARGET)

-del $(TARGET)
-del *.obj
-del *.exp
-del *.lib
-del $(TARGET).manifest

python runme.py

I'd like to improve a couple of things here:

  • I'd like to consider swig files (*.i) in the makefile. For example, every time some swig file has been changed a new wrap file should be generated (ie: swig -python -c++ file_has_changed.cpp) and then rebuild the project

  • I'd like to avoid having hardcoded object files. For instance, I'd like to use all cpp files using wildcards somehow

I've read a little bit of the docs talking about Makefiles but I'm still pretty much confused. How could I achieve this?

Right now I'm using a hacky solution like
swig -python -c++ whatever_file.i && nmake
, that's of course it's not ideal at all


Achieving this inside visual studio IDE is quite easy following these steps but I'd like to use this makefile inside SublimeText, that's why I'm quite interested on knowing how to have a proper Makefile

Answer Source

Producing any kind of target from any kind of source, that's the essence of a makefile:

    swig -python -c++ $<

This, however, will break with nmake (as opposed to GNU make) if the .cpp is missing because nmake refuses to look beyond a single link when trying to build a dependency tree.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download