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