Skip to content

Commit ce2b4b4

Browse files
committed
Mac OS support
1 parent a37a1d4 commit ce2b4b4

File tree

21 files changed

+936
-146
lines changed

21 files changed

+936
-146
lines changed

Examples/basic_interface/makefile

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,67 @@
1-
PYTHON_VERSION = 3.5
1+
# default PTRHON_VERSION is 3.6 on Mac, 3.5 in other os
2+
# if you installed other python version, Please specific your Python Version below
3+
PYTHON_VERSION = None
24
TARGET = basic_interface
35

46
CFLAGS = -lm -pthread -O3 -std=c++11 -march=native -Wall -funroll-loops -Wno-unused-result
7+
osname := $(shell uname)
58

6-
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
7-
8-
# Only need if install from source
9-
9+
# Only need to change if you install boost-python from source
1010
BOOST_INC = /usr/local/include/boost
1111
BOOST_LIB = /usr/local/lib
1212

13+
# $(info $$osname is [${osname}])
14+
15+
# if PYTHON_VERSION not set, set default PYTHON_VERSION
16+
ifeq ($(osname), Darwin)
17+
EXPORT_DYNAMIC_NAME = export_dynamic
18+
ifeq ($(PYTHON_VERSION), None)
19+
PYTHON_VERSION = 3.6
20+
endif
21+
else
22+
EXPORT_DYNAMIC_NAME = -export-dynamic
23+
ifeq ($(PYTHON_VERSION), None)
24+
PYTHON_VERSION = 3.5
25+
endif
26+
endif
27+
28+
$(eval REMAINDER := $$$(PYTHON_VERSION))
29+
FIRST := $(subst $(REMAINDER),,$(PYTHON_VERSION))
30+
31+
# set default PYTHON_INCLUDE and LIBPYTHON_PATH for different os
32+
# PYTHON_INCLUDE should be the path contain pyconfig.h
33+
# LIBPYTHON_PATH should be the path contain libpython3.6 or libpython3.5 or libpython2.7 or whichever your python version
34+
ifeq ($(osname), Darwin)
35+
ifeq ($(FIRST), 3)
36+
PYTHON_INCLUDE = /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/include/python3.6m/
37+
LIBPYTHON_PATH = /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/
38+
else
39+
PYTHON_INCLUDE = /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/include/python2.7/
40+
LIBPYTHON_PATH = /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/
41+
endif
42+
else
43+
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
44+
LIBPYTHON_PATH = /usr/lib/python$(PYTHON_VERSION)/config
45+
endif
1346

14-
ifeq ($(PYTHON_VERSION), 3.5)
47+
# boost python lib, on mac, default is lboost_python for python2.x, lboost_python3 for python3.x
48+
# on ubuntu, name ===> python3.5m
49+
# on mac, name ===> python3.6
50+
ifeq ($(FIRST), 3)
1551
BOOST = lboost_python3
16-
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
52+
ifeq ($(osname), Darwin)
53+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
54+
else
55+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
56+
endif
1757
else
1858
BOOST = lboost_python
1959
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
2060
endif
2161

2262

2363
$(TARGET).so: $(TARGET).o
24-
g++ $(CFLAGS) -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
64+
g++ $(CFLAGS) -shared -Wl,-$(EXPORT_DYNAMIC_NAME) $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L$(LIBPYTHON_PATH) -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
2565

2666
$(TARGET).o: $(TARGET).cpp
2767
g++ $(CFLAGS) -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp

Examples/basic_interface/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class X(list):
44
def __init__(self, *args, **kwargs):
5-
super().__init__(*args, **kwargs)
5+
super(X, self).__init__(*args, **kwargs)
66

77
def __setattr__(self, name, value):
88
self.__dict__[name] = value

Examples/call_policies/makefile

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,67 @@
1-
PYTHON_VERSION = 3.5
1+
# default PTRHON_VERSION is 3.6 on Mac, 3.5 in other os
2+
# if you installed other python version, Please specific your Python Version below
3+
PYTHON_VERSION = None
24
TARGET = call_policies
35

46
CFLAGS = -lm -pthread -O3 -std=c++11 -march=native -Wall -funroll-loops -Wno-unused-result
7+
osname := $(shell uname)
58

