]> Git — Sourcephile - julm/air-duino.git/blob - GNUmakefile
fix collect.pl when Unkown values, better .png rules, and add .html5
[julm/air-duino.git] / GNUmakefile
1 # Licence: GPLv3+ <http://www.gnu.org/licenses/gpl.txt>
2 # Copyright 2015: Julien Moutinho <julm+air@autogeree.net>
3
4 #
5 ## GNUmakefile
6 ###
7 .SECONDARY:
8 .SUFFIXES:
9 MAKEFLAGS += -r
10
11 uniq=$(if $1,$(call \
12 uniq,$(wordlist 2,$(words $1),$1),$2 $(if \
13 $(filter $(firstword $1),$2),,$(firstword $1))) \
14 ,$2)
15
16 outs := png html5
17 all: $(outs)
18
19 #
20 ## Sensors
21 ###
22
23 SENSOR_LABEL_temperature=Température (°C)
24 SENSOR_LABEL_humidity=Humidité (%)
25 SENSOR_LABEL_particles=Particules
26 SENSOR_LABEL_quality=Qualité de l’air
27 sensors := \
28 temperature \
29 humidity \
30 quality \
31 particles
32
33 #
34 ## Round Robin Database (RRD)
35 ###
36
37 RRD_CF := AVERAGE
38 .rrd = $(wildcard rrd/*/*.rrd)
39
40 #
41 ## INO
42 ###
43
44 # For GNU/Linux
45 ARDUINO_DIR := /usr/share/arduino/
46 ARDMK_DIR := /usr/share/arduino/
47 AVR_TOOLS_DIR := /usr
48
49 # For Seeeduino
50 BOARD_TAG := uno
51
52 ARDUINO_LIBS := \
53 AirQuality_Sensor \
54 DustSensor \
55 Humidity_Temperature_Sensor \
56 LCD_Display9696 \
57 Wire
58
59 USER_LIB_PATH := $(abspath ./libraries)
60
61 include $(ARDMK_DIR)/Arduino.mk
62
63 ino: $(TARGET_EEP) $(TARGET_HEX)
64
65 #
66 ## PNG
67 ###
68
69 define out/sensor/png
70 endef
71
72 define out/sensor/year/png
73 out/$(sensor)/$(year)/png:
74 endef
75
76 define out/sensor/year/month/png
77 out/$(sensor)/$(year)/$(month)/png: \
78 out/$(sensor)/$(year)/$(month).png
79
80 out/$(sensor)/$(year)/$(month).png: \
81 rrd/$(year)/$(month).rrd
82 mkdir -p $$(@D)
83 rrdtool graph $$@ \
84 -w 785 -h 120 -a PNG \
85 --slope-mode \
86 --start $(month_begin) --end $(month_end) \
87 --vertical-label '$$(SENSOR_LABEL_$(sensor))' \
88 --x-grid HOUR:8:DAY:1:DAY:1:86400:%d \
89 DEF:$(sensor)=rrd/$(year)/$(month).rrd:$(sensor):$$(RRD_CF) \
90 LINE1:$(sensor)'#ff0000':"$(sensor)"
91 endef
92
93 define out/sensor/year/month/day/png
94 out/$(sensor)/$(year)/$(month)/$(day)/png: \
95 out/$(sensor)/$(year)/$(month)/$(day).png
96
97 out/$(sensor)/$(year)/$(month)/$(day).png: \
98 rrd/$(year)/$(month).rrd
99 mkdir -p $$(@D)
100 rrdtool graph $$@ \
101 -w 785 -h 120 -a PNG \
102 --slope-mode \
103 --start $(day_begin) --end $(day_end) \
104 --vertical-label '$$(SENSOR_LABEL_$(sensor))' \
105 --x-grid MINUTE:10:HOUR:1:HOUR:1:0:%H \
106 DEF:$(sensor)=rrd/$(year)/$(month).rrd:$(sensor):$$(RRD_CF) \
107 LINE1:$(sensor)'#ff0000':"$(sensor)";
108 endef
109
110 #
111 ## HTML5
112 ###
113
114 define out/sensor/html5
115 endef
116
117 define out/sensor/year/html5
118 out/$(sensor)/$(year)/html5:
119 endef
120
121 define out/sensor/year/month/html5
122 out/$(sensor)/$(year)/$(month)/html5: \
123 out/$(sensor)/$(year)/$(month).html5
124
125 out/$(sensor)/$(year)/$(month).html5: \
126 out/$(sensor)/$(year)/$(month)/png
127 printf ' \
128 <report sensor="$(sensor)" year="$(year)" month="$(month)"> \
129 $(foreach day,$(days), \
130 <date \
131 day="$(day)" \
132 day-name="$$(shell date +'%A' -d '$(year)/$(month)/$(day)')"/>) \
133 </report>' | \
134 xsltproc --output $$@ \
135 xsl/sensor/year/month.html5.xsl -
136 endef
137 define out/year/month/html5
138 out/$(year)/$(month)/html5: \
139 out/$(year)/$(month).html5
140
141 out/$(year)/$(month).html5: \
142 $(foreach sensor,$(sensors), out/$(sensor)/$(year)/$(month)/png)
143 mkdir -p $$(@D)
144 printf ' \
145 <report year="$(year)" month="$(month)"> \
146 $(foreach day,$(days), \
147 <date \
148 day="$(day)" \
149 day-name="$$(shell date +'%A' -d '$(year)/$(month)/$(day)')"> \
150 $(foreach sensor,$(sensors), \
151 <sensor name="$(sensor)"/> \
152 ) \
153 </date>) \
154 </report>' | \
155 xsltproc --output $$@ \
156 xsl/year/month.html5.xsl -
157 endef
158
159 define out/sensor/year/month/day/html5
160 #out/$(sensor)/$(year)/$(month)/$(day)/html5: \
161 #out/$(sensor)/$(year)/$(month)/$(day).html5
162
163 endef
164
165 #
166 ## Dates
167 ###
168 years=$(call uniq,$(foreach rrd,$(.rrd),$(word 2,$(subst /, ,$(rrd)))))
169 months=$(foreach rrd,$(filter rrd/$(year)/%,$(.rrd)),$(basename $(word 3,$(subst /, ,$(rrd)))))
170 days=$(shell seq -w $$(date +'%d' -d '$(year)/$(month)/01 + 1 month - 1 second'))
171
172 month_begin=$(shell date +'%s' -d '$(year)/$(month)/01')
173 month_end=$(shell date +'%s' -d '$(year)/$(month)/01 + 1 month - 1 second')
174
175 day_begin=$(shell date +'%s' -d '$(year)/$(month)/$(day)')
176 day_end=$(shell date +'%s' -d '$(year)/$(month)/$(day) + 1 day - 1 second')
177
178 define foreach/sensor
179 .PHONY: out/$(sensor)/$(out)
180 out/$(out): out/$(sensor)/$(out)
181 $(call out/sensor/$(out))
182 endef
183
184 define foreach/year/sensor/out
185 .PHONY: out/$(sensor)/$(year)/$(out)
186 out/$(sensor)/$(out): out/$(sensor)/$(year)/$(out)
187 $(call out/sensor/year/$(out))
188 endef
189
190 define foreach/year/month/sensor/out
191 .PHONY: out/$(sensor)/$(year)/$(month)/$(out)
192 out/$(sensor)/$(year)/$(out): out/$(sensor)/$(year)/$(month)/$(out)
193 $(call out/sensor/year/month/$(out))
194 endef
195 define foreach/year/month/out
196 .PHONY: out/$(year)/$(month)/$(out)
197 out/$(year)/$(out): out/$(year)/$(month)/$(out)
198 $(call out/year/month/$(out))
199 endef
200
201 define foreach/year/month/day/sensor/out
202 .PHONY: out/$(sensor)/$(year)/$(month)/$(day)/$(out)
203 out/$(sensor)/$(year)/$(month)/$(out): out/$(sensor)/$(year)/$(month)/$(day)/$(out)
204 $(call out/sensor/year/month/day/$(out))
205 endef
206
207 $(foreach sensor,$(sensors), \
208 $(foreach out,$(outs), \
209 $(eval $(call foreach/sensor)) \
210 ) \
211 )
212 $(foreach year,$(years), \
213 $(foreach out,$(outs), \
214 $(eval $(call foreach/year/out)) \
215 ) \
216 $(foreach sensor,$(sensors), \
217 $(foreach out,$(outs), \
218 $(eval $(call foreach/year/sensor/out)) \
219 ) \
220 ) \
221 $(foreach month,$(months), \
222 $(foreach out,$(outs), \
223 $(eval $(call foreach/year/month/out)) \
224 ) \
225 $(foreach sensor,$(sensors), \
226 $(foreach out,$(outs), \
227 $(eval $(call foreach/year/month/sensor/out)) \
228 ) \
229 ) \
230 $(foreach day,$(days), \
231 $(foreach out,$(outs), \
232 $(eval $(call foreach/year/month/day/out)) \
233 ) \
234 $(foreach sensor,$(sensors), \
235 $(foreach out,$(outs), \
236 $(eval $(call foreach/year/month/day/sensor/out)) \
237 ) \
238 ) \
239 ) \
240 ) \
241 )