1 | ############################################################################### |
---|
2 | # Makefile for the project avr-m200-card-reader-controller |
---|
3 | ############################################################################### |
---|
4 | |
---|
5 | ## General Flags |
---|
6 | PROJECT = avr-m200-card-reader-controller |
---|
7 | MCU = atmega644 |
---|
8 | TARGET = avr-m200-card-reader-controller.elf |
---|
9 | CC = avr-gcc |
---|
10 | |
---|
11 | CPP = avr-g++ |
---|
12 | |
---|
13 | ## Options common to compile, link and assembly rules |
---|
14 | COMMON = -mmcu=$(MCU) |
---|
15 | |
---|
16 | ## Compile options common for all C compilation units. |
---|
17 | CFLAGS = $(COMMON) |
---|
18 | CFLAGS += -Wall -gdwarf-2 -std=gnu99 -DF_CPU=8000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums |
---|
19 | CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d |
---|
20 | |
---|
21 | ## Assembly specific flags |
---|
22 | ASMFLAGS = $(COMMON) |
---|
23 | ASMFLAGS += $(CFLAGS) |
---|
24 | ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2 |
---|
25 | |
---|
26 | ## Linker flags |
---|
27 | LDFLAGS = $(COMMON) |
---|
28 | LDFLAGS += -Wl,-Map=avr-m200-card-reader-controller.map |
---|
29 | |
---|
30 | |
---|
31 | ## Intel Hex file production flags |
---|
32 | HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature |
---|
33 | |
---|
34 | HEX_EEPROM_FLAGS = -j .eeprom |
---|
35 | HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load" |
---|
36 | HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings |
---|
37 | |
---|
38 | |
---|
39 | ## Objects that must be built in order to link |
---|
40 | OBJECTS = main.o punchcard.o |
---|
41 | |
---|
42 | ## Objects explicitly added by the user |
---|
43 | LINKONLYOBJECTS = |
---|
44 | |
---|
45 | ## Build |
---|
46 | all: $(TARGET) avr-m200-card-reader-controller.hex avr-m200-card-reader-controller.eep avr-m200-card-reader-controller.lss size |
---|
47 | |
---|
48 | ## Compile |
---|
49 | main.o: ../src/main.c |
---|
50 | $(CC) $(INCLUDES) $(CFLAGS) -c $< |
---|
51 | |
---|
52 | punchcard.o: ../src/punchcard.c |
---|
53 | $(CC) $(INCLUDES) $(CFLAGS) -c $< |
---|
54 | |
---|
55 | ##Link |
---|
56 | $(TARGET): $(OBJECTS) |
---|
57 | $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET) |
---|
58 | |
---|
59 | %.hex: $(TARGET) |
---|
60 | avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@ |
---|
61 | |
---|
62 | %.eep: $(TARGET) |
---|
63 | -avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0 |
---|
64 | |
---|
65 | %.lss: $(TARGET) |
---|
66 | avr-objdump -h -S $< > $@ |
---|
67 | |
---|
68 | size: ${TARGET} |
---|
69 | @echo |
---|
70 | @avr-size -C --mcu=${MCU} ${TARGET} |
---|
71 | |
---|
72 | ## Clean target |
---|
73 | .PHONY: clean |
---|
74 | clean: |
---|
75 | -rm -rf $(OBJECTS) avr-m200-card-reader-controller.elf dep/* avr-m200-card-reader-controller.hex avr-m200-card-reader-controller.eep avr-m200-card-reader-controller.lss avr-m200-card-reader-controller.map |
---|
76 | |
---|
77 | |
---|
78 | ## Other dependencies |
---|
79 | -include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*) |
---|
80 | |
---|