1# SPDX-License-Identifier: GPL-2.0
2# this make file is simply to help autogenerate these files:
3# 	ni_route_values.h
4#	ni_device_routes.h
5# in order to do this, we are also generating a python representation (using
6# ctypesgen) of ../../../../../include/uapi/linux/comedi.h.
7# This allows us to sort NI signal/terminal names numerically to use a binary
8# search through the device_routes tables to find valid routes.
9
10ALL:
11	@echo Typical targets:
12	@echo "\`make csv-files\`"
13	@echo "  Creates new csv-files using content of c-files of existing"
14	@echo "  ni_routing/* content.  New csv files are placed in csv"
15	@echo "  sub-directory."
16	@echo "\`make c-files\`"
17	@echo "  Creates new c-files using content of csv sub-directory.  These"
18	@echo "  new c-files can be compared to the active content in the"
19	@echo "  ni_routing directory."
20	@echo "\`make csv-blank\`"
21	@echo "  Create a new blank csv file.  This is useful for establishing a"
22	@echo "  new data table for either a device family \(less likely\) or a"
23	@echo "  specific board of an existing device family \(more likely\)."
24	@echo "\`make clean-partial\`"
25	@echo "  Remove all generated files/directories EXCEPT for csv/c files."
26	@echo "\`make clean\`"
27	@echo "  Remove all generated files/directories."
28	@echo "\`make everything\`"
29	@echo "  Build all csv-files, then all new c-files."
30
31everything : csv-files c-files csv-blank
32
33CPPFLAGS = -D__user=
34INC_UAPI = ../../../../../include/uapi
35
36comedi_h.py: $(INC_UAPI)/linux/comedi.h
37	ctypesgen $< --include "sys/ioctl.h" --cpp 'gcc -E $(CPPFLAGS)' -o $@
38
39convert_c_to_py: all_cfiles.c linux/comedi.h
40	gcc -g -I. convert_c_to_py.c -o convert_c_to_py -std=c99
41
42# Create a local 'linux/comedi.h' for use when compiling 'convert_c_to_py.c'
43# with the '-I.' option.  (Cannot specify '-I../../../../../include/uapi'
44# because that interferes with inclusion of other system headers.)
45linux/comedi.h: $(INC_UAPI)/linux/comedi.h
46	mkdir -p linux
47	ln -snf ../$< $@
48
49ni_values.py: convert_c_to_py
50	./convert_c_to_py
51
52csv-files : ni_values.py comedi_h.py
53	./convert_py_to_csv.py
54
55csv-blank : comedi_h.py
56	./make_blank_csv.py
57	@echo New blank csv signal table in csv/blank_route_table.csv
58
59c-files : comedi_h.py
60	./convert_csv_to_c.py --route_values --device_routes
61
62ROUTE_VALUES_SRC=$(wildcard ../ni_route_values/*.c)
63DEVICE_ROUTES_SRC=$(wildcard ../ni_device_routes/*.c)
64all_cfiles.c : $(DEVICE_ROUTES_SRC) $(ROUTE_VALUES_SRC)
65	@for i in $(DEVICE_ROUTES_SRC) $(ROUTE_VALUES_SRC); do \
66		echo "#include \"$$i\"" >> all_cfiles.c; \
67	done
68
69clean-partial :
70	$(RM) -rf comedi_h.py ni_values.py convert_c_to_py all_cfiles.c *.pyc \
71		__pycache__/
72
73clean : clean-partial
74	$(RM) -rf c/ csv/ linux/
75
76# Note:  One could also use ctypeslib in order to generate these files.  The
77# caveat is that ctypeslib does not do a great job at handling macro functions.
78# The make rules are as follows:
79# comedi.h.xml : $(INC_UAPI)/linux/comedi.h
80# 	# note that we have to use PWD here to avoid h2xml finding a system
81# 	# installed version of the comedilib/comedi.h file
82# 	h2xml ${PWD}/$(INC_UAPI)/linux/comedi.h -c D__user="" -o comedi.h.xml
83#
84# comedi_h.py : comedi.h.xml
85# 	xml2py ./comedi.h.xml -o comedi_h.py
86# clean :
87# 	rm -f comedi.h.xml comedi_h.py comedi_h.pyc
88