| ␊ |
| PORT=/dev/ttyACM0␊ |
| ARDUINO_DIR=/usr/share/arduino␊ |
| BOARD_TYPE=arduino␊ |
| BAUD_RATE=115200␊ |
| MCU=atmega328p␊ |
| DF_CPU=16000000␊ |
| CORE_C_FILES=pins_arduino wiring wiring_digital␊ |
| CORE_CPP_FILES=main HardwareSerial Print␊ |
| CPP_FILES=greenhouse dht11␊ |
| ␊ |
| ARDUINO_CORE=$(ARDUINO_DIR)/hardware/arduino/cores/arduino␊ |
| INCLUDE=-I. -I$(ARDUINO_DIR)/hardware/arduino/cores/arduino␊ |
| CC=/usr/bin/avr-gcc␊ |
| CPP=/usr/bin/avr-g++␊ |
| AVR_OBJCOPY=/usr/bin/avr-objcopy ␊ |
| AVRDUDE=/usr/bin/avrdude␊ |
| AVRDUDE_CONF=/etc/avrdude.conf␊ |
| CC_FLAGS=-g -Os -w -Wall -ffunction-sections -fdata-sections -fno-exceptions -std=gnu99␊ |
| CPP_FLAGS=-g -Os -w -Wall -ffunction-sections -fdata-sections -fno-exceptions␊ |
| ␊ |
| all:␉␉clean compile upload␊ |
| ␊ |
| clean:␊ |
| ␉␉@echo '# *** Cleaning...'␊ |
| ␉␉rm -rf bin/␊ |
| ␊ |
| compile:␊ |
| ␉␉@echo '# *** Compiling...'␊ |
| ␊ |
| ␉␉mkdir -p bin␊ |
| ␊ |
| ␉␉for cpp_file in ${CPP_FILES}; do \␊ |
| ␉␉␉$(CPP) -c -mmcu=$(MCU) -DF_CPU=$(DF_CPU) $(INCLUDE) \␊ |
| ␉␉␉$(CPP_FLAGS) $$cpp_file.cpp -o bin/$$cpp_file.o; \␊ |
| ␉␉done␊ |
| ␉␉␊ |
| ␉␉for core_c_file in ${CORE_C_FILES}; do \␊ |
| ␉␉␉$(CC) -c -mmcu=$(MCU) -DF_CPU=$(DF_CPU) $(INCLUDE) \␊ |
| ␉␉␉$(CC_FLAGS) $(ARDUINO_CORE)/$$core_c_file.c \␊ |
| ␉␉␉-o bin/$$core_c_file.o; \␊ |
| ␉␉done␊ |
| ␊ |
| ␉␉for core_cpp_file in ${CORE_CPP_FILES}; do \␊ |
| ␉␉␉$(CPP) -c -mmcu=$(MCU) -DF_CPU=$(DF_CPU) $(INCLUDE) \␊ |
| ␉␉␉$(CPP_FLAGS) $(ARDUINO_CORE)/$$core_cpp_file.cpp \␊ |
| ␉␉␉-o bin/$$core_cpp_file.o; \␊ |
| ␉␉done␊ |
| ␊ |
| ␉␉$(CC) -mmcu=$(MCU) -lm -Wl,--gc-sections -Os \␊ |
| ␉␉␉-o bin/project.elf bin/*.o␊ |
| ␉␉$(AVR_OBJCOPY) -O ihex -R .eeprom \␊ |
| ␉␉␉bin/project.elf \␊ |
| ␉␉␉bin/project.hex␊ |
| ␉␉@echo '# *** Compilation complete'␊ |
| ␊ |
| reset:␊ |
| ␉␉@echo '# *** Resetting...'␊ |
| ␉␉stty --file $(PORT) hupcl␊ |
| ␉␉sleep 0.1␊ |
| ␉␉stty --file $(PORT) -hupcl␊ |
| ␉␉␊ |
| upload:␊ |
| ␉␉@echo '# *** Uploading...'␊ |
| ␉␉$(AVRDUDE) -q -V -p $(MCU) -C $(AVRDUDE_CONF) -c $(BOARD_TYPE) \␊ |
| ␉␉␉-b $(BAUD_RATE) -P $(PORT) \␊ |
| ␉␉␉-U flash:w:bin/project.hex:i␊ |
| ␉␉@echo '# *** Upload complete'␊ |
| ␊ |