Makefile 1.86 KB
export CC = avr-gcc

export MCU = atmega328p
export TARGET_ARCH = -mmcu=$(MCU)

export CFLAGS =  -Wall -I. -DF_CPU=16000000 -Os #-pedantic -std=c99#-g
export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections #	-Os

TARGET = libretour
TERM0 = /dev/ttyACM0
TERM1 = /dev/ttyACM1
CPPFLAGS = -mmcu=$(MCU)
#PGMER = -c stk500v1 -b 57600 -P $(TERM)
PGMERISP0 = -c stk500v1 -b 115200 -P $(TERM0)
PGMERISP1 = -c stk500v1 -b 115200 -P $(TERM1)
ARVDUDECONF= -C /usr/local/arduino/arduino-0021/hardware/tools/avrdude.conf
export DUDE = /usr/bin/avrdude -F -v -p $(MCU) $(AVRDUDECONF)
CLIB=ar cq

C_SRC = $(wildcard *.c)
OBJS = $(C_SRC:.c=.o)

all: $(TARGET).a


clean:
	rm -f *.o *.hex *.elf *.a

$(TARGET).o: $(TARGET).c $(TARGET).h
	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@


$(TARGET).elf: $(OBJS)
	$(CC) $(LDFLAGS) -o $@ $(OBJS)

$(TARGET).hex: $(TARGET).elf
	avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex
	avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex

$(TARGET).a: $(TARGET).o
	rm -rf $@
	$(CLIB) $@ $+


#UPLOAD CONDITIONNEL
FOLDER = $(notdir $(CURDIR))

upload: $(TARGET).hex
#CAPTEUR 1
ifeq ($(FOLDER), capteur1-0)

	stty -F $(TERM0) hupcl # reset
	#	$(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
	$(DUDE) $(PGMERISP0) -U flash:w:$(TARGET).hex
endif

ifeq ($(FOLDER), capteur1-1)

	stty -F $(TERM0) hupcl # reset
	#	$(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
	$(DUDE) $(PGMERISP0) -U flash:w:$(TARGET).hex
endif

#CAPTEUR 2
ifeq ($(FOLDER), capteur2-0)

	stty -F $(TERM1) hupcl # reset
	#	$(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
	$(DUDE) $(PGMERISP1) -U flash:w:$(TARGET).hex
endif

ifeq ($(FOLDER), capteur2-1)

	stty -F $(TERM1) hupcl # reset
	#	$(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
	$(DUDE) $(PGMERISP1) -U flash:w:$(TARGET).hex
endif

size: $(TARGET).elf
	avr-size --format=avr --mcu=$(MCU) $(TARGET).elf