-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpicosat.patch
181 lines (181 loc) · 5.86 KB
/
picosat.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
diff -Naur picosat-960/configure picosat.patched/configure
--- picosat-960/configure 2014-10-26 11:03:30.000000000 +0100
+++ picosat.patched/configure 2015-03-04 11:02:52.914498551 +0100
@@ -79,6 +79,7 @@
*wine*|*mingw*) CFLAGS="-DNGETRUSAGE -DNALLSIGNALS";;
*);;
esac
+ CFLAGS="$CFLAGS -fPIC"
[ $log = yes ] && CFLAGS="$CFLAGS -DLOGGING"
[ $stats = yes ] && CFLAGS="$CFLAGS -DSTATS"
[ $trace = yes ] && CFLAGS="$CFLAGS -DTRACE"
diff -Naur picosat-960/picosat_python.i picosat.patched/picosat_python.i
--- picosat-960/picosat_python.i 1970-01-01 01:00:00.000000000 +0100
+++ picosat.patched/picosat_python.i 2015-03-04 11:46:44.022432617 +0100
@@ -0,0 +1,38 @@
+/* -*- swig -*- */
+/* SWIG interface file to create the Python API for PicoSAT */
+/* author: Andrea Micheli <[email protected]> */
+
+%include "typemaps.i"
+
+/***************************************************************************/
+
+/* EXTRA_SWIG_CODE_TAG */
+
+%module picosat
+%{
+#include "picosat.h"
+/* EXTRA_C_INCLUDE_TAG */
+%}
+
+%include "picosat.h"
+/* EXTRA_SWIG_INCLUDE_TAG */
+
+%{
+
+/* EXTRA_C_STATIC_CODE_TAG */
+
+%}
+
+
+%inline %{
+
+/* EXTRA_C_INLINE_CODE_TAG */
+
+%}
+
+
+%pythoncode %{
+
+## EXTRA_PYTHON_CODE_TAG
+
+%}
diff -Naur picosat-960/setup.py picosat.patched/setup.py
--- picosat-960/setup.py 1970-01-01 01:00:00.000000000 +0100
+++ picosat.patched/setup.py 2015-03-04 10:48:06.538520763 +0100
@@ -0,0 +1,124 @@
+#!/usr/bin/env python
+
+import os, sys
+import optparse
+import subprocess
+import tempfile
+from distutils.core import setup, Extension
+import distutils.ccompiler
+
+def msg(s):
+ sys.stdout.write(s)
+ sys.stdout.write('\n')
+ sys.stdout.flush()
+
+p = optparse.OptionParser('%prog [options] [-- [setup_options]]')
+p.add_option('--extra-swig-code', help='file with extra SWIG code')
+p.add_option('--extra-c-include-code', help='file with extra C headers')
+p.add_option('--extra-swig-include-code',
+ help='file with extra SWIG include directives')
+p.add_option('--extra-c-static-code', help='file with extra C static code')
+p.add_option('--extra-c-inline-code', help='file with extra C inline code')
+p.add_option('--extra-python-code', help='file with extra Python code')
+p.add_option('--extra-compile-args', help='extra compilation args', default="")
+p.add_option('--extra-link-args', help='extra link args', default="")
+p.add_option('--extra-libraries', help='extra libraries', default="")
+p.add_option('--swig-only', help='only run SWIG '
+ '(do not compile generated bindings)', action='store_true')
+p.add_option('--swig-tool', help='custom path to the swig executable')
+p.add_option('--extra-include-dir', help='extra include directories',
+ action='append', default=[])
+p.add_option('--extra-lib-dir', help='extra library directories',
+ action='append', default=[])
+
+try:
+ idx = sys.argv.index('--')
+ optargs = sys.argv[1:idx]
+ argv = sys.argv[idx+1:]
+except ValueError:
+ optargs, argv = sys.argv[1:], []
+sys.argv = [sys.argv[0]] + argv
+
+def error(msg):
+ sys.stderr.write(msg)
+ sys.stderr.write('\n')
+ p.print_help(sys.stderr)
+ sys.exit(-1)
+
+opts, args = p.parse_args(optargs)
+
+if args:
+ sys.argv = [sys.argv[0]] + args + sys.argv[1:]
+
+
+
+with open(os.path.join(os.path.dirname(__file__), 'picosat_python.i')) as f:
+ swigdata = f.read()
+
+def inject(data, tag, filenames):
+ if filenames:
+ if not isinstance(filenames, list):
+ filenames = [filenames]
+
+ d = ""
+ for filename in filenames:
+ with open(filename) as f:
+ d += f.read()
+ data = data.replace(tag, d)
+ return data
+
+
+swigdata = inject(swigdata, '/* EXTRA_SWIG_CODE_TAG */', opts.extra_swig_code)
+swigdata = inject(swigdata, '/* EXTRA_C_INCLUDE_TAG */',
+ opts.extra_c_include_code)
+swigdata = inject(swigdata, '/* EXTRA_SWIG_INCLUDE_TAG */',
+ opts.extra_swig_include_code)
+swigdata = inject(swigdata, '/* EXTRA_C_STATIC_CODE_TAG */',
+ opts.extra_c_static_code)
+swigdata = inject(swigdata, '/* EXTRA_C_INLINE_CODE_TAG */',
+ opts.extra_c_inline_code)
+swigdata = inject(swigdata, '## EXTRA_PYTHON_CODE_TAG', opts.extra_python_code)
+
+msg("Generating Python wrapper with SWIG...")
+swig = 'swig'
+if opts.swig_tool:
+ swig = opts.swig_tool
+
+
+fd, swigfile = tempfile.mkstemp('.c')
+out = os.fdopen(fd, 'w')
+out.write(swigdata)
+out.close()
+
+swig_cmd = [swig, '-I.', '-python', '-o',
+ 'picosat_python_wrap.c'] + \
+ ['-I%s' % p for p in opts.extra_include_dir] + [swigfile]
+msg(' '.join(swig_cmd))
+p = subprocess.Popen(swig_cmd)
+p.communicate()
+if os.path.exists(swigfile):
+ os.unlink(swigfile)
+
+if p.returncode == 0 and not opts.swig_only:
+ incdirs = ["./"] + opts.extra_include_dir
+ libdirs = ["./"] + opts.extra_lib_dir
+ msg("Compiling the extension module...")
+ extra_compile_args = opts.extra_compile_args.split()
+ if distutils.ccompiler.get_default_compiler() == 'unix':
+ extra_compile_args += ['-Wno-unused', '-Wno-uninitialized']
+ extra_link_args = opts.extra_link_args.split()
+ libraries = opts.extra_libraries.split() + ['picosat']
+ if sys.platform == 'win32':
+ libraries.append('psapi')
+ setup(name='picosat', version='0.1',
+ description='PicoSAT API',
+ ext_modules=[Extension('_picosat', ['picosat_python_wrap.c'],
+ define_macros=[('SWIG','1')],
+ include_dirs=incdirs,
+ library_dirs=libdirs,
+ extra_compile_args=extra_compile_args,
+ extra_link_args=extra_link_args,
+ libraries=libraries,
+ language='c',
+ )]
+ )