]> Git — Sourcephile - julm/air-duino.git/blob - GNUmakefile
add systemd and udev config
[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 define view/year/month/png
113 view/$(year)/$(month)/png: \
114 $(foreach sensor,$(sensors), view/$(sensor)/$(year)/$(month)/png)
115 endef
116 define view/year/month/day/png
117 view/$(year)/$(month)/$(day)/png: \
118 $(foreach sensor,$(sensors), view/$(sensor)/$(year)/$(month)/$(day)/png)
119 endef
120
121 #
122 ## HTML5
123 ###
124
125 define view/sensor/html5
126 endef
127
128 define view/sensor/year/html5
129 view/$(sensor)/$(year)/html5:
130 endef
131
132 define view/sensor/year/month/html5
133 view/$(sensor)/$(year)/$(month)/html5: \
134 view/$(sensor)/$(year)/$(month).html5
135
136 view/$(sensor)/$(year)/$(month).html5: \
137 view/$(sensor)/$(year)/$(month)/png
138 printf ' \
139 <report sensor="$(sensor)" year="$(year)" month="$(month)"> \
140 $(foreach day,$(days), \
141 <date \
142 day="$(day)" \
143 day-name="$$(shell date +'%A' -d '$(year)/$(month)/$(day)')"/>) \
144 </report>' | \
145 xsltproc --output $$@ \
146 xsl/sensor/year/month.html5.xsl -
147 endef
148 define view/year/month/html5
149 view/$(year)/$(month)/html5: \
150 view/$(year)/$(month).html5
151
152 view/$(year)/$(month).html5: \
153 view/$(year)/$(month)/png
154 mkdir -p $$(@D)
155 printf ' \
156 <report year="$(year)" month="$(month)"> \
157 $(foreach day,$(days), \
158 <date \
159 day="$(day)" \
160 day-name="$$(shell date +'%A' -d '$(year)/$(month)/$(day)')"> \
161 $(foreach sensor,$(sensors), \
162 <sensor name="$(sensor)"/> \
163 ) \
164 </date>) \
165 </report>' | \
166 xsltproc --output $$@ \
167 xsl/year/month.html5.xsl -
168 endef
169
170 #
171 ## Dates
172 ###
173 years=$(call uniq,$(foreach rrd,$(.rrd),$(word 2,$(subst /, ,$(rrd)))))
174 months=$(foreach rrd,$(filter rrd/$(year)/%,$(.rrd)),$(basename $(word 3,$(subst /, ,$(rrd)))))
175 days=$(shell seq -w $$(date +'%d' -d '$(year)/$(month)/01 + 1 month - 1 second'))
176
177 month_begin=$(shell date +'%s' -d '$(year)/$(month)/01')
178 month_end=$(shell date +'%s' -d '$(year)/$(month)/01 + 1 month - 1 second')
179
180 day_begin=$(shell date +'%s' -d '$(year)/$(month)/$(day)')
181 day_end=$(shell date +'%s' -d '$(year)/$(month)/$(day) + 1 day - 1 second')
182
183 define foreach/sensor
184 .PHONY: view/$(sensor)/$(view)
185 view/$(view): view/$(sensor)/$(view)
186 $(call view/sensor/$(view))
187 endef
188
189 define foreach/year/sensor/view
190 .PHONY: view/$(sensor)/$(year)/$(view)
191 view/$(sensor)/$(view): view/$(sensor)/$(year)/$(view)
192 $(call view/sensor/year/$(view))
193 endef
194
195 define foreach/year/month/sensor/view
196 .PHONY: view/$(sensor)/$(year)/$(month)/$(view)
197 view/$(sensor)/$(year)/$(view): view/$(sensor)/$(year)/$(month)/$(view)
198 $(call view/sensor/year/month/$(view))
199 endef
200 define foreach/year/month/view
201 .PHONY: view/$(year)/$(month)/$(view)
202 view/$(year)/$(view): view/$(year)/$(month)/$(view)
203 $(call view/year/month/$(view))
204 endef
205
206 define foreach/year/month/day/sensor/view
207 .PHONY: view/$(sensor)/$(year)/$(month)/$(day)/$(view)
208 view/$(sensor)/$(year)/$(month)/$(view): view/$(sensor)/$(year)/$(month)/$(day)/$(view)
209 $(call view/sensor/year/month/day/$(view))
210 endef
211 define foreach/year/month/day/view
212 .PHONY: view/$(year)/$(month)/$(day)/$(view)
213 view/$(year)/$(month)/$(view): view/$(year)/$(month)/$(day)/$(view)
214 $(call view/year/month/day/$(view))
215 endef
216
217 $(foreach sensor,$(sensors), \
218 $(foreach view,$(views), \
219 $(eval $(call foreach/sensor)) \
220 ) \
221 )
222 $(foreach year,$(years), \
223 $(foreach view,$(views), \
224 $(eval $(call foreach/year/view)) \
225 ) \
226 $(foreach sensor,$(sensors), \
227 $(foreach view,$(views), \
228 $(eval $(call foreach/year/sensor/view)) \
229 ) \
230 ) \
231 $(foreach month,$(months), \
232 $(foreach view,$(views), \
233 $(eval $(call foreach/year/month/view)) \
234 ) \
235 $(foreach sensor,$(sensors), \
236 $(foreach view,$(views), \
237 $(eval $(call foreach/year/month/sensor/view)) \
238 ) \
239 ) \
240 $(foreach day,$(days), \
241 $(foreach view,$(views), \
242 $(eval $(call foreach/year/month/day/view)) \
243 ) \
244 $(foreach sensor,$(sensors), \
245 $(foreach view,$(views), \
246 $(eval $(call foreach/year/month/day/sensor/view)) \
247 ) \
248 ) \
249 ) \
250 ) \
251 )