-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile.avr
119 lines (100 loc) · 4.63 KB
/
makefile.avr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# System configuration - UNCOMMENT AS DESIRED
TCHAIN=
CC = $(TCHAIN)avr-gcc
CCP = $(TCHAIN)avr-g++
OPT = -O2
OBJCOPY = $(TCHAIN)avr-objcopy
AR = $(TCHAIN)avr-ar
RM = rm -rf
SIZE = $(TCHAIN)avr-size
OBJDUMP = $(TCHAIN)avr-objdump
NM = $(TCHAIN)avr-nm
AVRDUDE ?= c:/bin/avrdude
COMPORT ?= com5
BOARD ?= _BS_NFET_
# Add .d to Make's recognized suffixes.
SUFFIXES += .d
#We don't need to clean up when we're making these targets
NODEPS:=clean tags svn
lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
# Define output directory
OBJECT_DIR = obj/avr
BIN_DIR = bin/avr
OUT_FILE = wii_esc_ng
MCU?=atmega8
F_CPU?=16000000L
# Assembler, Compiler and Linker flags and linker script settings
LINKER_FLAGS=-mmcu=$(MCU) $(OPT) -Wl,--relax,--gc-sections "-Wl,-Map=$(BIN_DIR)/$(OUT_FILE).map"
ASSEMBLER_FLAGS=-c $(OPT) -mmcu=$(MCU) -x assembler-with-cpp -Isrc -Ilib-avr/arduino
COMPILER_FLAGS=-c -g -mmcu=$(MCU) $(OPT) -ffunction-sections -fdata-sections -fno-exceptions \
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
-fno-split-wide-types \
-mcall-prologues \
-DF_CPU=$(F_CPU) -DARDUINO=22 -DBOARD=$(BOARD) -DUSB_VID=0x2341 -DUSB_PID=0x8036 -Isrc -Ilib-avr/arduino -Ilib/MWC_PT -Ilib-avr -Ilib-avr/nvram
# Define sources and objects
LSRC := $(wildcard lib-avr/*/*/*/*/*/*/*.c) \
$(wildcard lib-avr/*/*/*/*/*/*.c) \
$(wildcard lib-avr/*/*/*/*/*.c) \
$(wildcard lib-avr/*/*/*/*.c) \
$(wildcard lib-avr/*/*/*.c) \
$(wildcard lib-avr/*/*.c) \
$(wildcard lib-avr/*.c) \
LSRCP:= $(wildcard lib-avr/*/*/*/*/*/*/*.cpp) \
$(wildcard lib-avr/*/*/*/*/*/*.cpp) \
$(wildcard lib-avr/*/*/*/*/*.cpp) \
$(wildcard lib-avr/*/*/*/*.cpp) \
$(wildcard lib-avr/*/*/*.cpp) \
$(wildcard lib-avr/*/*.cpp) \
$(wildcard lib-arm/*.cpp) \
LOBJS := $(LSRC:%.c=$(OBJECT_DIR)/%.o) $(LSRCP:%.cpp=$(OBJECT_DIR)/%.o) $(LSRCSASM:%.s=$(OBJECT_DIR)/%.o)
LOBJS := $(LOBJS:%.S=$(OBJECT_DIR)/%.o)
LDEPS :=$(patsubst %.o,%.d,$(LOBJS))
SRC := $(wildcard src/*.c)
SRCP:= $(wildcard src/*.cpp)
OBJS := $(SRC:%.c=$(OBJECT_DIR)/%.o) $(SRCP:%.cpp=$(OBJECT_DIR)/%.o) $(SRCSASM:%.s=$(OBJECT_DIR)/%.o)
OBJS := $(OBJS:%.S=$(OBJECT_DIR)/%.o)
DEPS := $(patsubst %.o,%.d,$(OBJS))
all: $(BIN_DIR)/$(OUT_FILE).elf
@mkdir -p $(dir $@) "$(BIN_DIR)/conf"
@$(OBJCOPY) -O ihex -R .eeprom "$(BIN_DIR)/$(OUT_FILE).elf" "$(BIN_DIR)/$(OUT_FILE).hex"
@$(OBJCOPY) -j default_eep --change-section-lma default_eep=0 -O ihex "$(OBJECT_DIR)/src/wii_esc_ng.o" "$(BIN_DIR)/conf/default.eep"
@$(OBJCOPY) -j extended_eep --change-section-lma extended_eep=0 -O ihex "$(OBJECT_DIR)/src/wii_esc_ng.o" "$(BIN_DIR)/conf/extended.eep"
@$(OBJCOPY) -j free_flight_eep --change-section-lma free_flight_eep=0 -O ihex "$(OBJECT_DIR)/src/wii_esc_ng.o" "$(BIN_DIR)/conf/free_flight.eep"
@$(OBJCOPY) -j ultra_pwm_eep --change-section-lma ultra_pwm_eep=0 -O ihex "$(OBJECT_DIR)/src/wii_esc_ng.o" "$(BIN_DIR)/conf/ultra_pwm.eep"
@$(OBJCOPY) -j multiwii_eep --change-section-lma multiwii_eep=0 -O ihex "$(OBJECT_DIR)/src/wii_esc_ng.o" "$(BIN_DIR)/conf/multiwii.eep"
@$(OBJDUMP) -d -C "$(BIN_DIR)/$(OUT_FILE).elf" > "$(BIN_DIR)/$(OUT_FILE).asm"
@$(NM) -C -n -S -l "$(BIN_DIR)/$(OUT_FILE).elf" > "$(BIN_DIR)/$(OUT_FILE).mem"
@$(SIZE) --mcu=$(MCU) -C "$(BIN_DIR)/$(OUT_FILE).elf"
@cp "$(BIN_DIR)/$(OUT_FILE).hex" "$(BIN_DIR)/$(call lc,$(patsubst _%_,%,$(BOARD))).hex"
upload: all
$(AVRDUDE) -q -q -p atmega328p -c arduino -P $(COMPORT) -b 57600 -D -Uflash:w:$(BIN_DIR)/$(OUT_FILE).hex:i
#Don't create dependencies when we're cleaning, for instance
ifeq (0, $(words $(findstring $(MAKECMDGOALS), $(NODEPS))))
#Chances are, these files don't exist. GMake will create them and
#clean up automatically afterwards
-include $(DEPS)
-include $(LDEPS)
endif
$(BIN_DIR)/$(OUT_FILE).elf: $(OBJECT_DIR)/core.a $(OBJS)
@mkdir -p $(dir $@)
$(CC) -o "$(BIN_DIR)/$(OUT_FILE).elf" $(LINKER_FLAGS) $(OBJS) $(OBJECT_DIR)/core.a -lm
$(OBJECT_DIR)/core.a: $(LOBJS)
$(AR) -rcs $@ $^
clean:
$(RM) $(LOBJS)
$(RM) $(LDEPS)
$(RM) $(OBJS)
$(RM) $(DEPS)
$(RM) $(BIN_DIR)/*
$(OBJECT_DIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) -MD $(COMPILER_FLAGS) $< -o $@
$(OBJECT_DIR)/%.o: %.cpp
@mkdir -p $(dir $@)
$(CCP) -MD $(COMPILER_FLAGS) $< -o $@
$(OBJECT_DIR)/%.o: %.s
@mkdir -p $(dir $@)
$(CC) -MD $(ASSEMBLER_FLAGS) $< -o $@
$(OBJECT_DIR)/%.o: %.S
@mkdir -p $(dir $@)
$(CC) -MD $(ASSEMBLER_FLAGS) $< -o $@