make: improve portability

Modifications to initial commit:

* Collapse conditional NULL device assignment into single line

resolves #55.

Signed-off-by: Vanya A. Sergeev <v@sergeev.io>
This commit is contained in:
javalikescript
2024-04-27 21:52:46 +02:00
committed by Vanya A. Sergeev
parent 1f8545b1f8
commit 024a25d18e

View File

@@ -10,11 +10,12 @@ TEST_PROGRAMS = $(basename $(wildcard tests/*.c))
OBJECTS = $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SRCS))
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 $$?)
NULL := $(if $(filter Windows_NT,$(OS)),NUL,/dev/null)
GPIO_CDEV_V1_SUPPORT := $(shell ! echo -e "\x23include <linux/gpio.h>\n\x23ifndef GPIO_GET_LINEEVENT_IOCTL\n\x23error\n\x23endif" | $(CC) -E - >$(NULL) 2>&1; echo $$?)
GPIO_CDEV_V2_SUPPORT := $(shell ! echo -e "\x23include <linux/gpio.h>\nint main(void) { GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME; return 0; }" | $(CC) -x c - >$(NULL) 2>&1; echo $$?)
GPIO_CDEV_SUPPORT = $(if $(filter 1,$(GPIO_CDEV_V2_SUPPORT)),2,$(if $(filter 1,$(GPIO_CDEV_V1_SUPPORT)),1,0))
COMMIT_ID := $(shell git describe --abbrev --always --tags --dirty 2>/dev/null || echo "")
COMMIT_ID := $(shell git describe --abbrev --always --tags --dirty 2>$(NULL) || echo "")
OPT ?= -O3
CFLAGS += -std=gnu99 -pedantic