Move the sources to trunk
[opencv] / interfaces / swig / python / setup-for-win.py
1 from distutils.core import setup, Extension\rimport os
2 opencv_pwrap_dir = r'.'
3 opencv_base_dir = r'../../..'
4
5 def patch_for_win32(filename,outfile,patches,extra_defs):
6     print 'patching '+filename+'...'
7     src = open(filename,'rt')
8     dst = open(outfile, 'wt')
9     for l in src.xreadlines():
10         dl = l
11         for (from_str,to_str) in patches:
12             dl = dl.replace(from_str,to_str)
13         for i in extra_defs:
14             if l.find(i[0]) >= 0:
15                 dst.write(i[1])
16                 extra_defs.remove(i)
17         dst.write(dl)
18     src.close()
19     dst.close()
20
21 def is_older(a,b):
22     return os.path.getmtime(a)<os.path.getmtime(b)
23
24 if not os.path.exists('_cv_win32.cpp') or is_older('_cv_win32.cpp','_cv.cpp'):
25     patch_for_win32('_cv.cpp', '_cv_win32.cpp',
26         [('unsigned long long','uint64',),('long long','int64'),
27         ("char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);",
28         "char *doc = (char*)(((PyCFunctionObject *)obj) -> m_ml -> ml_doc);"),
29         ("char *c = methods[i].ml_doc;",
30         "char *c = (char*)methods[i].ml_doc;")],
31         [('PyAPI_FUNC','#undef PyAPI_FUNC\n'), ('cv.h',
32 """
33 #include "cv.h"
34
35 const signed char icvDepthToType[]=
36 {
37     -1, -1, CV_8U, CV_8S, CV_16U, CV_16S, -1, -1,
38     CV_32F, CV_32S, -1, -1, -1, -1, -1, -1, CV_64F, -1
39 };
40
41 CvModuleInfo* CvModule::first = 0;
42 CvModuleInfo* CvModule::last = 0;
43 CvTypeInfo* CvType::first = 0;
44 CvTypeInfo* CvType::last = 0;
45
46 """)])
47
48 if not os.path.exists('_highgui_win32.cpp') or is_older('_highgui_win32.cpp','_highgui.cpp'):
49     patch_for_win32('_highgui.cpp', '_highgui_win32.cpp',
50         [('unsigned long long','uint64',),('long long','int64'),
51         ("char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);",
52         "char *doc = (char*)(((PyCFunctionObject *)obj) -> m_ml -> ml_doc);"),
53         ("char *c = methods[i].ml_doc;",
54         "char *c = (char*)methods[i].ml_doc;")],
55         [('PyAPI_FUNC','#undef PyAPI_FUNC\n')])
56
57 setup(name='OpenCV Python Wrapper',
58       version='0.0',
59       packages = ['opencv'],
60       package_dir = {'opencv': opencv_pwrap_dir},
61       ext_modules=[Extension('opencv._cv',
62                              [os.path.join (opencv_pwrap_dir, '_cv_win32.cpp'),
63                               os.path.join (opencv_pwrap_dir, 'error.cpp'),
64                               os.path.join (opencv_pwrap_dir, 'cvshadow.cpp'),
65                               os.path.join (opencv_pwrap_dir, 'pyhelpers.cpp')],
66                              include_dirs = [os.path.join (opencv_base_dir,
67                                                            'cv', 'include'),
68                                              os.path.join (opencv_base_dir,
69                                                            'cxcore', 'include'),
70                                                            ],
71                              library_dirs = [os.path.join (opencv_base_dir,
72                                                            'lib')],
73                              libraries = ['cv', 'cxcore'],
74                              ),
75
76                    Extension('opencv._highgui',\r                             [os.path.join (opencv_pwrap_dir, '_highgui_win32.cpp'),
77                               os.path.join (opencv_pwrap_dir, 'error.cpp'),
78                               os.path.join (opencv_pwrap_dir, 'cvshadow.cpp'),
79                               os.path.join (opencv_pwrap_dir, 'pyhelpers.cpp')],
80                              include_dirs = [os.path.join (opencv_base_dir,
81                                                            'otherlibs', 'highgui'),
82                                              os.path.join (opencv_base_dir,
83                                                            'cxcore', 'include'),
84                                              os.path.join (opencv_base_dir,
85                                                            'cv', 'include')],
86                              library_dirs = [os.path.join (opencv_base_dir,
87                                                            'lib')],
88                              libraries = ['highgui', 'cv', 'cxcore'],
89                              )
90                    ]
91       )