Imported Upstream version 1.5
[routino] / src / xml / Makefile
1 # $Header: /home/amb/routino/src/xml/RCS/Makefile,v 1.10 2010/07/07 17:26:24 amb Exp $
2 #
3 # XML test programs Makefile
4 #
5 # Part of the Routino routing software.
6 #
7 # This file Copyright 2010 Andrew M. Bishop
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU Affero General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU Affero General Public License for more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 #
22
23 # Programs
24
25 CC=gcc
26 LD=gcc
27
28 # Program options
29
30 CFLAGS=-Wall -Wmissing-prototypes -O0 -g
31 LDFLAGS=-lm -lc
32
33 # Required to use stdio with files > 2GiB on 32-bit system.
34
35 FLAGS64=-D_FILE_OFFSET_BITS=64
36
37 # Compilation targets
38
39 XMLDIR=../../xml
40
41 X=$(notdir $(wildcard $(XMLDIR)/*.xsd))
42 C=$(foreach f,$(X),$(addsuffix -skeleton.c,$(basename $f)))
43 D=$(foreach f,$(C),$(addprefix .deps/,$(addsuffix .d,$(basename $f))))
44 O=$(foreach f,$(C),$(addsuffix .o,$(basename $f)))
45 E=$(foreach f,$(C),$(basename $f))
46
47 EXE=xsd-to-xmlparser
48
49 ########
50
51 all : $(EXE) $(C) $(E)
52         @true
53
54 ########
55
56 xsd-to-xmlparser : xsd-to-xmlparser.o ../xmlparse.o
57         $(LD) xsd-to-xmlparser.o ../xmlparse.o -o $@ $(LDFLAGS)
58
59 ########
60
61 %-skeleton.c : $(XMLDIR)/%.xsd xsd-to-xmlparser
62         -./xsd-to-xmlparser < $< > $@
63         @test -s $@ || rm $@
64
65 %-skeleton : %-skeleton.o ../xmlparse.o
66         $(LD) $< ../xmlparse.o -o $@ $(LDFLAGS)
67
68 .SECONDARY : $(O)
69
70 ########
71
72 ../xmlparse.o : ../xmlparse.c ../xmlparse.h
73         cd .. && $(MAKE) xmlparse.o
74
75 ../xmlparse.c : ../xmlparse.l
76         cd .. && $(MAKE) xmlparse.o
77
78 ########
79
80 %.o : %.c
81         $(CC) -c $(CFLAGS) $(FLAGS64) -I.. $< -o $@ -MMD -MP -MF $(addprefix .deps/,$(addsuffix .d,$(basename $<)))
82
83 ########
84
85 test : all test-skeleton .FORCE
86         @status=true ;\
87         echo "" ;\
88         for good in test/good*.xml; do \
89            echo "Testing: $$good ... " ;\
90            if ./test-skeleton < $$good > /dev/null; then echo "... passed"; else echo "... FAILED"; status=false; fi ;\
91            echo "" ;\
92         done ;\
93         for bad in test/bad*.xml; do \
94            echo "Testing: $$bad ... " ;\
95            if ./test-skeleton < $$bad > /dev/null; then echo "... FAILED"; status=false; else echo "... passed"; fi ;\
96            echo "" ;\
97         done ;\
98         if $$status; then echo "Success: all tests passed"; else echo "Warning: Some tests FAILED"; fi ;\
99         $$status
100
101 test-skeleton : test-skeleton.o
102         $(LD) $< ../xmlparse.o -o $@ $(LDFLAGS)
103
104 test-skeleton.c : test/test.xsd xsd-to-xmlparser
105         ./xsd-to-xmlparser < $< | sed -e 's/XMLPARSE_UNKNOWN_ATTR_WARN/XMLPARSE_UNKNOWN_ATTR_ERROR/' > $@
106
107 ########
108
109 clean:
110         rm -f *.o
111         rm -f *~
112
113 ########
114
115 distclean: clean
116         -rm -f $(EXE)
117         -rm -f $(E) test-skeleton
118         -rm -f $(D) .deps/test-skeleton.d
119         -rm -f $(C) test-skeleton.c
120         -rm -fr .deps
121
122 ########
123
124 .deps : .FORCE
125         @[ -d .deps ] || mkdir $@
126
127 $(D) : .deps
128         @touch $@
129
130 include $(D)
131
132 ########
133
134 .FORCE :