6-
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
7-
8-
# Only need if install from source
9-
9+
# Only need to change if you install boost-python from source
1010
BOOST_INC = /usr/local/include/boost
1111
BOOST_LIB = /usr/local/lib
1212

13+
# $(info $$osname is [${osname}])
14+
15+
# if PYTHON_VERSION not set, set default PYTHON_VERSION
16+
ifeq ($(osname), Darwin)
17+
EXPORT_DYNAMIC_NAME = export_dynamic
18+
ifeq ($(PYTHON_VERSION), None)
19+
PYTHON_VERSION = 3.6
20+
endif
21+
else
22+
EXPORT_DYNAMIC_NAME = -export-dynamic
23+
ifeq ($(PYTHON_VERSION), None)
24+
PYTHON_VERSION = 3.5
25+
endif
26+
endif
27+
28+
$(eval REMAINDER := $$$(PYTHON_VERSION))
29+
FIRST := $(subst $(REMAINDER),,$(PYTHON_VERSION))
30+
31+
# set default PYTHON_INCLUDE and LIBPYTHON_PATH for different os
32+
# PYTHON_INCLUDE should be the path contain pyconfig.h
33+
# LIBPYTHON_PATH should be the path contain libpython3.6 or libpython3.5 or libpython2.7 or whichever your python version
34+
ifeq ($(osname), Darwin)
35+
ifeq ($(FIRST), 3)
36+
PYTHON_INCLUDE = /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/include/python3.6m/
37+
LIBPYTHON_PATH = /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/
38+
else
39+
PYTHON_INCLUDE = /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/include/python2.7/
40+
LIBPYTHON_PATH = /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/
41+
endif
42+
else
43+
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
44+
LIBPYTHON_PATH = /usr/lib/python$(PYTHON_VERSION)/config
45+
endif
1346

14-
ifeq ($(PYTHON_VERSION), 3.5)
47+
# boost python lib, on mac, default is lboost_python for python2.x, lboost_python3 for python3.x
48+
# on ubuntu, name ===> python3.5m
49+
# on mac, name ===> python3.6
50+
ifeq ($(FIRST), 3)
1551
BOOST = lboost_python3
16-
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
52+
ifeq ($(osname), Darwin)
53+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
54+
else
55+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
56+
endif
1757
else
1858
BOOST = lboost_python
1959
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
2060
endif
2161

2262

2363
$(TARGET).so: $(TARGET).o
24-
g++ $(CFLAGS) -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
64+
g++ $(CFLAGS) -shared -Wl,-$(EXPORT_DYNAMIC_NAME) $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L$(LIBPYTHON_PATH) -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
2565

2666
$(TARGET).o: $(TARGET).cpp
2767
g++ $(CFLAGS) -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp

Examples/class_hello/makefile

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,67 @@
1-
PYTHON_VERSION = 3.5
1+
# default PTRHON_VERSION is 3.6 on Mac, 3.5 in other os
2+
# if you installed other python version, Please specific your Python Version below
3+
PYTHON_VERSION = None
24
TARGET = class_hello
35

46
CFLAGS = -lm -pthread -O3 -std=c++11 -march=native -Wall -funroll-loops -Wno-unused-result
7+
osname := $(shell uname)
58

6-
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
7-
8-
# Only need if install from source
9+
# Only need to change if you install boost-python from source
910
BOOST_INC = /usr/local/include/boost
1011
BOOST_LIB = /usr/local/lib
1112

13+
# $(info $$osname is [${osname}])
14+
15+
# if PYTHON_VERSION not set, set default PYTHON_VERSION
16+
ifeq ($(osname), Darwin)
17+
EXPORT_DYNAMIC_NAME = export_dynamic
18+
ifeq ($(PYTHON_VERSION), None)
19+
PYTHON_VERSION = 3.6
20+
endif
21+
else
22+
EXPORT_DYNAMIC_NAME = -export-dynamic
23+
ifeq ($(PYTHON_VERSION), None)
24+
PYTHON_VERSION = 3.5
25+
endif
26+
endif
27+
28+
$(eval REMAINDER := $$$(PYTHON_VERSION))
29+
FIRST := $(subst $(REMAINDER),,$(PYTHON_VERSION))
30+
31+
# set default PYTHON_INCLUDE and LIBPYTHON_PATH for different os
32+
# PYTHON_INCLUDE should be the path contain pyconfig.h
33+
# LIBPYTHON_PATH should be the path contain libpython3.6 or libpython3.5 or libpython2.7 or whichever your python version
34+
ifeq ($(osname), Darwin)
35+
ifeq ($(FIRST), 3)
36+
PYTHON_INCLUDE = /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/include/python3.6m/
37+
LIBPYTHON_PATH = /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/
38+
else
39+
PYTHON_INCLUDE = /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/include/python2.7/
40+
LIBPYTHON_PATH = /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/
41+
endif
42+
else
43+
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
44+
LIBPYTHON_PATH = /usr/lib/python$(PYTHON_VERSION)/config
45+
endif
1246

