seperate avr gcc and g++ compilers

This commit is contained in:
sessionm21 2020-04-19 09:47:49 +01:00
parent f6156743cf
commit e2ae008ab4

View File

@ -1,5 +1,5 @@
ARDUINO_DIR?="external/ArduinoCore-avr"
NANOPB_DIR?="external/nanopb"
ARDUINO_DIR?=external/ArduinoCore-avr
NANOPB_DIR?=external/nanopb
CC=avr-gcc
CXX=avr-g++
@ -10,6 +10,22 @@ OUT=./bin/
NAME=collar
CFLAGS?=-Datmega328p\
-Dmega328p\
-mmcu=atmega328p\
-Wl,--gc-sections\
-DF_CPU=16000000L\
-DARDUINO=200\
-DARDUINO_AVR_NANO\
-DARDUINO_ARCH_AVR\
-Os\
-ffunction-sections\
-fdata-sections\
-MMD\
-flto\
-fno-fat-lto-objects\
-fuse-linker-plugin
CXXFLAGS?=-Datmega328p\
-Dmega328p\
-mmcu=atmega328p\
-Wl,--gc-sections\
@ -43,6 +59,10 @@ SRC_FILES?=./$(ARDUINO_DIR)/cores/arduino/main.cpp\
./$(ARDUINO_DIR)/cores/arduino/WInterrupts.c\
./$(ARDUINO_DIR)/cores/arduino/hooks.c\
./$(ARDUINO_DIR)/cores/arduino/wiring.c\
./$(NANOPB_DIR)/pb_encode.c\
./$(NANOPB_DIR)/pb_decode.c\
./$(NANOPB_DIR)/pb_common.c\
./protobuf/gateway/message.pb.c\
./$(ARDUINO_DIR)/cores/arduino/HardwareSerial.cpp\
./$(ARDUINO_DIR)/cores/arduino/HardwareSerial0.cpp\
./$(ARDUINO_DIR)/cores/arduino/HardwareSerial1.cpp\
@ -58,11 +78,7 @@ SRC_FILES?=./$(ARDUINO_DIR)/cores/arduino/main.cpp\
./libraries/arduino-LoRa/src/LoRa.cpp\
./libraries/TinyGPSPlus/src/TinyGPS++.cpp\
./libraries/TinyLoRa/TinyLoRa.cpp\
./libraries/arduino-base64/Base64.cpp\
./$(NANOPB_DIR)/pb_encode.c\
./$(NANOPB_DIR)/pb_decode.c\
./$(NANOPB_DIR)/pb_common.c\
./protobuf/gateway/message.pb.c
./libraries/arduino-base64/Base64.cpp
SRC_FILES_COMMON?=\
./$(NANOPB_DIR)/pb_encode.c\
@ -70,14 +86,25 @@ SRC_FILES_COMMON?=\
./$(NANOPB_DIR)/pb_common.c\
./protobuf/gateway/message.pb.c
# Make targets for each source file
OBJS := $(SRC_FILES:%=./bin/%.o)
OBJDIRS := $(SRC_FILES:%=./bin/%)
build: $(OUT)$(NAME)
$(OBJDIRS):
mkdir -p $(shell dirname $@)
$(OUT)%.cpp.o: %.cpp
$(CXX) $(CXXFLAGS) -c $(INC_DIRS) -o $@ $<
$(OUT)%.c.o: %.c
$(CC) $(CFLAGS) -c $(INC_DIRS) -o $@ $<
$(OUT)$(NAME): $(OUT)$(NAME).elf
$(OBJCOPY) -R .eeprom -O ihex $(OUT)$(NAME).elf $(OUT)$(NAME).hex
$(OUT)eep.hex: $(OUT)$(NAME).elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $(OUT)$(NAME).elf $(OUT)eep.hex
$(OUT)$(NAME).elf: protobufg bin
$(CC) $(CFLAGS) -o $(OUT)$(NAME).elf collar.cpp $(INC_DIRS) $(SRC_FILES)
$(OUT)$(NAME).elf: protobufg bin $(OBJDIRS) $(OBJS)
$(CC) $(CFLAGS) -o $(OUT)$(NAME).elf collar.cpp $(INC_DIRS) $(OBJS)
test:
g++ -o $(OUT)test prototest.cpp $(INC_DIRS) $(SRC_FILES_COMMON)