|
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 |
2 | 4 | TARGET = basic_interface |
3 | 5 |
|
4 | 6 | CFLAGS = -lm -pthread -O3 -std=c++11 -march=native -Wall -funroll-loops -Wno-unused-result |
| 7 | +osname := $(shell uname) |
5 | 8 |
|
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 |
10 | 10 | BOOST_INC = /usr/local/include/boost |
11 | 11 | BOOST_LIB = /usr/local/lib |
12 | 12 |
|
| 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 |
13 | 46 |
|
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) |
15 | 51 | 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 |
17 | 57 | else |
18 | 58 | BOOST = lboost_python |
19 | 59 | PYTHON_VERSION_FINAL = $(PYTHON_VERSION) |
20 | 60 | endif |
21 | 61 |
|
22 | 62 |
|
23 | 63 | $(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 |
25 | 65 |
|
26 | 66 | $(TARGET).o: $(TARGET).cpp |
27 | 67 | g++ $(CFLAGS) -I$(PYTHON_INCLUDE) -I$(BOOST_INC) -fPIC -c $(TARGET).cpp |
0 commit comments