summaryrefslogtreecommitdiff
path: root/robot/makefile
diff options
context:
space:
mode:
Diffstat (limited to 'robot/makefile')
-rw-r--r--robot/makefile28
1 files changed, 20 insertions, 8 deletions
diff --git a/robot/makefile b/robot/makefile
index 598e0fa..6f50519 100644
--- a/robot/makefile
+++ b/robot/makefile
@@ -5,23 +5,33 @@ DEVICE ?= atmega168
MCU ?= atmega168
AVRDUDE_DEVICE ?= m168
-CFLAGS=-g -Wall -mcall-prologues -mmcu=$(MCU) $(DEVICE_SPECIFIC_CFLAGS) -Os
-LDFLAGS=-Wl,-gc-sections -lpololu_$(DEVICE) -Wl,-relax
-
PORT ?= /dev/ttyACM0
-SOURCES := $(wildcard *.c)
-HEADERS := $(wildcard *.h)
+CFLAGS=-g -Wall $(DEVICE_SPECIFIC_CFLAGS) -Os
+LDFLAGS=-Wl,-gc-sections -Wl,-relax
+
+SOURCES := $(filter-out sim.c, $(wildcard *.c))
+HEADERS := $(filter-out sim.h, $(wildcard *.h))
+
+# simulation
+# SIM = true
+CFLAGS += $(if $(SIM), -DW2_SIM, -mcall-prologues -mmcu=$(MCU))
+LDFLAGS += $(if $(SIM), , -lpololu_$(DEVICE))
+PREFIX := $(if $(SIM), , avr-)
+SOURCES += $(if $(SIM), sim.c, )
+HEADERS += $(if $(SIM), sim.h, )
+
OBJECTS := $(patsubst %.c,%.o, $(SOURCES))
AVRDUDE=avrdude
-CC=avr-gcc
-OBJ2HEX=avr-objcopy
+CC=$(PREFIX)gcc
+OBJ2HEX=$(PREFIX)objcopy
+# debug build info string
BUILD_STR=$(shell git update-index -q --refresh; git describe --tags --dirty='*' --broken='x' | cut -c1-20)
CFLAGS += -DW2_BUILD_STR="$(BUILD_STR)"
-all: out.hex
+all: $(if $(SIM), a.out, out.hex)
clean:
rm -f *.o out.hex a.out compile_commands.json
@@ -40,6 +50,8 @@ flash: out.hex
$(AVRDUDE) -p $(AVRDUDE_DEVICE) -c avrisp2 -P $(PORT) -U flash:w:out.hex
format:
+ $(eval SOURCES := $(filter-out sim.c, $(SOURCES)))
+ $(eval HEADERS := $(filter-out sim.h, $(HEADERS)))
clang-format -i $(SOURCES) $(HEADERS)
clang-tidy --fix-errors $(SOURCES) $(HEADERS)