-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
87 lines (72 loc) · 2.64 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# AVR-Geiger
# https://github.com/gcavallo/AVR-Geiger
# Copyright (c) 2015, Gabriel Cavallo
# GPLv3 License https://gnu.org/licenses/gpl.txt
DEVICE = atmega328p
PROGRAMMER = usbasp
PORT = /dev/ttyACM0
NAME = geiger
SRCDIR = avr
OBJDIR = avr/obj
BINDIR = avr/bin
OBJECTS = $(patsubst $(SRCDIR)/%.c,%.o,$(wildcard $(SRCDIR)/*.c))
VPATH = $(SRCDIR)
CC = avr-gcc -mmcu=$(DEVICE)
CFLAGS = -Wall -Wextra -Werror -Os -std=c99 -pedantic
AVRDUDE = avrdude -v -c $(PROGRAMMER) -p $(DEVICE) -P $(PORT) -b 57600 -D -U flash:w:$(BINDIR)/$(NAME).hex:i
.PHONY: test
all: $(BINDIR)/$(NAME).hex
help:
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
install: ## install daemon on this system.
cp daemon/geiger /usr/local/bin && chmod 755 /usr/local/bin/geiger
ifneq ($(wildcard /usr/share/geiger),)
$(info "/usr/share/geiger" exists)
else
mkdir -p /usr/share/geiger && chmod 755 /usr/share/geiger
endif
ifneq ($(wildcard /usr/share/geiger/geiger.conf),)
$(info "/usr/share/geiger/geiger.conf" exists)
else
cp daemon/geiger.conf /usr/share/geiger && chmod 640 /usr/share/geiger/geiger.conf
endif
ifneq ($(wildcard /usr/share/geiger/geiger.rrd),)
$(info "/usr/share/geiger/geiger.rrd" exists)
else
rrdtool create "/usr/share/geiger/geiger.rrd" --no-overwrite --step=1 \
DS:cpm:GAUGE:1m:0:U RRA:AVERAGE:0.5:1m:1w RRA:AVERAGE:0.5:1h:1y \
&& chmod 640 /usr/share/geiger/geiger.conf
endif
ifneq ($(wildcard /etc/systemd/system),)
cp daemon/geiger.service /etc/systemd/system && chmod 644 /etc/systemd/system/geiger.service
@echo Enable daemon with \'systemctl enable geiger.service\' as root!
else
$(warning Systemd not found!)
endif
uninstall: ## remove all files from system including database and configs.
uninstall: clean
rm -rf /usr/share/geiger
rm -f /usr/lib/systemd/user/geiger.service
clean: ## remove binary files for reinstall (keep database and config).
rm -f $(BINDIR)/$(NAME).hex $(BINDIR)/$(NAME).elf $(addprefix $(OBJDIR)/, $(OBJECTS))
rm -f /usr/local/bin/geiger
flash: ## flash microcontroller with an AVR programmer.
$(AVRDUDE)
test:
gcc $(CFLAGS) test/test.c -o test/test
chmod 755 test/test
@echo -e "\e[1;32m"
@test/test
@echo -e "\e[0m"
dump: ## dump AVR binary for debug.
@echo -e "\e[1;33m"
@avr-objdump -d $(BINDIR)/$(NAME).elf
@echo -e "\e[1;31m"
@avr-size --format=avr --mcu=$(DEVICE) $(BINDIR)/$(NAME).elf
@echo -e "\e[0m"
$(OBJDIR)/%.o: %.c
$(CC) -c $(CFLAGS) -o $@ $<
$(BINDIR)/$(NAME).elf: $(addprefix $(OBJDIR)/, $(OBJECTS))
$(CC) -o $@ $^
$(BINDIR)/$(NAME).hex: $(BINDIR)/$(NAME).elf
avr-objcopy -O ihex -R .eeprom $(BINDIR)/$(NAME).elf $(BINDIR)/$(NAME).hex