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 ../../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"BIT(x)=(1UL<<(x))" -D__user=
34
35comedi_h.py : ../../../comedi.h
36	ctypesgen $< --include "sys/ioctl.h" --cpp 'gcc -E $(CPPFLAGS)' -o $@
37
38convert_c_to_py: all_cfiles.c
39	gcc -g convert_c_to_py.c -o convert_c_to_py -std=c99
40
41ni_values.py: convert_c_to_py
42	./convert_c_to_py
43
44csv-files : ni_values.py comedi_h.py
45	./convert_py_to_csv.py
46
47csv-blank :
48	./make_blank_csv.py
49	@echo New blank csv signal table in csv/blank_route_table.csv
50
51c-files : comedi_h.py
52	./convert_csv_to_c.py --route_values --device_routes
53
54ROUTE_VALUES_SRC=$(wildcard ../ni_route_values/*.c)
55DEVICE_ROUTES_SRC=$(wildcard ../ni_device_routes/*.c)
56all_cfiles.c : $(DEVICE_ROUTES_SRC) $(ROUTE_VALUES_SRC)
57	@for i in $(DEVICE_ROUTES_SRC) $(ROUTE_VALUES_SRC); do \
58		echo "#include \"$$i\"" >> all_cfiles.c; \
59	done
60
61clean-partial :
62	$(RM) -rf comedi_h.py ni_values.py convert_c_to_py all_cfiles.c *.pyc \
63		__pycache__/
64
65clean : partial_clean
66	$(RM) -rf c/ csv/
67
68# Note:  One could also use ctypeslib in order to generate these files.  The
69# caveat is that ctypeslib does not do a great job at handling macro functions.
70# The make rules are as follows:
71# comedi.h.xml : ../../comedi.h
72# 	# note that we have to use PWD here to avoid h2xml finding a system
73# 	# installed version of the comedilib/comedi.h file
74# 	h2xml ${PWD}/../../comedi.h -c -D__user="" -D"BIT(x)=(1<<(x))" \
75# 		-o comedi.h.xml
76#
77# comedi_h.py : comedi.h.xml
78# 	xml2py ./comedi.h.xml -o comedi_h.py
79# clean :
80# 	rm -f comedi.h.xml comedi_h.py comedi_h.pyc
81