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