1 # Override with `make BUILD=release`
2 # default to debug build
5 # You must create the file "local.propertiessudo" on your local machine which contains any local paths, etc
6 # local_settings.mk should NOT be committed to repo
7 include ../../local.properties
13 OBJCopy := avr-objcopy
15 # Name of testing application
17 C_COMPONENTS_DIR := ocrandom
19 # Folders that contain C source code
20 C_SRC_DIR := $(foreach d, $(C_COMPONENTS_DIR),../../../$d/src)
22 #Folders that contain C source code related to arduino
23 C_SRC_DIR_ARDUINO := $(ARDUINO_DIR)/hardware/arduino/cores/arduino
25 #Folders that contain CPP source code
26 CPP_SRC_DIR := ../../test/arduino
28 #Folders that contain CPP source code related to arduino
29 CPP_SRC_DIR_ARDUINO := $(ARDUINO_DIR)/hardware/arduino/cores/arduino
31 # Folders that contain Headers
32 TEMP_INC_DIR := $(foreach d, $(C_COMPONENTS_DIR),../../../$d/include)
33 TEMP_INC_DIR2 := $(foreach d, $(CXX_COMPONENTS_DIR),../../../$d/include)
34 INC_DIR := $(TEMP_INC_DIR) $(TEMP_INC_DIR2)
35 INC_DIR += $(ARDUINO_DIR)/hardware/arduino/cores/arduino
36 INC_DIR += $(ARDUINO_DIR)/hardware/arduino/variants/mega
37 INC_CMD = $(foreach d, $(INC_DIR), -I$d)
39 # Compiler flags specific to arduino
40 ARDUINO_FLAGS = -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=156 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR -MMD
43 CC_FLAGS.debug := -c -Os -Wall -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -std=c99 -DATMEGA2560 -DTB_LOG
44 CC_FLAGS.release := -c -Os -Wall -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -std=c99 -DATMEGA2560
45 CC_FLAGS := $(CC_FLAGS.$(BUILD))
47 CXX_FLAGS.debug := -c -Os -Wall -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -felide-constructors -std=c++0x -DATMEGA2560 -DTB_LOG
48 CXX_FLAGS.release := -c -Os -Wall -Wno-write-strings -ffunction-sections -fdata-sections -fno-exceptions -felide-constructors -std=c++0x -DATMEGA2560
49 CXX_FLAGS := $(CXX_FLAGS.$(BUILD))
51 # using make's computed variables to select object and bin folders
52 # depending on the build type
53 OBJ_DIR.debug := ./obj/debug
54 OBJ_DIR.release := ./obj/release
55 OBJ_DIR := $(OBJ_DIR.$(BUILD))
57 BIN_DIR.debug := ./bin/debug
58 BIN_DIR.release := ./bin/release
59 BIN_DIR := $(BIN_DIR.$(BUILD))
61 C_FILES := $(shell find $(C_SRC_DIR) -maxdepth 1 -name '*.c')
62 CPP_FILES := $(shell find $(CPP_SRC_DIR) -maxdepth 1 -name '*.cpp')
63 OBJ_FILES := $(addprefix $(OBJ_DIR)/,$(notdir $(CPP_FILES:.cpp=.o) $(C_FILES:.c=.o)))
65 C_FILES_ARDUINO := $(shell find $(C_SRC_DIR_ARDUINO) -maxdepth 1 -name '*.c')
66 CPP_FILES_ARDUINO := $(shell find $(CPP_SRC_DIR_ARDUINO) -maxdepth 1 -name '*.cpp')
67 OBJ_FILES_ARDUINO := $(addprefix $(OBJ_DIR)/,$(notdir $(CPP_FILES_ARDUINO:.cpp=.o) $(C_FILES_ARDUINO:.c=.o)))
69 all: $(BIN_DIR)/$(PROG).hex
71 $(BIN_DIR)/core.a: $(OBJ_FILES_ARDUINO)
74 #mv ./core.a ./$(BIN_DIR)
76 @echo 'done making core.a'
78 $(OBJ_DIR)/%.o: $(CPP_SRC_DIR_ARDUINO)/%.cpp
80 $(CXX) $(CXX_FLAGS) $(ARDUINO_FLAGS) $(INC_CMD) $< -o $@
82 $(OBJ_DIR)/%.o: $(CPP_SRC_DIR)/%.cpp
84 $(CXX) $(CXX_FLAGS) $(ARDUINO_FLAGS) $(INC_CMD) $< -o $@
86 $(OBJ_DIR)/%.o: $(C_SRC_DIR_ARDUINO)/%.c
88 $(CC) $(CC_FLAGS) $(ARDUINO_FLAGS) $(INC_CMD) $< -o $@
90 $(OBJ_DIR)/%.o: $(C_SRC_DIR)/%.c
92 $(CXX) $(CXX_FLAGS) $(ARDUINO_FLAGS) $(INC_CMD) $< -o $@
94 $(BIN_DIR)/$(PROG).elf: $(OBJ_FILES) $(BIN_DIR)/core.a
95 #$(CC) -Os -Wl,--gc-sections,--relax $(ARDUINO_FLAGS) $< $(BIN_DIR)/core.a -lm -o $@
96 #$(CC) -Os -Wl,--gc-sections,--relax $(ARDUINO_FLAGS) $(OBJ_FILES) $(OBJ_FILES_ARDUINO) -lm -o $@
97 $(CC) -Os -Wl,--gc-sections,--relax $(ARDUINO_FLAGS) $(OBJ_FILES) $(BIN_DIR)/core.a -lm -o $@
99 @echo 'done making elf'
101 $(BIN_DIR)/$(PROG).hex: $(BIN_DIR)/$(PROG).elf
102 $(OBJCopy) -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 $< $(BIN_DIR)/$(PROG).eep
103 $(OBJCopy) -O ihex -R .eeprom $< $@
105 @echo 'done making hex'
108 #$(ARDUINO_DIR)/hardware/tools/avrdude -C$(ARDUINO_DIR)/hardware/tools/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P/dev/ttyACM0 -b115200 -D -Uflash:w:$(BIN_DIR)/$(PROG).hex:i
109 avrdude -C$(ARDUINO_DIR)/hardware/tools/avrdude.conf -v -v -v -v -patmega2560 -cstk500v2 -P/dev/ttyACM0 -b115200 -D -Uflash:w:$(BIN_DIR)/$(PROG).hex:i
114 rm -rf ./obj/release/*
116 rm -rf ./lib/release/*
118 rm -rf ./bin/release/*
119 rm -rf ./test/tst_*.txt
127 @echo 'BUILD = '$(value BUILD)
128 @echo 'C_SRC_DIR = '$(value C_SRC_DIR)
129 @echo 'C_SRC_DIR_ARDUINO = '$(value C_SRC_DIR_ARDUINO)
130 @echo 'CPP_SRC_DIR = '$(CPP_SRC_DIR)
131 @echo 'CPP_SRC_DIR_ARDUINO = '$(value CPP_SRC_DIR_ARDUINO)
132 @echo 'INC_DIR = '$(INC_DIR)
133 @echo 'H_FILES = '$(H_FILES)
134 @echo 'C_FILES = '$(C_FILES)
135 @echo 'CPP_FILES = '$(CPP_FILES)
136 @echo 'C_FILES_ARDUINO = '$(C_FILES_ARDUINO)
137 @echo 'CPP_FILES_ARDUINO = '$(CPP_FILES_ARDUINO)
138 @echo 'OBJ_FILES = '$(OBJ_FILES)
139 @echo 'OBJ_FILES_ARDUINO = '$(OBJ_FILES_ARDUINO)