]> Git — Sourcephile - julm/air-duino.git/blob - GNUmakefile
fix png/$(sensor) (bis)
[julm/air-duino.git] / GNUmakefile
1 # Licence: WTFPLv2 <http://www.wtfpl.net/txt/copying/>
2 # Copyright 2015: Julien Moutinho <julm+air@autogeree.net>
3
4 .SECONDARY:
5 .SUFFIXES:
6 MAKEFLAGS += -r
7 RRD_CF:=AVERAGE
8 SENSORS:= \
9 humidity \
10 temperature \
11 quality \
12 particles
13
14 .rrd = $(wildcard rrd/*/*.rrd)
15
16 all: png
17
18 #
19 ## INO
20 ###
21
22 # For GNU/Linux
23 ARDUINO_DIR := /usr/share/arduino/
24 ARDMK_DIR := /usr/share/arduino/
25 AVR_TOOLS_DIR := /usr
26
27 # For Seeeduino
28 BOARD_TAG := uno
29
30 ARDUINO_LIBS := \
31 AirQuality_Sensor \
32 DustSensor \
33 Humidity_Temperature_Sensor \
34 LCD_Display9696 \
35 Wire
36
37 USER_LIB_PATH := $(abspath ./libraries)
38
39 #include $(ARDMK_DIR)/Arduino.mk
40
41 ino: $(TARGET_EEP) $(TARGET_HEX)
42
43 #
44 ## PNG
45 ###
46 .PHONY: png $(addprefix png/,$(SENSORS))
47 png: $(addprefix png/,$(SENSORS))
48
49 ym=$(patsubst %.rrd,,$(notdir $*))
50 month_begin=$(shell date +'%s' -d '$(ym)/01')
51 month_end=$(shell date +'%s' -d '$(ym)/01 + 1 month - 1 second')
52 month_length=$(shell date +'%d' -d '$(ym)/01 + 1 month - 1 second')
53 day_begin=$(shell date +'%s' -d '$(ym)/$(day)')
54 day_end=$(shell date +'%s' -d '$(ym)/$(day) + 1 month - 1 second')
55
56 define png/sensor
57 png/$(sensor): \
58 $$(patsubst rrd/%.rrd,png/$(sensor)/%.png,$$(.rrd))
59
60
61 png/$(sensor)/%.png: rrd/%.rrd
62 mkdir -p png/$(sensor)/$$*
63 rrdtool graph $$@ \
64 -w 785 -h 120 -a PNG \
65 --slope-mode \
66 --start $$(month_begin) --end $$(month_end) \
67 --vertical-label '$$(SENSOR_LABEL_$(sensor))' \
68 --x-grid HOUR:8:DAY:1:DAY:1:86400:%d \
69 DEF:$(sensor)=rrd/$$*.rrd:$(sensor):$$(RRD_CF) \
70 LINE1:$(sensor)'#ff0000':"$(sensor)"
71 for day in $$(shell seq -w $$(month_length)); \
72 do \
73 day_begin=$$$$(date +'%s' -d "$$(ym)/$$$$day"); \
74 day_end=$$$$(date +'%s' -d "$$(ym)/$$$$day + 1 day - 1 second"); \
75 rrdtool graph png/$(sensor)/$$*/$$$$day.png \
76 -w 785 -h 120 -a PNG \
77 --slope-mode \
78 --start $$$$day_begin --end $$$$day_end \
79 --vertical-label '$$(SENSOR_LABEL_$(sensor))' \
80 --x-grid MINUTE:10:HOUR:1:HOUR:1:0:%H \
81 DEF:$(sensor)=rrd/$$*.rrd:$(sensor):$$(RRD_CF) \
82 LINE1:$(sensor)'#ff0000':"$(sensor)"; \
83 done
84 endef
85
86 SENSOR_LABEL_temperature=Température (°C)
87 SENSOR_LABEL_humidity=Humidité (%)
88 SENSOR_LABEL_particles=Particules
89 SENSOR_LABEL_quality=Qualité de l’air
90 $(foreach sensor,$(SENSORS),$(eval $(call png/sensor)))