Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
148 lines (123 loc) · 4.59 KB
/
Copy pathMakefile
File metadata and controls
148 lines (123 loc) · 4.59 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
################################################################################
# \brief Makefile which controls the generation of the WiFiRoomSensor
#
# \details The first few lines may be used to configure the setup. The later
# lines specify the overall build process. Supported targets:
# * all: Builds everything but avoids any installation
# * clean: Removes every generated file
# * install: Uploads the source code to the MCU
# * doc: Generates the documentation
# * binary: Generates the binary files
# * size: Computes the size of the output
#
# \author Michael Spiegel, <michael.h.spiegel@gmail.com>
#
# Copyright (C) 2016 Michael Spiegel
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
################################################################################
# \brief Lists each source file of the project relative to the source directory
SRC_FILES = main.c am2303.c esp8266_transceiver.c system_timer.c
SRC_FILES += esp8266_session.c iec61499_com.c soft_uart.c oscillator.c
SRC_FILES += ws2801.c button_cnt.c
# \brief The name of the project
PROJECT = WiFiRoomSensor
# \brief The path to the binary directory
BINDIR = bin
# \brief The path of the source directory
SRCDIR = src
# \brief The documentation directory
DOCDIR = doc/api_doc
# \brief The target microcontroller (GCC's -mmcu option)
MCU = atmega8
# \brief The target microcontroller for avrdude
PROG_MCU = m8
# \brief The CPU frequency
F_CPU = 8280000UL
# \brief If defined, overrides the read oscal values.
# \details The values may be used to tweak the frequency of the processor such
# that the required UART baudrate can be achieved
MAN_OSCCAL = 0xbb,0xbb,0xbb,0xbb
# The commands in use
CC = avr-gcc
LD = avr-gcc
PROG = avrdude
PSIZE = avr-size
OCOPY = avr-objcopy
ODUMP = avr-objdump
DOX = doxygen
GDB = gdb
# \brief The compiler flags
CC_FLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -Wall -Wstrict-prototypes -O3
CC_FLAGS += -frename-registers -fshort-enums -fpack-struct
CC_FLAGS += -std=gnu99
#CC_FLAGS += -DNDEBUG
#CC_FLAGS += -DUSE_AM2303_CHN1
CC_FLAGS += -DUSE_WS2801
CC_FLAGS += -DUSE_BUTTON_CNT
# \brief The linker flags
LD_FLAGS = -mmcu=$(MCU)
# \brief The programmer flags
PROG_FLAGS = -p$(PROG_MCU) -cavrisp2 -Pusb
# \brief The fuse values to set
PROG_FUSE = -Ulfuse:w:0xe4:m -Uhfuse:w:0xd1:m
# \brief The destination object files
OBJ=$(SRC_FILES:%.c=$(BINDIR)/%.o)
.PHONY: all size clean binary install doc
all: binary
binary: $(BINDIR)/$(PROJECT).elf $(BINDIR)/$(PROJECT).lss size
$(BINDIR):
mkdir $(BINDIR)
$(DOCDIR):
mkdir -p $(DOCDIR)
$(BINDIR)/%.o: $(SRCDIR)/%.c $(BINDIR) $(SRCDIR)/*.h
$(CC) $(CC_FLAGS) -c -o $@ $<
$(BINDIR)/$(PROJECT).elf: $(OBJ)
$(LD) $(LD_FLAGS) -o $@ $^
# \brief Reads the calibration from the connected MCU
$(BINDIR)/calibration.txt:
$(PROG) $(PROG_FLAGS) -Ucalibration:r:$@:h
# Create the batch file which manipulates the oscal value
ifdef MAN_OSCCAL
$(BINDIR)/conf.batch:
echo "set var (char[4]) oscillator_calibration = { $(MAN_OSCCAL) }" > $@
else
$(BINDIR)/conf.batch: $(BINDIR)/calibration.txt
echo -n "set var (char[4]) oscillator_calibration = { " > $@
cat $(BINDIR)/calibration.txt | tr -d '\n\r' >> $@
echo " }" >> $@
endif
# Sets the dynamic variables
$(BINDIR)/$(PROJECT).mod.elf: $(BINDIR)/$(PROJECT).elf $(BINDIR)/conf.batch
cp $< $@
$(GDB) -batch -x $(BINDIR)/conf.batch --write $@
$(BINDIR)/$(PROJECT).hex: $(BINDIR)/$(PROJECT).mod.elf
$(OCOPY) -R .eeprom -R .fuse -R .lock -R .signature -O ihex $< $@
$(BINDIR)/$(PROJECT).eep: $(BINDIR)/$(PROJECT).mod.elf
$(OCOPY) -j .eeprom --no-change-warnings --change-section-lma .eeprom=0 \
-O ihex $< $@
$(BINDIR)/$(PROJECT).lss: $(BINDIR)/$(PROJECT).elf
$(ODUMP) -h -S $< >$@
size: $(BINDIR)/$(PROJECT).elf
$(PSIZE) --format=avr --mcu=$(MCU) $<
install: $(BINDIR)/$(PROJECT).hex $(BINDIR)/$(PROJECT).eep
$(PROG) $(PROG_FLAGS) \
-Uflash:w:$(BINDIR)/$(PROJECT).hex:a \
-Ueeprom:w:$(BINDIR)/$(PROJECT).eep:a \
$(PROG_FUSE)
doc: $(DOCDIR) $(SRCDIR)/*.c $(SRCDIR)/*.h
$(DOX) Doxyfile
clean:
rm -rf $(BINDIR)
rm -rf $(DOCDIR)