13-
ifeq ($(PYTHON_VERSION), 3.5)
47+
# boost python lib, on mac, default is lboost_python for python2.x, lboost_python3 for python3.x
48+
# on ubuntu, name ===> python3.5m
49+
# on mac, name ===> python3.6
50+
ifeq ($(FIRST), 3)
1451
BOOST = lboost_python3
15-
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
52+
ifeq ($(osname), Darwin)
53+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
54+
else
55+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
56+
endif
1657
else
1758
BOOST = lboost_python
1859
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
1960
endif
2061

2162

2263
$(TARGET).so: $(TARGET).o
23-
g++ $(CFLAGS) -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
64+
g++ $(CFLAGS) -shared -Wl,-$(EXPORT_DYNAMIC_NAME) $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L$(LIBPYTHON_PATH) -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
2465

2566
$(TARGET).o: $(TARGET).cpp
2667
g++ $(CFLAGS) -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp

Examples/class_member/makefile

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,67 @@
1-
PYTHON_VERSION = 3.5
1+
# default PTRHON_VERSION is 3.6 on Mac, 3.5 in other os
2+
# if you installed other python version, Please specific your Python Version below
3+
PYTHON_VERSION = None
24
TARGET = class_member
35

46
CFLAGS = -lm -pthread -O3 -std=c++11 -march=native -Wall -funroll-loops -Wno-unused-result
7+
osname := $(shell uname)
58

6-
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
7-
8-
# Only need if install from source
9+
# Only need to change if you install boost-python from source
910
BOOST_INC = /usr/local/include/boost
1011
BOOST_LIB = /usr/local/lib
1112

13+
# $(info $$osname is [${osname}])
14+
15+
# if PYTHON_VERSION not set, set default PYTHON_VERSION
16+
ifeq ($(osname), Darwin)
17+
EXPORT_DYNAMIC_NAME = export_dynamic
18+
ifeq ($(PYTHON_VERSION), None)
19+
PYTHON_VERSION = 3.6
20+
endif
21+
else
22+
EXPORT_DYNAMIC_NAME = -export-dynamic
23+
ifeq ($(PYTHON_VERSION), None)
24+
PYTHON_VERSION = 3.5
25+
endif
26+
endif
27+
28+
$(eval REMAINDER := $$$(PYTHON_VERSION))
29+
FIRST := $(subst $(REMAINDER),,$(PYTHON_VERSION))
30+
31+
# set default PYTHON_INCLUDE and LIBPYTHON_PATH for different os
32+
# PYTHON_INCLUDE should be the path contain pyconfig.h
33+
# LIBPYTHON_PATH should be the path contain libpython3.6 or libpython3.5 or libpython2.7 or whichever your python version
34+
ifeq ($(osname), Darwin)
35+
ifeq ($(FIRST), 3)
36+
PYTHON_INCLUDE = /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/include/python3.6m/
37+
LIBPYTHON_PATH = /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/
38+
else
39+
PYTHON_INCLUDE = /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/include/python2.7/
40+
LIBPYTHON_PATH = /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/
41+
endif
42+
else
43+
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
44+
LIBPYTHON_PATH = /usr/lib/python$(PYTHON_VERSION)/config
45+
endif
1246

13-
ifeq ($(PYTHON_VERSION), 3.5)
47+
# boost python lib, on mac, default is lboost_python for python2.x, lboost_python3 for python3.x
48+
# on ubuntu, name ===> python3.5m
49+
# on mac, name ===> python3.6
50+
ifeq ($(FIRST), 3)
1451
BOOST = lboost_python3
15-
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
52+
ifeq ($(osname), Darwin)
53+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
54+
else
55+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
56+
endif
1657
else
1758
BOOST = lboost_python
1859
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
1960
endif
2061

