]> Git — Sourcephile - julm/air-duino.git/blob - GNUmakefile
add javascript refresh
[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_dust=Particules
26 SENSOR_LABEL_air=Qualité de l’air
27 SENSOR_LABEL_co_ch4_lpg=CO/CH4/LPG
28 sensors := \
29 temperature \
30 humidity \
31 air \
32 dust \
33 co_ch4_lpg
34
35 #
36 ## Round Robin Database (RRD)
37 ###
38
39 RRD_CF := AVERAGE
40 .rrd = $(wildcard rrd/*/*.rrd)
41
42 #
43 ## INO
44 ###
45
46 # For GNU/Linux
47 ARDUINO_DIR := /usr/share/arduino/
48 ARDMK_DIR := /usr/share/arduino/
49 AVR_TOOLS_DIR := /usr
50
51 # For Seeeduino
52 BOARD_TAG := uno
53
54 ARDUINO_LIBS := \
55 AirQuality_Sensor \
56 DustSensor \
57 Humidity_Temperature_Sensor \
58 LCD_Display9696 \
59 Wire
60
61 USER_LIB_PATH := $(realpath ./libraries)
62
63 ifeq ($(NO_INO),)
64 include $(ARDMK_DIR)/Arduino.mk
65 endif
66
67 ino: $(TARGET_EEP) $(TARGET_HEX)
68
69 #
70 ## PNG
71 ###
72
73 define view/sensor/png
74 endef
75
76 define view/sensor/year/png
77 view/$(sensor)/$(year)/png:
78 endef
79
80 define view/sensor/year/month/png
81 view/$(sensor)/$(year)/$(month)/png: \
82 view/$(sensor)/$(year)/$(month).png
83
84 view/$(sensor)/$(year)/$(month).png: \
85 rrd/$(year)/$(month).rrd
86 mkdir -p $$(@D)
87 rrdtool graph $$@ \
88 -w 785 -h 120 -a PNG \
89 --slope-mode \
90 --start $(month_begin) --end $(month_end) \
91 --vertical-label '$$(SENSOR_LABEL_$(sensor))' \
92 --x-grid HOUR:8:DAY:1:DAY:1:86400:%d \
93 DEF:$(sensor)=rrd/$(year)/$(month).rrd:$(sensor):$$(RRD_CF) \
94 LINE1:$(sensor)'#ff0000':"$(sensor)"
95 endef
96
97 define view/sensor/year/month/day/png
98 view/$(sensor)/$(year)/$(month)/$(day)/png: \
99 view/$(sensor)/$(year)/$(month)/$(day).png
100
101 view/$(sensor)/$(year)/$(month)/$(day).png: \
102 rrd/$(year)/$(month).rrd
103 mkdir -p $$(@D)
104 rrdtool graph $$@ \
105 -w 785 -h 120 -a PNG \
106 --slope-mode \
107 --start $(day_begin) --end $(day_end) \
108 --vertical-label '$$(SENSOR_LABEL_$(sensor))' \
109 --x-grid MINUTE:10:HOUR:1:HOUR:1:0:%H \
110 DEF:$(sensor)=rrd/$(year)/$(month).rrd:$(sensor):$$(RRD_CF) \
111 LINE1:$(sensor)'#ff0000':"$(sensor)";
112 endef
113
114 define view/year/month/png
115 view/$(year)/$(month)/png: \
116 $(foreach sensor,$(sensors), view/$(sensor)/$(year)/$(month)/png)
117 endef
118 define view/year/month/day/png
119 view/$(year)/$(month)/$(day)/png: \
120 $(foreach sensor,$(sensors), view/$(sensor)/$(year)/$(month)/$(day)/png)
121 endef
122
123 #
124 ## HTML5
125 ###
126
127 define view/sensor/html5
128 endef
129
130 define view/sensor/year/html5
131 view/$(sensor)/$(year)/html5:
132 endef
133
134 define view/sensor/year/month/html5
135 view/$(sensor)/$(year)/$(month)/html5: \
136 view/$(sensor)/$(year)/$(month).html5
137
138 view/$(sensor)/$(year)/$(month).html5: \
139 view/$(sensor)/$(year)/$(month)/png
140 printf ' \
141 <report sensor="$(sensor)" year="$(year)" month="$(month)"> \
142 $(foreach day,$(days), \
143 <date \
144 day="$(day)" \
145 day-name="$$(shell date +'%A' -d '$(year)/$(month)/$(day)')"/>) \
146 </report>' | \
147 xsltproc --output $$@ \
148 xsl/sensor/year/month.html5.xsl -
149 endef
150 define view/year/month/html5
151 view/$(year)/$(month)/html5: \
152 view/$(year)/$(month).html5
153
154 view/$(year)/$(month).html5: \
155 view/$(year)/$(month)/png
156 mkdir -p $$(@D)
157 printf ' \
158 <report year="$(year)" month="$(month)"> \
159 $(foreach day,$(days), \
160 <date \
161 day="$(day)" \
162 day-name="$$(shell date +'%A' -d '$(year)/$(month)/$(day)')"> \
163 $(foreach sensor,$(sensors), \
164 <sensor name="$(sensor)"/> \
165 ) \
166 </date>) \
167 </report>' | \
168 xsltproc --output $$@ \
169 xsl/year/month.html5.xsl -
170 endef
171
172 #
173 ## Dates
174 ###
175 years=$(call uniq,$(foreach rrd,$(.rrd),$(word 2,$(subst /, ,$(rrd)))))
176 months=$(foreach rrd,$(filter rrd/$(year)/%,$(.rrd)),$(basename $(word 3,$(subst /, ,$(rrd)))))
177 days=$(shell seq -w $$(date +'%d' -d '$(year)/$(month)/01 + 1 month - 1 second'))
178
179 month_begin=$(shell date +'%s' -d '$(year)/$(month)/01')
180 month_end=$(shell date +'%s' -d '$(year)/$(month)/01 + 1 month - 1 second')
181
182 day_begin=$(shell date +'%s' -d '$(year)/$(month)/$(day)')
183 day_end=$(shell date +'%s' -d '$(year)/$(month)/$(day) + 1 day - 1 second')
184
185 define foreach/sensor
186 .PHONY: view/$(sensor)/$(view)
187 view/$(view): view/$(sensor)/$(view)
188 $(call view/sensor/$(view))
189 endef
190
191 define foreach/year/sensor/view
192 .PHONY: view/$(sensor)/$(year)/$(view)
193 view/$(sensor)/$(view): view/$(sensor)/$(year)/$(view)
194 $(call view/sensor/year/$(view))
195 endef
196
197 define foreach/year/month/sensor/view
198 .PHONY: view/$(sensor)/$(year)/$(month)/$(view)
199 view/$(sensor)/$(year)/$(view): view/$(sensor)/$(year)/$(month)/$(view)
200 $(call view/sensor/year/month/$(view))
201 endef
202 define foreach/year/month/view
203 .PHONY: view/$(year)/$(month)/$(view)
204 view/$(year)/$(view): view/$(year)/$(month)/$(view)
205 $(call view/year/month/$(view))
206 endef
207
208 define foreach/year/month/day/sensor/view
209 .PHONY: view/$(sensor)/$(year)/$(month)/$(day)/$(view)
210 view/$(sensor)/$(year)/$(month)/$(view): view/$(sensor)/$(year)/$(month)/$(day)/$(view)
211 $(call view/sensor/year/month/day/$(view))
212 endef
213 define foreach/year/month/day/view
214 .PHONY: view/$(year)/$(month)/$(day)/$(view)
215 view/$(year)/$(month)/$(view): view/$(year)/$(month)/$(day)/$(view)
216 $(call view/year/month/day/$(view))
217 endef
218
219 $(foreach sensor,$(sensors), \
220 $(foreach view,$(views), \
221 $(eval $(call foreach/sensor)) \
222 ) \
223 )
224 $(foreach year,$(years), \
225 $(foreach view,$(views), \
226 $(eval $(call foreach/year/view)) \
227 ) \
228 $(foreach sensor,$(sensors), \
229 $(foreach view,$(views), \
230 $(eval $(call foreach/year/sensor/view)) \
231 ) \
232 ) \
233 $(foreach month,$(months), \
234 $(foreach view,$(views), \
235 $(eval $(call foreach/year/month/view)) \
236 ) \
237 $(foreach sensor,$(sensors), \
238 $(foreach view,$(views), \
239 $(eval $(call foreach/year/month/sensor/view)) \
240 ) \
241 ) \
242 $(foreach day,$(days), \
243 $(foreach view,$(views), \
244 $(eval $(call foreach/year/month/day/view)) \
245 ) \
246 $(foreach sensor,$(sensors), \
247 $(foreach view,$(views), \
248 $(eval $(call foreach/year/month/day/sensor/view)) \
249 ) \
250 ) \
251 ) \
252 ) \
253 )