summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: a6d25c91c5b938ace97ef0dd61335f344fe2466d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# Create a wrapper around a legacy implementation
# for the proposed new bps interfaces.  This relies on the -Wp,-dM option
# in gcc and uses a not too crazy heuristic that if all the numbers
# equal their corresponding integer then the interface already takes
# arbitrary integers.
#

CC		= gcc
CFLAGS		= -g -O2
MACRODEFS	= -Wp,-dM -E

.SUFFIXES:
.SUFFIXES: .c .h .i .s .o

all: termbaud.o termbaud.h

.c.o:
	$(CC) $(CFLAGS) -c -o $@ $<
.c.i:
	$(CC) $(CFLAGS) -E -o $@ $<
.c.s:
	$(CC) $(CFLAGS) -S -o $@ $<

speed.list: termios.c
	$(CC) $(CFLAGS) $(MACRODEFS) $< | \
		sed -r -n -e 's/^#define B([0-9]+) .*$$/\1/p' | \
		sort -n | uniq > $@

termistriv.h: speed.list Makefile
	( echo -n "#if (1"; \
	while read m; do \
	  echo " && \\" ; \
	  echo -n "    (B$$m == $$m)"; \
	done; \
	echo ')'; \
	echo '#define CFENCSPEED_IS_TRIVIAL 1'; \
	echo '#endif' \
	) < $< >> $@ || ( rm -f $@ ; false )

speedtbl.h: speed.list Makefile
	( while read m; do \
	  echo "    {B$$m, $$m},"; \
	done \
	) < $< >> $@ || ( rm -f $@ ; false )

termistriv.i: termistriv.c termistriv.h termbaud_nontrivial.h

termbaud.h: termistriv.i termbaud_nontrivial.h termbaud_trivial.h
	cp -f `grep '^termbaud.*\.h$$' $<` termbaud.h

termbaud.o: termbaud.c termbaud_nontrivial.h termistriv.h speedtbl.h

clean:
	rm -f speed.list termbaud.h termistriv.h *.o *.i *.s

spotless: clean
	rm -f *~ \#*