How to rebuild a project after changing SWIG files?

Given the following makefile:

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

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
LFLAGS = /LIBPATH:. /NOLOGO /DYNAMICBASE /NXCOMPAT /DLL /MANIFEST /MANIFESTFILE:$(TARGET).manifest /SUBSYSTEM:WINDOWS /INCREMENTAL:NO
LIBS = /LIBPATH:d:\virtual_envs\py351\libs python35.lib
.SUFFIXES: .c .cpp .cc .cxx .C


{.}.cpp{}.obj::
    $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -Fo @<<
    $<
<<

{.}.cc{}.obj::
    $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -Fo @<<
    $<
<<

{.}.cxx{}.obj::
    $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -Fo @<<
    $<
<<

{.}.C{}.obj::
    $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) -Fo @<<
    $<
<<

{.}.c{}.obj::
    $(CC) -c $(CFLAGS) $(CPPFLAGS) -Fo @<<
    $<
<<

all: $(TARGET)

$(OFILES): $(HFILES)

$(TARGET): $(OFILES)
    $(LINK) $(LFLAGS) /OUT:$(TARGET) @<<
      $(OFILES) $(LIBS)
<<
    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)

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

test:
    python runme.py

I would like to improve a couple of things here:

  • I would like to examine the swig files (* .i) in the makefile. For example, every time a certain swig file has been modified, a new migration file should be generated (i.e.: swig -python -C ++ file_has_changed.cpp), and then rebuild the project
  • I would like to avoid having hardcoded object files. For example, I would like to use all cpp files using wildcards somehow

I read a few documents talking about Makefiles , but I'm still very confused. How could I achieve this?

Now I am using a hacker solution, such as swig -python -c++ whatever_file.i && nmakethat, of course, it is not perfect at all

BIBLIOGRAPHY

IDE , make SublimeText, Makefile

+4
2

, make :

.i.cpp:
    swig -python -c++ $<

, , nmake ( GNU make), .cpp , nmake .
, "" , ( ), .

kludges ( nmake, ):

  • nmake, , ( , , , ),

    • script, make . .: Makefile main_makefile Makefile , :

      python -c "import os,os.path,subprocess;
                 subprocess.check_call(['nmake', '/F', 'main_makefile']
                     +[os.path.splitext(f)[0]+'.cpp'
                       for f in os.listdir('.') if os.path.isfile(f)
                                                   and f.endswith('.i')])"
      nmake /F main_makefile
      
  • , .cpp, (, CMake btw)

    • , Makefile . !INCLUDE 'd, , , , nmake . ( , Python):

      import os,os.path,subprocess
      for f in os.listdir('.') if os.path.isfile(f) and f.endswith('.i'):
          print '"%s": "%s"'%(os.path.splitext(f)[0]+'.cxx',f)
          #quotes are to allow for special characters,
          # see https://msdn.microsoft.com/en-us/library/956d3677.aspx
          #command is not needed, it will be added from the inferred rule I gave
          # in the beginning, see http://www.darkblue.ch/programming/Namke.pdf, p.41 (567)
      
+3

CMake, autoconf automake makefiles.

,

DEPENDENCIES = `swig -M -python -c++ -I. example.i | sed 's/\//g'`

. .i, SWIG.

+1

Source: https://habr.com/ru/post/1656573/


All Articles