-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Makefile and project structure improvements
- BBB renamed to SPIDEV - SPIDEV - support for spidev device specification by RF24 constructor - LittleWire support unified with other supported linux devices - configure script introduced for auto detection/configuration - support for cross compilation including library upload/installation to a remote host - examples_RPi renamed to examples_linux - Python wrapper - preparation for cross compiling support
- Loading branch information
1 parent
970309d
commit 3b13827
Showing
32 changed files
with
394 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,95 @@ | ||
############################################################################# | ||
# | ||
# Makefile for librf24-bcm on Raspberry Pi | ||
# Makefile for librf24 | ||
# | ||
# License: GPL (General Public License) | ||
# Author: Charles-Henri Hallard | ||
# Date: 2013/03/13 | ||
# | ||
# Description: | ||
# ------------ | ||
# use make all and mak install to install the library | ||
# You can change the install directory by editing the LIBDIR line | ||
# use make all and make install to install the library | ||
# | ||
PREFIX=/usr/local | ||
|
||
# Library parameters | ||
# where to put the lib | ||
LIBDIR=$(PREFIX)/lib | ||
# lib name | ||
LIB=librf24-bcm | ||
# shared library name | ||
LIBNAME=$(LIB).so.1.0 | ||
ifeq ($(wildcard Makefile.inc), ) | ||
$(error Configuration not found. Run ./configure first) | ||
endif | ||
|
||
# Where to put the header files | ||
HEADER_DIR=${PREFIX}/include/RF24 | ||
include Makefile.inc | ||
|
||
# The base location of support files for different devices | ||
ARCH_DIR=utility | ||
|
||
ARCH=armv6zk | ||
ifeq "$(shell uname -m)" "armv7l" | ||
ARCH=armv7-a | ||
endif | ||
|
||
# The default objects to compile | ||
OBJECTS=RF24.o spi.o | ||
|
||
SHARED_LINKER_FLAGS=-shared -Wl,-soname,$@.so.1 | ||
|
||
|
||
|
||
# Detect the Raspberry Pi from cpuinfo | ||
# Allow users to override the use of BCM2835 driver and force use of SPIDEV by specifying " sudo make install -B RF24_SPIDEV=1 " | ||
ifeq "$(RF24_SPIDEV)" "1" | ||
RPI=0 | ||
else | ||
#Count the matches for BCM2708 or BCM2709 in cpuinfo | ||
RPI=$(shell cat /proc/cpuinfo | grep Hardware | grep -c BCM2708) | ||
ifneq "${RPI}" "1" | ||
RPI=$(shell cat /proc/cpuinfo | grep Hardware | grep -c BCM2709) | ||
endif | ||
# Objects to compile | ||
OBJECTS=RF24.o | ||
ifeq ($(DRIVER), MRAA) | ||
OBJECTS+=spi.o gpio.o compatibility.o | ||
else ifeq ($(DRIVER), RPi) | ||
OBJECTS+=spi.o bcm2835.o interrupt.o | ||
else ifeq ($(DRIVER), SPIDEV) | ||
OBJECTS+=spi.o gpio.o compatibility.o | ||
endif | ||
|
||
ifeq "$(RF24_MRAA)" "1" | ||
SHARED_LINKER_FLAGS+=-lmraa | ||
DRIVER_DIR=$(ARCH_DIR)/MRAA | ||
OBJECTS+=gpio.o compatibility.o | ||
|
||
else ifeq "$(RPI)" "1" | ||
DRIVER_DIR=$(ARCH_DIR)/RPi | ||
OBJECTS+=bcm2835.o | ||
OBJECTS+=interrupt.o | ||
SHARED_LINKER_FLAGS+=-pthread | ||
# The recommended compiler flags for the Raspberry Pi | ||
CCFLAGS=-Ofast -mfpu=vfp -mfloat-abi=hard -march=$(ARCH) -mtune=arm1176jzf-s | ||
|
||
else | ||
DRIVER_DIR=$(ARCH_DIR)/BBB | ||
OBJECTS+=gpio.o compatibility.o interrupt.o | ||
SHARED_LINKER_FLAGS+=-pthread | ||
endif | ||
|
||
|
||
# make all | ||
# reinstall the library after each recompilation | ||
all: test librf24-bcm | ||
all: $(LIBNAME) | ||
|
||
test: | ||
cp ${DRIVER_DIR}/includes.h $(ARCH_DIR)/includes.h | ||
# Make the library | ||
librf24-bcm: $(OBJECTS) | ||
g++ ${SHARED_LINKER_FLAGS} ${CCFLAGS} -o ${LIBNAME} $^ | ||
|
||
$(LIBNAME): $(OBJECTS) | ||
@echo "[Linking]" | ||
${CC} ${SHARED_LINKER_FLAGS} ${CFLAGS} -o ${LIBNAME} $^ | ||
|
||
# Library parts | ||
RF24.o: RF24.cpp | ||
g++ -Wall -fPIC ${CCFLAGS} -c $^ | ||
${CXX} -Wall -fPIC ${CFLAGS} -c $^ | ||
|
||
bcm2835.o: $(DRIVER_DIR)/bcm2835.c | ||
gcc -Wall -fPIC ${CCFLAGS} -c $^ | ||
${CC} -Wall -fPIC ${CFLAGS} -c $^ | ||
|
||
spi.o: $(DRIVER_DIR)/spi.cpp | ||
g++ -Wall -fPIC ${CCFLAGS} -c $^ | ||
${CXX} -Wall -fPIC ${CFLAGS} -c $^ | ||
|
||
compatibility.o: $(DRIVER_DIR)/compatibility.c | ||
gcc -Wall -fPIC ${CCFLAGS} -c $(DRIVER_DIR)/compatibility.c | ||
${CC} -Wall -fPIC ${CFLAGS} -c $(DRIVER_DIR)/compatibility.c | ||
|
||
gpio.o: $(DRIVER_DIR)/gpio.cpp | ||
g++ -Wall -fPIC ${CCFLAGS} -c $(DRIVER_DIR)/gpio.cpp | ||
${CXX} -Wall -fPIC ${CFLAGS} -c $(DRIVER_DIR)/gpio.cpp | ||
|
||
interrupt.o: $(DRIVER_DIR)/interrupt.c | ||
g++ -Wall -fPIC ${CCFLAGS} -c $(DRIVER_DIR)/interrupt.c | ||
${CXX} -Wall -fPIC ${CFLAGS} -c $(DRIVER_DIR)/interrupt.c | ||
|
||
# clear build files | ||
clean: | ||
rm -rf *.o ${LIB}.* | ||
@echo "[Cleaning]" | ||
rm -rf *.o ${LIBNAME}.* | ||
|
||
install: all install-libs install-headers | ||
upload: all upload-libs upload-headers | ||
|
||
# Install the library to LIBPATH | ||
install-libs: | ||
install-libs: | ||
@echo "[Installing Libs]" | ||
@if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi | ||
@install -m 0755 ${LIBNAME} ${LIBDIR} | ||
@ln -sf ${LIBDIR}/${LIBNAME} ${LIBDIR}/${LIB}.so.1 | ||
@ln -sf ${LIBDIR}/${LIBNAME} ${LIBDIR}/${LIB}.so | ||
@ldconfig | ||
@install -m 0755 ${LIBNAME} ${LIB_DIR} | ||
@ln -sf ${LIB_DIR}/${LIBNAME} ${LIB_DIR}/${LIBNAME}.1 | ||
# @${LDCONFIG} | ||
|
||
upload-libs: | ||
@echo "[Uploading Libs to ${REMOTE}]" | ||
@ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "mkdir -p ${REMOTE_LIB_DIR}" | ||
@scp -q -P ${REMOTE_PORT} ${LIBNAME} ${REMOTE}:/tmp | ||
@ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "sudo install -m 0755 /tmp/${LIBNAME} ${REMOTE_LIB_DIR} && rm /tmp/${LIBNAME} && sudo ln -sf ${REMOTE_LIB_DIR}/${LIBNAME} ${REMOTE_LIB_DIR}/${LIBNAME}.1 && sudo ldconfig" | ||
|
||
install-headers: | ||
@echo "[Installing Headers]" | ||
@if ( test ! -d ${HEADER_DIR} ) ; then mkdir -p ${HEADER_DIR} ; fi | ||
@mkdir -p ${HEADER_DIR}/${DRIVER_DIR} | ||
@install -m 0644 *.h ${HEADER_DIR} | ||
@if ( test ! -d ${HEADER_DIR}/${DRIVER_DIR} ) ; then mkdir -p ${HEADER_DIR}/${DRIVER_DIR} ; fi | ||
@install -m 0644 ${DRIVER_DIR}/*.h ${HEADER_DIR}/${DRIVER_DIR} | ||
@install -m 0644 ${ARCH_DIR}/*.h ${HEADER_DIR}/${ARCH_DIR} | ||
|
||
upload-headers: | ||
@echo "[Uploading Headers to ${REMOTE}]" | ||
@ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "sudo mkdir -p ${REMOTE_HEADER_DIR}/${DRIVER_DIR}" | ||
@ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "mkdir -p /tmp/RF24 && rm -rf /tmp/RF24/*" | ||
@rsync -a --include="*.h" --include="*/" --exclude="*" -e "ssh -p ${REMOTE_PORT}" . ${REMOTE}:/tmp/RF24 | ||
@ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "sudo install -m 0644 /tmp/RF24/*.h ${REMOTE_HEADER_DIR}" | ||
@ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "sudo install -m 0644 /tmp/RF24/${DRIVER_DIR}/*.h ${REMOTE_HEADER_DIR}/${DRIVER_DIR}" | ||
@ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "sudo install -m 0644 /tmp/RF24/${ARCH_DIR}/*.h ${REMOTE_HEADER_DIR}/${ARCH_DIR}" | ||
@ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "rm -rf /tmp/RF24" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import sys | ||
from distutils import unixccompiler | ||
from distutils import ccompiler | ||
|
||
|
||
def register(): | ||
sys.modules['distutils.crossunixccompiler'] = sys.modules[__name__] | ||
ccompiler.compiler_class['crossunix'] = (__name__, | ||
'CrossUnixCCompiler', | ||
'UNIX-style compiler for cross compilation') | ||
|
||
|
||
def try_remove_all(lst, starts): | ||
lst[:] = [x for x in lst if not x.startswith(starts)] | ||
|
||
|
||
class CrossUnixCCompiler(unixccompiler.UnixCCompiler): | ||
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): | ||
try_remove_all(self.compiler_so, ('-m64', '-fstack-protector-strong', '-mtune=generic')) | ||
try_remove_all(cc_args, '-I/usr') | ||
try_remove_all(pp_opts, '-I/usr') | ||
return unixccompiler.UnixCCompiler._compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts) | ||
|
||
def link(self, target_desc, objects, | ||
output_filename, output_dir=None, libraries=None, | ||
library_dirs=None, runtime_library_dirs=None, | ||
export_symbols=None, debug=0, extra_preargs=None, | ||
extra_postargs=None, build_temp=None, target_lang=None): | ||
try_remove_all(self.library_dirs, ('/usr')) | ||
return unixccompiler.UnixCCompiler.link(self, target_desc, objects, output_filename, output_dir, libraries, | ||
library_dirs, runtime_library_dirs, export_symbols, debug, | ||
extra_preargs, extra_postargs, build_temp, target_lang) | ||
|
||
def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs): | ||
self.__class__ = unixccompiler.UnixCCompiler | ||
ret = unixccompiler.UnixCCompiler._fix_lib_args(self, libraries, library_dirs, runtime_library_dirs) | ||
self.__class__ = CrossUnixCCompiler | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,37 @@ | ||
#!/usr/bin/env python | ||
|
||
from distutils.core import setup, Extension | ||
import os | ||
import sys | ||
# import distutils.core | ||
import setuptools | ||
import crossunixccompiler | ||
|
||
|
||
def process_configparams(): | ||
with open('../Makefile.inc') as f: | ||
config_lines = f.readlines() | ||
|
||
for line in config_lines: | ||
identifier, value = line.split('=', 1) | ||
os.environ[identifier] = value | ||
|
||
|
||
if sys.version_info >= (3,): | ||
BOOST_LIB = 'boost_python3' | ||
else: | ||
BOOST_LIB = 'boost_python' | ||
|
||
module_RF24 = Extension('RF24', | ||
libraries = ['rf24-bcm', BOOST_LIB], | ||
sources = ['pyRF24.cpp']) | ||
process_configparams() | ||
crossunixccompiler.register() | ||
|
||
# module_RF24 = distutils.core.Extension('RF24', | ||
module_RF24 = setuptools.Extension('RF24', | ||
libraries=['rf24', BOOST_LIB], | ||
sources=['pyRF24.cpp'] | ||
) | ||
|
||
setup(name='RF24', | ||
version='1.1', | ||
ext_modules=[module_RF24] | ||
) | ||
# distutils.core.setup(name='RF24', | ||
setuptools.setup(name='RF24', | ||
version='1.1', | ||
ext_modules=[module_RF24] | ||
) |
Oops, something went wrong.