Update to 2.0.0 tree from current Fremantle build
[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 if not os.path.exists('_ml_win32.cpp') or is_older('_ml_win32.cpp','_ml.cpp'):
58     patch_for_win32('_ml.cpp', '_ml_win32.cpp',
59         [('unsigned long long','uint64',),('long long','int64'),
60         ("char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);",
61         "char *doc = (char*)(((PyCFunctionObject *)obj) -> m_ml -> ml_doc);"),
62         ("char *c = methods[i].ml_doc;",
63         "char *c = (char*)methods[i].ml_doc;")],
64         [('PyAPI_FUNC','#undef PyAPI_FUNC\n')])
65
66
67 setup(name='OpenCV Python Wrapper',
68       version='0.0',
69       packages = ['opencv'],
70       package_dir = {'opencv': opencv_pwrap_dir},
71       ext_modules=[Extension('opencv._cv',
72                              [os.path.join (opencv_pwrap_dir, '_cv_win32.cpp'),
73                               os.path.join (opencv_pwrap_dir, 'error.cpp'),
74                               os.path.join (opencv_pwrap_dir, 'cvshadow.cpp'),
75                               os.path.join (opencv_pwrap_dir, 'pyhelpers.cpp')],
76                              include_dirs = [os.path.join (opencv_base_dir,
77                                                            'cv', 'include'),
78                                              os.path.join (opencv_base_dir,
79                                                            'cxcore', 'include'),
80                                                            ],
81                              library_dirs = [os.path.join (opencv_base_dir,
82                                                            'lib')],
83                              libraries = ['cv', 'cxcore'],
84                              ),
85
86                    Extension('opencv._ml',
87                              [os.path.join (opencv_pwrap_dir, '_ml_win32.cpp'),
88                               os.path.join (opencv_pwrap_dir, 'error.cpp'),
89                               os.path.join (opencv_pwrap_dir, 'cvshadow.cpp'),
90                               os.path.join (opencv_pwrap_dir, 'pyhelpers.cpp')],
91                              include_dirs = [os.path.join (opencv_base_dir,
92                                                            'cv', 'include'),
93                                              os.path.join (opencv_base_dir,
94                                                            'cxcore', 'include'),
95                                              os.path.join (opencv_base_dir,
96                                                            'ml', 'include'),
97                                              os.path.join (opencv_base_dir,
98                                                            'otherlibs', 'highgui'),
99                                                            ],
100                              library_dirs = [os.path.join (opencv_base_dir,
101                                                            'lib')],
102                              libraries = ['cv', 'cxcore', 'ml'],
103                              ),
104
105                    Extension('opencv._highgui',\r                             [os.path.join (opencv_pwrap_dir, '_highgui_win32.cpp'),
106                               os.path.join (opencv_pwrap_dir, 'error.cpp'),
107                               os.path.join (opencv_pwrap_dir, 'cvshadow.cpp'),
108                               os.path.join (opencv_pwrap_dir, 'pyhelpers.cpp')],
109                              include_dirs = [os.path.join (opencv_base_dir,
110                                                            'otherlibs', 'highgui'),
111                                              os.path.join (opencv_base_dir,
112                                                            'cxcore', 'include'),
113                                              os.path.join (opencv_base_dir,
114                                                            'cv', 'include')],
115                              library_dirs = [os.path.join (opencv_base_dir,
116                                                            'lib')],
117                              libraries = ['highgui', 'cv', 'cxcore'],
118                              )
119                    ]
120       )