Skip to content

Commit fdd3b18

Browse files
committed
Update setup.py
merge linux and mac
1 parent 15a8dd0 commit fdd3b18

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

src/setup.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
numpy.__file__), "core", "include", "numpy")
1010
print(numpy_include)
1111

12+
setup_path = os.path.dirname(os.path.realpath(__file__))
13+
1214
# Customization for different platforms
1315
dbr_lib_dir = ''
1416
dbr_dll = ''
@@ -17,18 +19,39 @@
1719

1820
if sys.platform == "linux" or sys.platform == "linux2":
1921
# linux
20-
dbr_lib_dir = '/usr/lib'
22+
dbr_lib_dir = os.path.dirname(os.path.realpath(__file__))
2123
elif sys.platform == "darwin":
2224
# OS X
23-
dbr_lib_dir = '/usr/lib'
25+
dbr_lib_dir = os.path.dirname(os.path.realpath(__file__))
2426
pass
2527
elif sys.platform == "win32":
2628
# Windows
2729
dbr_lib_name = 'DBRx64'
2830
dbr_lib_dir = r'c:\Program Files (x86)\Dynamsoft\Barcode Reader 7.2.2\Components\C_C++\Lib'
2931
dbr_dll = r'c:\Program Files (x86)\Dynamsoft\Barcode Reader 7.2.2\Components\C_C++\Redist\x64'
32+
# dbr_lib_dir = r'..\Lib'
33+
# dbr_dll = r'..\bin'
34+
35+
if sys.platform == "linux" or sys.platform == "linux2":
36+
ext_args = dict(
37+
include_dirs = [numpy_include],
38+
library_dirs = [dbr_lib_dir],
39+
extra_compile_args = ['-std=c99'],
40+
extra_link_args = ["-Wl,-rpath=$ORIGIN"],
41+
libraries = [dbr_lib_name]
42+
)
43+
elif sys.platform == "darwin":
44+
ext_args = dict(
45+
include_dirs = [numpy_include],
46+
library_dirs = [dbr_lib_dir],
47+
extra_compile_args = ['-std=c99'],
48+
libraries = [dbr_lib_name]
49+
)
3050

31-
module_dbr = Extension('dbr', sources=['dbr.c'], include_dirs=[
51+
if sys.platform == "linux" or sys.platform == "linux2" or sys.platform == "darwin":
52+
module_dbr = Extension('dbr', ['dbr.c'], **ext_args)
53+
else:
54+
module_dbr = Extension('dbr', sources=['dbr.c'], include_dirs=[
3255
numpy_include], library_dirs=[dbr_lib_dir], libraries=[dbr_lib_name])
3356

3457

@@ -48,6 +71,14 @@ def run(self):
4871
shutil.copy2(dll, dst)
4972
else:
5073
shutil.copy2(src, dst)
74+
elif sys.platform == "linux" or sys.platform == "linux2":
75+
dst = get_python_lib()
76+
lib = setup_path + "/libDynamsoftBarcodeReader.so"
77+
os.system("cp {} {}".format(lib, dst))
78+
elif sys.platform == "darwin":
79+
dst = get_python_lib()
80+
lib = setup_path + "/libDynamsoftBarcodeReader.dylib"
81+
os.system("cp {} {}".format(lib, dst))
5182

5283

5384
setup(name='dbr',

0 commit comments

Comments
 (0)