-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
169 lines (120 loc) · 4.37 KB
/
Makefile
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#=======================================================================
# @file
# @brief R8C Makefile
# @author 平松邦仁 ([email protected])
# @copyright Copyright (C) 2017, 2021 Kunihito Hiramatsu @n
# Released under the MIT license @n
# https://github.com/hirakuni45/R8C/blob/master/LICENSE
#=======================================================================
TARGET = ad9833_sample
BUILD = release
VPATH = ../
ASOURCES = common/start.s
CSOURCES = common/vect.c \
common/init.c \
common/syscalls.c
PSOURCES = main.cpp
USER_LIBS = supc++ m
LDSCRIPT = ../M120AN/m120an.ld
USER_DEFS = F_CLK=20000000
MCU_TARGET = -mcpu=r8c
INC_SYS =
INC_APP = . ../
OPTIMIZE = -Os
CP_OPT = -Wall -Werror \
-Wno-unused-variable \
-fno-exceptions
CC_OPT = -Wall -Werror \
-Wno-unused-variable \
-fno-exceptions
SYSINCS = $(addprefix -I, $(INC_SYS))
APPINCS = $(addprefix -I, $(INC_APP))
AINCS = $(SYSINCS) $(APPINCS)
CINCS = $(SYSINCS) $(APPINCS)
PINCS = $(SYSINCS) $(APPINCS)
LIBINCS = $(addprefix -L, $(LIB_ROOT))
DEFS = $(addprefix -D, $(USER_DEFS))
LIBS = $(addprefix -l, $(USER_LIBS))
# You should not have to change anything below here.
AS = m32c-elf-as
CC = m32c-elf-gcc
CP = m32c-elf-g++
AR = m32c-elf-ar
LD = m32c-elf-ld
OBJCOPY = m32c-elf-objcopy
OBJDUMP = m32c-elf-objdump
SIZE = m32c-elf-size
# AFLAGS = -Wa,-adhlns=$(<:.s=.lst),-gstabs
# AFLAGS = -Wa,-adhlns=$(<:.s=.lst)
# ALL_ASFLAGS = -x assembler-with-cpp $(ASFLAGS) $(DEFS)
ALL_ASFLAGS = $(AFLAGS) $(MCU_TARGET) $(DEFS)
# Override is only needed by avr-lib build system.
CFLAGS = -std=gnu99 $(CC_OPT) $(OPTIMIZE) $(MCU_TARGET) $(DEFS)
PFLAGS = -std=c++14 $(CP_OPT) $(OPTIMIZE) $(MCU_TARGET) $(DEFS)
# override LDFLAGS = $(MCU_TARGET) -nostartfiles -Wl,-Map,$(TARGET).map,-fdata-sections,-ffunction-sections,-falign-jumps,-fno-function-cse,-funit-at-a-time --select-lib=newlib -T $(LDSCRIPT)
# override LDFLAGS = $(MCU_TARGET) -nostartfiles -Wl,-Map,$(TARGET).map,--cref,--gc-sections -T $(LDSCRIPT)
override LDFLAGS = $(MCU_TARGET) -nostartfiles -Wl,-Map,$(TARGET).map -T $(LDSCRIPT)
OBJCOPY_OPT = --srec-forceS3 --srec-len 32
OBJECTS = $(addprefix $(BUILD)/,$(patsubst %.s,%.o,$(ASOURCES))) \
$(addprefix $(BUILD)/,$(patsubst %.c,%.o,$(CSOURCES))) \
$(addprefix $(BUILD)/,$(patsubst %.cpp,%.o,$(PSOURCES)))
DOBJECTS = $(addprefix $(BUILD)/,$(patsubst %.c,%.o,$(CSOURCES))) \
$(addprefix $(BUILD)/,$(patsubst %.cpp,%.o,$(PSOURCES)))
DEPENDS = $(patsubst %.o,%.d, $(DOBJECTS))
.PHONY: all clean
.SUFFIXES :
.SUFFIXES : .rc .hpp .s .h .c .cpp .d .o
all: $(BUILD) $(TARGET).elf text
$(TARGET).elf: $(OBJECTS) $(LDSCRIPT) Makefile
$(CC) $(LDFLAGS) $(LIBINCS) -o $@ $(OBJECTS) $(LIBS)
$(SIZE) $@
$(BUILD)/%.o: %.s
mkdir -p $(dir $@); \
$(AS) -c $(AOPT) $(AFLAGS) $(AINCS) -o $@ $<
$(BUILD)/%.o : %.c
mkdir -p $(dir $@); \
$(CC) -c $(COPT) $(CFLAGS) $(CINCS) $(CCWARN) -o $@ $<
$(BUILD)/%.o : %.cpp
mkdir -p $(dir $@); \
$(CP) -c $(POPT) $(PFLAGS) $(PINCS) $(CPWARN) -o $@ $<
$(BUILD)/%.d: %.c
mkdir -p $(dir $@); \
$(CC) -MM -DDEPEND_ESCAPE $(COPT) $(CFLAGS) $(APPINCS) $< \
| sed 's/$(notdir $*)\.o:/$(subst /,\/,$(patsubst %.d,%.o,$@) $@):/' > $@ ; \
[ -s $@ ] || rm -f $@
$(BUILD)/%.d: %.cpp
mkdir -p $(dir $@); \
$(CP) -MM -DDEPEND_ESCAPE $(POPT) $(PFLAGS) $(APPINCS) $< \
| sed 's/$(notdir $*)\.o:/$(subst /,\/,$(patsubst %.d,%.o,$@) $@):/' > $@ ; \
[ -s $@ ] || rm -f $@
clean:
rm -rf $(BUILD) $(TARGET).elf $(TARGET).mot $(TARGET).lst $(TARGET).map
clean_depend:
rm -f $(DEPENDS)
lst: $(TARGET).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
# Rules for building the .text rom images
text: mot lst
bin: $(TARGET).bin
mot: $(TARGET).mot
lst: $(TARGET).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
%.mot: %.elf
$(OBJCOPY) $(OBJCOPY_OPT) -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -O binary $< $@
# $(OBJCOPY) -j .vects -j .text -j .data -O binary $< $@
tarball:
tar cfvz $(subst .exe,,$(TARGET))_$(shell date +%Y%m%d%H).tgz \
*.[hc]pp Makefile ../common/*/*.[hc]pp ../common/*/*.[hc]
bin_zip:
$(LK) $(LFLAGS) $(LIBS) $(OBJECTS) $(ICON_OBJ) $(LIBN) -mwindows -o $(TARGET)
rm -f $(subst .exe,,$(TARGET))_$(shell date +%Y%m%d%H)_bin.zip
zip $(subst .exe,,$(TARGET))_$(shell date +%Y%m%d%H)_bin.zip *.exe *.dll res/*.*
run:
r8c_prog -d R5F2M120 --progress -e -w -v $(TARGET).mot
verify:
r8c_prog -d R5F2M120 --progress -v $(TARGET).mot
-include $(DEPENDS)