]> Git — Sourcephile - julm/air-duino.git/blob - GNUmakefile
harden collect.pl parsing
[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 ifeq ($(NO_INO),)
62 include $(ARDMK_DIR)/Arduino.mk
63 endif
64
65 ino: $(TARGET_EEP) $(TARGET_HEX)
66
67 #
68 ## PNG
69 ###
70
71 define view/sensor/png
72 endef
73
74 define view/sensor/year/png
75 view/$(sensor)/$(year)/png:
76 endef
77
78 define view/sensor/year/month/png
79 view/$(sensor)/$(year)/$(month)/png: \
80 view/$(sensor)/$(year)/$(month).png
81
82 view/$(sensor)/$(year)/$(month).png: \
83 rrd/$(year)/$(month).rrd
84 mkdir -p $$(@D)
85 rrdtool graph $$@ \
86 -w 785 -h 120 -a PNG \
87 --slope-mode \
88 --start $(month_begin) --end $(month_end) \
89 --vertical-label '$$(SENSOR_LABEL_$(sensor))' \
90 --x-grid HOUR:8:DAY:1:DAY:1:86400:%d \
91 DEF:$(sensor)=rrd/$(year)/$(month).rrd:$(sensor):$$(RRD_CF) \
92 LINE1:$(sensor)'#ff0000':"$(sensor)"
93 endef
94
95 define view/sensor/year/month/day/png
96 view/$(sensor)/$(year)/$(month)/$(day)/png: \
97 view/$(sensor)/$(year)/$(month)/$(day).png
98
99 view/$(sensor)/$(year)/$(month)/$(day).png: \
100 rrd/$(year)/$(month).rrd
101 mkdir -p $$(@D)
102 rrdtool graph $$@ \
103 -w 785 -h 120 -a PNG \
104 --slope-mode \
105 --start $(day_begin) --end $(day_end) \
106 --vertical-label '$$(SENSOR_LABEL_$(sensor))' \
107 --x-grid MINUTE:10:HOUR:1:HOUR:1:0:%H \
108 DEF:$(sensor)=rrd/$(year)/$(month).rrd:$(sensor):$$(RRD_CF) \
109 LINE1:$(sensor)'#ff0000':"$(sensor)";
110 endef
111
112 #
113 ## HTML5
114 ###
115
116 define view/sensor/html5
117 endef
118
119 define view/sensor/year/html5
120 view/$(sensor)/$(year)/html5:
121 endef
122
123 define view/sensor/year/month/html5
124 view/$(sensor)/$(year)/$(month)/html5: \
125 view/$(sensor)/$(year)/$(month).html5
126
127 view/$(sensor)/$(year)/$(month).html5: \
128 view/$(sensor)/$(year)/$(month)/png
129 printf ' \
130 <report sensor="$(sensor)" year="$(year)" month="$(month)"> \
131 $(foreach day,$(days), \
132 <date \
133 day="$(day)" \
134 day-name="$$(shell date +'%A' -d '$(year)/$(month)/$(day)')"/>) \
135 </report>' | \
136 xsltproc --output $$@ \
137 xsl/sensor/year/month.html5.xsl -
138 endef
139 define view/year/month/html5
140 view/$(year)/$(month)/html5: \
141 view/$(year)/$(month).html5
142
143 view/$(year)/$(month).html5: \
144 $(foreach sensor,$(sensors), view/$(sensor)/$(year)/$(month)/png)
145 mkdir -p $$(@D)
146 printf ' \
147 <report year="$(year)" month="$(month)"> \
148 $(foreach day,$(days), \
149 <date \
150 day="$(day)" \
151 day-name="$$(shell date +'%A' -d '$(year)/$(month)/$(day)')"> \
152 $(foreach sensor,$(sensors), \
153 <sensor name="$(sensor)"/> \
154 ) \
155 </date>) \
156 </report>' | \
157 xsltproc --output $$@ \
158 xsl/year/month.html5.xsl -
159 endef
160
161 define view/sensor/year/month/day/html5
162 #view/$(sensor)/$(year)/$(month)/$(day)/html5: \
163 #view/$(sensor)/$(year)/$(month)/$(day).html5
164
165 endef
166
167 #
168 ## Dates
169 ###
170 years=$(call uniq,$(foreach rrd,$(.rrd),$(word 2,$(subst /, ,$(rrd)))))
171 months=$(foreach rrd,$(filter rrd/$(year)/%,$(.rrd)),$(basename $(word 3,$(subst /, ,$(rrd)))))
172 days=$(shell seq -w $$(date +'%d' -d '$(year)/$(month)/01 + 1 month - 1 second'))
173
174 month_begin=$(shell date +'%s' -d '$(year)/$(month)/01')
175 month_end=$(shell date +'%s' -d '$(year)/$(month)/01 + 1 month - 1 second')
176
177 day_begin=$(shell date +'%s' -d '$(year)/$(month)/$(day)')
178 day_end=$(shell date +'%s' -d '$(year)/$(month)/$(day) + 1 day - 1 second')
179
180 define foreach/sensor
181 .PHONY: view/$(sensor)/$(view)
182 view/$(view): view/$(sensor)/$(view)
183 $(call view/sensor/$(view))
184 endef
185
186 define foreach/year/sensor/view
187 .PHONY: view/$(sensor)/$(year)/$(view)
188 view/$(sensor)/$(view): view/$(sensor)/$(year)/$(view)
189 $(call view/sensor/year/$(view))
190 endef
191
192 define foreach/year/month/sensor/view
193 .PHONY: view/$(sensor)/$(year)/$(month)/$(view)
194 view/$(sensor)/$(year)/$(view): view/$(sensor)/$(year)/$(month)/$(view)
195 $(call view/sensor/year/month/$(view))
196 endef
197 define foreach/year/month/view
198 .PHONY: view/$(year)/$(month)/$(view)
199 view/$(year)/$(view): view/$(year)/$(month)/$(view)
200 $(call view/year/month/$(view))
201 endef
202
203 define foreach/year/month/day/sensor/view
204 .PHONY: view/$(sensor)/$(year)/$(month)/$(day)/$(view)
205 view/$(sensor)/$(year)/$(month)/$(view): view/$(sensor)/$(year)/$(month)/$(day)/$(view)
206 $(call view/sensor/year/month/day/$(view))
207 endef
208
209 $(foreach sensor,$(sensors), \
210 $(foreach view,$(views), \
211 $(eval $(call foreach/sensor)) \
212 ) \
213 )
214 $(foreach year,$(years), \
215 $(foreach view,$(views), \
216 $(eval $(call foreach/year/view)) \
217 ) \
218 $(foreach sensor,$(sensors), \
219 $(foreach view,$(views), \
220 $(eval $(call foreach/year/sensor/view)) \
221 ) \
222 ) \
223 $(foreach month,$(months), \
224 $(foreach view,$(views), \
225 $(eval $(call foreach/year/month/view)) \
226 ) \
227 $(foreach sensor,$(sensors), \
228 $(foreach view,$(views), \
229 $(eval $(call foreach/year/month/sensor/view)) \
230 ) \
231 ) \
232 $(foreach day,$(days), \
233 $(foreach view,$(views), \
234 $(eval $(call foreach/year/month/day/view)) \
235 ) \
236 $(foreach sensor,$(sensors), \
237 $(foreach view,$(views), \
238 $(eval $(call foreach/year/month/day/sensor/view)) \
239 ) \
240 ) \
241 ) \
242 ) \
243 )