]> Git — Sourcephile - julm/air-duino.git/blob - GNUmakefile
rename out/ -> view/, harden collect.pl parsing, add @id in .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 views := png html5
17 all: $(views)
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 view/sensor/png
70 endef
71
72 define view/sensor/year/png
73 view/$(sensor)/$(year)/png:
74 endef
75
76 define view/sensor/year/month/png
77 view/$(sensor)/$(year)/$(month)/png: \
78 view/$(sensor)/$(year)/$(month).png
79
80 view/$(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 view/sensor/year/month/day/png
94 view/$(sensor)/$(year)/$(month)/$(day)/png: \
95 view/$(sensor)/$(year)/$(month)/$(day).png
96
97 view/$(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 view/sensor/html5
115 endef
116
117 define view/sensor/year/html5
118 view/$(sensor)/$(year)/html5:
119 endef
120
121 define view/sensor/year/month/html5
122 view/$(sensor)/$(year)/$(month)/html5: \
123 view/$(sensor)/$(year)/$(month).html5
124
125 view/$(sensor)/$(year)/$(month).html5: \
126 view/$(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 view/year/month/html5
138 view/$(year)/$(month)/html5: \
139 view/$(year)/$(month).html5
140
141 view/$(year)/$(month).html5: \
142 $(foreach sensor,$(sensors), view/$(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 view/sensor/year/month/day/html5
160 #view/$(sensor)/$(year)/$(month)/$(day)/html5: \
161 #view/$(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: view/$(sensor)/$(view)
180 view/$(view): view/$(sensor)/$(view)
181 $(call view/sensor/$(view))
182 endef
183
184 define foreach/year/sensor/view
185 .PHONY: view/$(sensor)/$(year)/$(view)
186 view/$(sensor)/$(view): view/$(sensor)/$(year)/$(view)
187 $(call view/sensor/year/$(view))
188 endef
189
190 define foreach/year/month/sensor/view
191 .PHONY: view/$(sensor)/$(year)/$(month)/$(view)
192 view/$(sensor)/$(year)/$(view): view/$(sensor)/$(year)/$(month)/$(view)
193 $(call view/sensor/year/month/$(view))
194 endef
195 define foreach/year/month/view
196 .PHONY: view/$(year)/$(month)/$(view)
197 view/$(year)/$(view): view/$(year)/$(month)/$(view)
198 $(call view/year/month/$(view))
199 endef
200
201 define foreach/year/month/day/sensor/view
202 .PHONY: view/$(sensor)/$(year)/$(month)/$(day)/$(view)
203 view/$(sensor)/$(year)/$(month)/$(view): view/$(sensor)/$(year)/$(month)/$(day)/$(view)
204 $(call view/sensor/year/month/day/$(view))
205 endef
206
207 $(foreach sensor,$(sensors), \
208 $(foreach view,$(views), \
209 $(eval $(call foreach/sensor)) \
210 ) \
211 )
212 $(foreach year,$(years), \
213 $(foreach view,$(views), \
214 $(eval $(call foreach/year/view)) \
215 ) \
216 $(foreach sensor,$(sensors), \
217 $(foreach view,$(views), \
218 $(eval $(call foreach/year/sensor/view)) \
219 ) \
220 ) \
221 $(foreach month,$(months), \
222 $(foreach view,$(views), \
223 $(eval $(call foreach/year/month/view)) \
224 ) \
225 $(foreach sensor,$(sensors), \
226 $(foreach view,$(views), \
227 $(eval $(call foreach/year/month/sensor/view)) \
228 ) \
229 ) \
230 $(foreach day,$(days), \
231 $(foreach view,$(views), \
232 $(eval $(call foreach/year/month/day/view)) \
233 ) \
234 $(foreach sensor,$(sensors), \
235 $(foreach view,$(views), \
236 $(eval $(call foreach/year/month/day/sensor/view)) \
237 ) \
238 ) \
239 ) \
240 ) \
241 )