vsergeev / c-periphery

A C library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
MIT License
744 stars 229 forks source link

Makefile incorrectly set the flags for character device support #56

Open fell-z opened 2 months ago

fell-z commented 2 months ago

Hey.

I had some issues using the lib via lua-periphery. After some digging of my own, I discovered that 'c-periphery' wasn't building with character device support, so I took a look at the Makefile and found a problem in the following line.

GPIO_CDEV_SUPPORT = $(if $(filter 1,$(GPIO_CDEV_V2_SUPPORT)),2,$(if $(filter 1,$(GPIO_CDEV_V1_SUPPORT)),1,0))

In those conditions, filter 1 should be filter 0 to work correctly.

reeett commented 2 months ago

Hi @fell-z, had the same problem writing a Makefile of lua-periphery for OpenWRT. Your suggestion fixed it for me too.

Thank you


Patchfile for OpenWRT 23.05.4

Index: lua-periphery-2.4.2/c-periphery/Makefile
===================================================================
--- lua-periphery-2.4.2.orig/c-periphery/Makefile
+++ lua-periphery-2.4.2/c-periphery/Makefile
@@ -12,7 +12,7 @@ OBJECTS = $(patsubst $(SRCDIR)/%.c,$(OBJ

 GPIO_CDEV_V1_SUPPORT := $(shell ! echo -e "#include <linux/gpio.h>\n#ifndef GPIO_GET_LINEEVENT_IOCTL\n#error\n#endif" | $(CC) -E - >/dev/null 2>&1; echo $$?)
 GPIO_CDEV_V2_SUPPORT := $(shell ! echo -e "#include <linux/gpio.h>\nint main(void) { GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME; return 0; }" | $(CC) -x c - >/dev/null 2>&1; echo $$?)
-GPIO_CDEV_SUPPORT = $(if $(filter 1,$(GPIO_CDEV_V2_SUPPORT)),2,$(if $(filter 1,$(GPIO_CDEV_V1_SUPPORT)),1,0))
+GPIO_CDEV_SUPPORT = $(if $(filter 0,$(GPIO_CDEV_V2_SUPPORT)),2,$(if $(filter 0,$(GPIO_CDEV_V1_SUPPORT)),1,0))

 COMMIT_ID := $(shell git describe --abbrev --always --tags --dirty 2>/dev/null || echo "")