1# SPDX-License-Identifier: GPL-2.0 2include ../scripts/Makefile.include 3 4bindir ?= /usr/bin 5 6ifeq ($(srctree),) 7srctree := $(patsubst %/,%,$(dir $(CURDIR))) 8srctree := $(patsubst %/,%,$(dir $(srctree))) 9endif 10 11# Do not use make's built-in rules 12# (this improves performance and avoids hard-to-debug behaviour); 13MAKEFLAGS += -r 14 15CC = $(CROSS_COMPILE)gcc 16LD = $(CROSS_COMPILE)ld 17CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include 18 19ALL_TARGETS := iio_event_monitor lsiio iio_generic_buffer 20ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS)) 21 22all: $(ALL_PROGRAMS) 23 24export srctree OUTPUT CC LD CFLAGS 25include $(srctree)/tools/build/Makefile.include 26 27# 28# We need the following to be outside of kernel tree 29# 30$(OUTPUT)include/linux/iio: ../../include/uapi/linux/iio 31 mkdir -p $(OUTPUT)include/linux/iio 2>&1 || true 32 ln -sf $(CURDIR)/../../include/uapi/linux/iio/events.h $@ 33 ln -sf $(CURDIR)/../../include/uapi/linux/iio/types.h $@ 34 35prepare: $(OUTPUT)include/linux/iio 36 37LSIIO_IN := $(OUTPUT)lsiio-in.o 38$(LSIIO_IN): prepare FORCE 39 $(Q)$(MAKE) $(build)=lsiio 40$(OUTPUT)lsiio: $(LSIIO_IN) 41 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ 42 43IIO_EVENT_MONITOR_IN := $(OUTPUT)iio_event_monitor-in.o 44$(IIO_EVENT_MONITOR_IN): prepare FORCE 45 $(Q)$(MAKE) $(build)=iio_event_monitor 46$(OUTPUT)iio_event_monitor: $(IIO_EVENT_MONITOR_IN) 47 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ 48 49IIO_GENERIC_BUFFER_IN := $(OUTPUT)iio_generic_buffer-in.o 50$(IIO_GENERIC_BUFFER_IN): prepare FORCE 51 $(Q)$(MAKE) $(build)=iio_generic_buffer 52$(OUTPUT)iio_generic_buffer: $(IIO_GENERIC_BUFFER_IN) 53 $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ 54 55clean: 56 rm -f $(ALL_PROGRAMS) 57 rm -rf $(OUTPUT)include/linux/iio 58 find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.d' -delete 59 60install: $(ALL_PROGRAMS) 61 install -d -m 755 $(DESTDIR)$(bindir); \ 62 for program in $(ALL_PROGRAMS); do \ 63 install $$program $(DESTDIR)$(bindir); \ 64 done 65 66FORCE: 67 68.PHONY: all install clean FORCE prepare 69