Python Модуль, использующий C Библиотеку - PullRequest
1 голос
/ 26 мая 2020

Я работаю над проектом, который требует использования библиотеки C в Python. Текущий файл C с использованием arm- linux -gnueabihf-g cc для компиляции, и у него есть собственный Makefile. Я изо всех сил пытаюсь изменить Makefile для компиляции кода C, который включает Python .h. Это то, что у меня есть в Makefile

Makefile

####################################################
#  TARGET
#  0: Raspberry-Pi
#  1: else
TARGET = 0

####################################################
#  INTERFACE_NUMBER
#  0: USE_UART  
#  1: USE_SPI    
#  2: USE_SPI_DRDY
INTERFACE_NUMBER = 1

####################################################
#  PRINT_LVL 
#  for   HAL_Print         
#  0:    none      
#  1:    fprintf (log.txt)       
#  2:    printf (terminal)  
#  3:    printf + fprintf    
PRINT_LVL = 2


PROGRAM = hello.so
SOURCES = tag_cfg1.c

HOME_DIR += ../../../../../../../../..
PROJ_DIR += ../../..
CFLAGS += -Wall

include $(PROJ_DIR)/include/dwm1001.mak

dwm1001.mak

##############################################################################
#
# BASE
#
#INCLUDES += ~/usr/include/python3.7/Python.h


# CC?=arm-linux-gnueabihf-gcc

ARM_CC ?= arm-linux-gnueabihf-gcc
GCC = gcc

LIBS=bcm2835

CFLAGS+=-pthread
CFLAGS+=-lwiringPi  
# Expand defines
# CFLAGS += $(addprefix -D,$(DEFINES))
# PROJ_DIR = $(shell pwd)
INC_DIR = $(PROJ_DIR)/include
DRIVER_DIR = $(PROJ_DIR)/dwm_driver
LMH_DIR = $(DRIVER_DIR)/lmh
API_DIR = $(DRIVER_DIR)/dwm_api
Py_DIR = $(HOME_DIR)/usr/include/python2.7
PYLIB = $(HOME_DIR)/usr/bin
INCLUDES += $(Py_DIR)/Python.h

##############################################################################
#  TARGET choice
#  0: Raspberry-Pi
#  1: else

ifeq ($(TARGET),0)
cc = $(ARM_CC)
HAL_DIR = $(PROJ_DIR)/platform/rpi/hal
endif 

SOURCEDIRS += $(INC_DIR)
SOURCEDIRS += $(DRIVER_DIR)
SOURCEDIRS += $(HAL_DIR)
SOURCEDIRS += $(LMH_DIR)
SOURCEDIRS += $(API_DIR)
SOURCEDIRS += $(Py_DIR)


# SOURCES += main.c
INCLUDES += $(INC_DIR)/dwm1001_tlv.h
INCLUDES += $(INC_DIR)/dwm_api.h
SOURCES += $(API_DIR)/dwm_api.c


INCLUDES += $(HAL_DIR)/hal.h
SOURCES += $(HAL_DIR)/hal.c
INCLUDES += $(HAL_DIR)/hal_fprint.h
SOURCES += $(HAL_DIR)/hal_fprint.c
INCLUDES += $(HAL_DIR)/hal_interface.h
LOGFILES += log.txt

INCLUDES += $(LMH_DIR)/lmh.h
SOURCES += $(LMH_DIR)/lmh.c

##############################################################################
#  INTERFACE_NUMBER choice
#  USE_UART           0
#  USE_SPI            1
#  USE_SPI_DRDY       2
ifndef INTERFACE_NUMBER
INTERFACE_NUMBER=0
endif

DEFINES += INTERFACE_NUMBER=$(INTERFACE_NUMBER)
ifeq ($(INTERFACE_NUMBER),0)
INCLUDES += $(HAL_DIR)/hal_uart.h
SOURCES += $(HAL_DIR)/hal_uart.c
INCLUDES += $(LMH_DIR)/lmh_uartrx.h
SOURCES += $(LMH_DIR)/lmh_uartrx.c
endif 

ifeq ($(INTERFACE_NUMBER),1)
INCLUDES += $(HAL_DIR)/hal_spi.h
SOURCES += $(HAL_DIR)/hal_spi.c
INCLUDES += $(LMH_DIR)/lmh_spirx.h
SOURCES += $(LMH_DIR)/lmh_spirx.c
endif 

ifeq ($(INTERFACE_NUMBER),2)
INCLUDES += $(HAL_DIR)/hal_spi.h
SOURCES += $(HAL_DIR)/hal_spi.c
INCLUDES += $(HAL_DIR)/hal_gpio.h
SOURCES += $(HAL_DIR)/hal_gpio.c
INCLUDES += $(LMH_DIR)/lmh_spirx.h
SOURCES += $(LMH_DIR)/lmh_spirx.c
INCLUDES += $(LMH_DIR)/lmh_spirx_drdy.h
SOURCES += $(LMH_DIR)/lmh_spirx_drdy.c
endif 

DEFINES += PRINT_LVL=$(PRINT_LVL)

# Expand defines
CFLAGS += $(addprefix -D,$(DEFINES))

# Expand search paths
CFLAGS += $(addprefix -I,$(SOURCEDIRS))

vpath %.c $(SOURCEDIRS)


$(PROGRAM): $(SOURCES) $(INCLUDES)
    $(cc) -g -o $@ $(SOURCES) -l $(LIBS) $(CFLAGS) -shared -L$(PYLIB) -lpython2.7
    @echo $@ "build done"  

clean:
    @echo "Cleaning"
    $(Q)-rm -f $(PROGRAM)
    $(Q)-rm -f $(LOGFILES)
   
   
...