sd-card: Only add header to the results file if it’s empty
[brewing-logger:firmware.git] / Makefile
1 #
2 # Main code
3 #
4
5 MAIN_SOURCES = \
6         adc.c \
7         button.c \
8         flash-rom.c \
9         gas.c \
10         heater.c \
11         humidity.c \
12         krausen-level.c \
13         lcd.c \
14         main.c \
15         power.c \
16         rtc.c \
17         sd-card.c \
18         sleep.c \
19         spi.c \
20         temperature.c \
21         test.c \
22         $(NULL)
23
24 LIB_SOURCES = \
25         lib/diskio.c \
26         lib/ds3231.c \
27         lib/ff.c \
28         lib/i2c.c \
29         lib/serial_lcd.c \
30         $(NULL)
31
32 CFLAGS = \
33         -Wdeclaration-after-statement -Wextra -Wformat=2 -Winit-self -Winline -Wpacked -Wpointer-arith -Wlarger-than-65500 -Wmissing-declarations \
34         -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wsign-compare \
35         -Wstrict-aliasing=2 -Wstrict-prototypes -Wswitch-enum -Wundef -Wunsafe-loop-optimizations -Wwrite-strings -Wno-missing-field-initializers \
36         -Wno-unused-parameter -Wshadow -Wcast-align -Wformat-nonliteral -Wformat-security -Wswitch-default -Wmissing-include-dirs \
37         -Waggregate-return -Wredundant-decls -Warray-bounds -Wunreachable-code -ggdb
38 # CFLAGS which aren't supported on the lab machines
39 # CFLAGS += \
40 #       -Wunused-but-set-variable
41 CPPFLAGS = -Ilib
42
43 main.elf: $(MAIN_SOURCES:.c=.o) $(LIB_SOURCES:.c=.o)
44
45 all: main.hex
46 program-main: main.hex
47         $(call program,$<)
48 .PHONY: program-main all
49
50 clean-main:
51         rm -f $(MAIN_SOURCES:.c=.o) $(LIB_SOURCES:.c=.o) main.elf main.hex
52 .PHONY: clean-main
53
54
55 #
56 # Documentation
57 #
58 empty:=
59 space:= $(empty) $(empty)
60
61 docs: doxygen.conf
62         doxygen $<
63         @echo "Documentation generated as:"
64         @echo " file://$(subst $(space),%20,$(abspath docs))/html/index.html"
65 .PHONY: docs
66
67 clean-docs:
68         rm -rf docs
69 .PHONY: clean-docs
70
71
72 #
73 # Simulation using simavr
74 #
75 # If you want to debug it with gdb, run:
76 #  > ./simulation/main main.elf 1234
77 #  > avr-gdb main.elf
78 #  > > target remote :1234
79 #
80 simulate: main.elf
81         PKG_CONFIG_PATH=$$PKG_CONFIG_PATH:/home/philip/bin/simavr/lib/pkgconfig/ $(MAKE) -C simulation main
82         LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:/home/philip/bin/simavr/lib/ ./simulation/main main.elf 1234 sdcard.img
83 .PHONY: simulate
84
85
86 #
87 # SD card support
88 #
89 # Mount/Unmount the SD card image used by the simulator as a read-only loopback file system. This allows it to be inspected while the simulation is
90 # running.
91 #
92 mount-sd-card:
93         mkdir /tmp/fatfs
94         sudo losetup /dev/loop0 sdcard.img
95         sudo mount -o ro /dev/loop0 /tmp/fatfs
96 umount-sd-card:
97         sudo umount /dev/loop0
98         rmdir /tmp/fatfs
99         sudo losetup -d /dev/loop0
100 .PHONY: mount-sd-card umount-sd-card
101
102
103 #
104 # Fuses
105 #
106 # These are the default fuses, which result in using an 8MHz internal oscillator with no CLKOUT signal
107 # Note that some fuse bits (e.g. clock out) are active low
108 #
109 fuses:
110         avrdude -p $(AVRDUDE_MCU) -P $(AVRDUDE_PROGRAMMER_DEVNODE) -c $(AVRDUDE_PROGRAMMER) -e -U hfuse:w:0xd9:m
111         avrdude -p $(AVRDUDE_MCU) -P $(AVRDUDE_PROGRAMMER_DEVNODE) -c $(AVRDUDE_PROGRAMMER) -e -U lfuse:w:0x62:m
112
113
114 #
115 # Clean
116 #
117
118 clean: clean-docs clean-main
119 .PHONY: clean
120
121 #
122 # Common
123 #
124
125 CPPFLAGS=-I. -I./lib
126 MCU=atmega1284p
127 AVRDUDE_MCU=m1284p # see http://www.nongnu.org/avrdude/user-manual/avrdude_4.html#Option-Descriptions
128 AVRDUDE_PROGRAMMER=avrusb500 # USB FTDI device
129 AVRDUDE_PROGRAMMER_DEVNODE=/dev/ttyUSB0
130
131 # Common rules for compiling programs for the MCU.
132 %.o: %.c
133         @avr-gcc ${CPPFLAGS} -Wall -Os ${CFLAGS} -mmcu=${MCU} -o $@ -c $^
134
135 %.elf: %.o
136         avr-gcc -Os -mmcu=${MCU} -o $@ $^
137
138 %.hex: %.elf
139         avr-objcopy -j .text -j .data -O ihex $^ $@
140
141 %.lst: %.elf
142         avr-objdump -h -S $^ > $@
143
144 # Function to program the device with the hex file given in $1.
145 program = avrdude -p ${AVRDUDE_MCU} -P ${AVRDUDE_PROGRAMMER_DEVNODE} -c ${AVRDUDE_PROGRAMMER} -e -U flash:w:$1