2162

2263
$(TARGET).so: $(TARGET).o
23-
g++ $(CFLAGS) -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
64+
g++ $(CFLAGS) -shared -Wl,-$(EXPORT_DYNAMIC_NAME) $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L$(LIBPYTHON_PATH) -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
2465

2566
$(TARGET).o: $(TARGET).cpp
2667
g++ $(CFLAGS) -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp

Examples/class_property/makefile

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,67 @@
1-
PYTHON_VERSION = 3.5
1+
# default PTRHON_VERSION is 3.6 on Mac, 3.5 in other os
2+
# if you installed other python version, Please specific your Python Version below
3+
PYTHON_VERSION = None
24
TARGET = class_property
35

46
CFLAGS = -lm -pthread -O3 -std=c++11 -march=native -Wall -funroll-loops -Wno-unused-result
7+
osname := $(shell uname)
58

6-
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
7-
8-
# Only need if install from source
9+
# Only need to change if you install boost-python from source
910
BOOST_INC = /usr/local/include/boost
1011
BOOST_LIB = /usr/local/lib
1112

13+
# $(info $$osname is [${osname}])
14+
15+
# if PYTHON_VERSION not set, set default PYTHON_VERSION
16+
ifeq ($(osname), Darwin)
17+
EXPORT_DYNAMIC_NAME = export_dynamic
18+
ifeq ($(PYTHON_VERSION), None)
19+
PYTHON_VERSION = 3.6
20+
endif
21+
else
22+
EXPORT_DYNAMIC_NAME = -export-dynamic
23+
ifeq ($(PYTHON_VERSION), None)
24+
PYTHON_VERSION = 3.5
25+
endif
26+
endif
27+
28+
$(eval REMAINDER := $$$(PYTHON_VERSION))
29+
FIRST := $(subst $(REMAINDER),,$(PYTHON_VERSION))
30+
31+
# set default PYTHON_INCLUDE and LIBPYTHON_PATH for different os
32+
# PYTHON_INCLUDE should be the path contain pyconfig.h
33+
# LIBPYTHON_PATH should be the path contain libpython3.6 or libpython3.5 or libpython2.7 or whichever your python version
34+
ifeq ($(osname), Darwin)
35+
ifeq ($(FIRST), 3)
36+
PYTHON_INCLUDE = /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/include/python3.6m/
37+
LIBPYTHON_PATH = /usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/
38+
else
39+
PYTHON_INCLUDE = /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/include/python2.7/
40+
LIBPYTHON_PATH = /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/
41+
endif
42+
else
43+
PYTHON_INCLUDE = /usr/include/python$(PYTHON_VERSION)
44+
LIBPYTHON_PATH = /usr/lib/python$(PYTHON_VERSION)/config
45+
endif
1246

13-
ifeq ($(PYTHON_VERSION), 3.5)
47+
# boost python lib, on mac, default is lboost_python for python2.x, lboost_python3 for python3.x
48+
# on ubuntu, name ===> python3.5m
49+
# on mac, name ===> python3.6
50+
ifeq ($(FIRST), 3)
1451
BOOST = lboost_python3
15-
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
52+
ifeq ($(osname), Darwin)
53+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
54+
else
55+
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)m
56+
endif
1657
else
1758
BOOST = lboost_python
1859
PYTHON_VERSION_FINAL = $(PYTHON_VERSION)
1960
endif
2061

2162

2263
$(TARGET).so: $(TARGET).o
23-
g++ $(CFLAGS) -shared -Wl,--export-dynamic $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L/usr/lib/python$(PYTHON_VERSION)/config -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
64+
g++ $(CFLAGS) -shared -Wl,-$(EXPORT_DYNAMIC_NAME) $(TARGET).o -L$(BOOST_LIB) -$(BOOST) -L$(LIBPYTHON_PATH) -lpython$(PYTHON_VERSION_FINAL) -o $(TARGET).so
2465

2566
$(TARGET).o: $(TARGET).cpp
2667
g++ $(CFLAGS) -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp

0 commit comments

Comments
 (0)