Skip to content

Commit f318b14

Browse files
committed
added windows support
1 parent 660c5d4 commit f318b14

1 file changed

Lines changed: 29 additions & 10 deletions

File tree

setup.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from os import getenv, environ
2+
import subprocess
23
import sys
34

45
from setuptools import setup, Extension, find_packages
56
from setuptools.command.build_ext import build_ext
67
import numpy
78

8-
libraries = ['usb-1.0', 'hackrf']
9+
libraries = ['hackrf']
910

1011
LIBHACKRF_FILES = ['python_hackrf/pylibhackrf/pyhackrf.pyx', 'python_hackrf/pylibhackrf/chackrf.pxd']
1112
PYHACKRF_TOOLS_FILES = ['python_hackrf/pyhackrf_tools/pyhackrf_sweep.pyx']
@@ -27,21 +28,39 @@
2728
cflags = environ.get('CFLAGS', '')
2829
ldflags = environ.get('LDFLAGS', '')
2930

30-
if PLATFORM == 'darwin':
31-
new_cflags = '-I/opt/homebrew/include/libusb-1.0 -I/opt/homebrew/include/libhackrf'
32-
new_ldflags = '-L/opt/homebrew/lib'
33-
elif PLATFORM.startswith('linux'):
34-
new_cflags = '-I/usr/include/libusb-1.0 -I/usr/include/libhackrf'
35-
new_ldflags = '-L/usr/lib64 -L/usr/lib'
31+
if PLATFORM in ('linux', 'darwin'):
32+
if environ.get('PYTHON_HACKRF_CFLAGS', None) is None:
33+
try:
34+
new_cflags = subprocess.check_output(['pkg-config', '--cflags', 'libhackrf']).decode('utf-8').strip()
35+
except Exception:
36+
new_cflags = ''
37+
else:
38+
new_cflags = environ.get('PYTHON_HACKRF_CFLAGS', '')
39+
40+
if environ.get('PYTHON_HACKRF_LDFLAGS', None) is None:
41+
try:
42+
new_ldflags = subprocess.check_output(['pkg-config', '--libs', 'libhackrf']).decode('utf-8').strip()
43+
except Exception:
44+
new_ldflags = ''
45+
else:
46+
new_ldflags = environ.get('PYTHON_HACKRF_LDFLAGS', '')
47+
3648
elif PLATFORM == 'win32':
37-
pass
49+
if environ.get('PYTHON_HACKRF_CFLAGS', None) is None:
50+
new_cflags = '/I"C:\\Program Files\\Hackrf\\include"'
51+
else:
52+
new_cflags = environ.get('PYTHON_HACKRF_CFLAGS', '')
53+
54+
if environ.get('PYTHON_HACKRF_LDFLAGS', None) is None:
55+
new_ldflags = '/LIBPATH"C:\\Program Files\\Hackrf\\lib"'
56+
else:
57+
new_ldflags = environ.get('PYTHON_HACKRF_LDFLAGS', '')
3858

3959
environ['CFLAGS'] = f'{cflags} {new_cflags}'.strip()
4060
environ['LDFLAGS'] = f'{ldflags} {new_ldflags}'.strip()
4161

4262
else:
43-
libraries = ['usb1.0', 'hackrf']
44-
LIBHACKRF_FILES = ['python_hackrf/pylibhackrf/pyhackrf_android.pyx', 'python_hackrf/pylibhackrf/chackrf_android.pxd', 'python_hackrf/pylibhackrf/hackrf.c']
63+
LIBHACKRF_FILES = ['python_hackrf/pylibhackrf/pyhackrf_android.pyx', 'python_hackrf/pylibhackrf/chackrf_android.pxd']
4564

4665
setup(
4766
name='python_hackrf',

0 commit comments

Comments
 (0)