Subversion Repositories svn.mios32

Rev

Rev 845 | Rev 1056 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 tk 1
# $Id: common.mk 1010 2010-04-25 09:56:20Z tk $
2
#
3
# following variables should be set before including this file:
69 tk 4
#   - PROCESSOR e.g.: STM32F103RE
6 tk 5
#   - FAMILY    e.g.: STM32F10x
230 tk 6
#   - BOARD     e.g.: MBHP_CORE_STM32
7
#   - LCD       e.g.: clcd
6 tk 8
#   - LD_FILE   e.g.: $(MIOS32_PATH)/etc/ld/$(FAMILY)/$(PROCESSOR).ld
9
#   - PROJECT   e.g.: project   # (.lst, .hex, .map, etc... will be added automatically)
10
#   - THUMB_SOURCE e.g.: main.c (.c only)
845 tk 11
#   - THUMB_CPP_SOURCE e.g.: main.cp (.cpp only)
6 tk 12
#   - THUMB_AS_SOURCE e.g.: assembly.s (.s only)
13
#   - ARM_SOURCE e.g.: my_startup.c (.c only)
845 tk 14
#   - ARM_CPP_SOURCE e.g.: my_startup.cpp (.cpp only)
6 tk 15
#   - ARM_AS_SOURCE e.g.: assembly.s (.s only)
16
#   - C_INCLUDE     e.g.: -I./ui  # (more include pathes will be added by .mk files)
17
#   - A_INCLUDE     same for assembly code
18
#   - DIST      e.g.: ./
19
#
20
# Modules can be added by including .mk files from $MIOS32_PATH/modules/*/*.mk
21
#
22
 
23
# if MIOS32_SHELL environment variable hasn't been set by the user, set it here
24
# Ubuntu users should set it to /bin/bash from external (-> "export MIOS32_SHELL /bin/bash")
25
MIOS32_SHELL ?= sh
26
export MIOS32_SHELL
27
 
28
# select GCC tools
88 tk 29
# can be optionally overruled via environment variable
30
# e.g. for Cortex M3 support provided by CodeSourcery, use MIOS32_GCC_PREFIX=arm-none-eabi
764 tk 31
# The usage of arm-elf isn't recommented due to compatibility issues!!!
32
MIOS32_GCC_PREFIX ?= arm-none-eabi
6 tk 33
 
88 tk 34
CC      = $(MIOS32_GCC_PREFIX)-gcc
845 tk 35
CPP     = $(MIOS32_GCC_PREFIX)-g++
88 tk 36
OBJCOPY = $(MIOS32_GCC_PREFIX)-objcopy
37
OBJDUMP = $(MIOS32_GCC_PREFIX)-objdump
38
NM      = $(MIOS32_GCC_PREFIX)-nm
39
SIZE    = $(MIOS32_GCC_PREFIX)-size
6 tk 40
 
41
# default linker flags
845 tk 42
#LDFLAGS += -T $(LD_FILE) -mthumb -Xlinker -o$(PROJECT).elf -u _start -Wl,--gc-section  -Xlinker -M -Xlinker -Map=$(PROJECT).map -nostartfiles
43
LDFLAGS += -T $(LD_FILE) -mthumb -Xlinker -o$(PROJECT).elf -u _start -Wl,--gc-section  -Xlinker -M -Xlinker -Map=$(PROJECT).map -lstdc++
6 tk 44
 
45
# default assembler flags
46
AFLAGS += $(A_DEFINES) $(A_INCLUDE) -Wa,-adhlns=$(<:.s=.lst)
47
 
48
# define C flags
845 tk 49
CFLAGS += $(C_DEFINES) $(C_INCLUDE)
6 tk 50
 
845 tk 51
# define CPP flags (will be added to CFLAGS)
1010 tk 52
CPPFLAGS += -fno-rtti -fno-exceptions -Wno-write-strings
845 tk 53
 
6 tk 54
# add family specific arguments
55
ifeq ($(FAMILY),STM32F10x)
232 tk 56
CFLAGS += -mcpu=cortex-m3 -mlittle-endian -ffunction-sections
6 tk 57
endif
58
 
59
ifeq ($(FAMILY),STR9x)
60
CFLAGS += -mcpu=arm7tdmi -D PACK_STRUCT_END=__attribute\(\(packed\)\) -D ALIGN_STRUCT_END=__attribute\(\(aligned\(4\)\)\) -fomit-frame-pointer -ffunction-sections -mthumb-interwork
61
endif
62
 
63
 
64
# convert .c/.s -> .o
65
THUMB_OBJS = $(THUMB_SOURCE:.c=.o)
845 tk 66
THUMB_CPP_OBJS = $(THUMB_CPP_SOURCE:.cpp=.o)
6 tk 67
THUMB_AS_OBJS = $(THUMB_AS_SOURCE:.s=.o)
68
ARM_OBJS = $(ARM_SOURCE:.c=.o)
845 tk 69
ARM_CPP_OBJS = $(ARM_CPP_SOURCE:.cpp=.o)
6 tk 70
ARM_AS_OBJS = $(ARM_AS_SOURCE:.s=.o)
71
 
241 tk 72
# convert .s -> .lst
73
THUMB_AS_LST = $(THUMB_AS_SOURCE:.s=.lst)
74
ARM_AS_LST = $(ARM_AS_SOURCE:.s=.lst)
75
 
6 tk 76
# add files for distribution
77
DIST += $(MIOS32_PATH)/include/makefile/common.mk $(MIOS32_PATH)/include/c
78
DIST += $(LD_FILE)
79
 
80
# default rule
81
# note: currently we always require a "cleanall", since dependencies (e.g. on .h files) are not properly declared
82
# later we could try it w/o "cleanall", and propose the usage of this step to the user
69 tk 83
all: cleanall $(PROJECT).hex $(PROJECT).bin $(PROJECT).lss $(PROJECT).sym projectinfo
6 tk 84
 
103 tk 85
# define debug/release target for easier use in codeblocks
86
debug: all
87
Debug: all
88
release: all
89
Release: all
90
 
6 tk 91
# rule to create a .hex and .bin file
92
%.bin : $(PROJECT).elf
93
	$(OBJCOPY) $< -O binary $@
94
%.hex : $(PROJECT).elf
95
	$(OBJCOPY) $< -O ihex $@
96
 
97
# rule to create a listing file from .elf
98
%.lss: $(PROJECT).elf
99
	$(OBJDUMP) -h -S -C $< > $@
100
 
101
# rule to create a symbol table from .elf
102
%.sym: $(PROJECT).elf
103
	$(NM) -n $< > $@
104
 
105
# rule to create .elf file
845 tk 106
$(PROJECT).elf: $(THUMB_CPP_OBJS) $(THUMB_OBJS) $(THUMB_AS_OBJS) $(ARM_CPP_OBJS) $(ARM_OBJS) $(ARM_AS_OBJS)
107
	$(CC) $(CFLAGS) $(ARM_OBJS) $(THUMB_OBJS) $(ARM_AS_OBJS) $(THUMB_CPP_OBJS) $(ARM_CPP_OBJS) $(THUMB_AS_OBJS) $(LIBS) $(LDFLAGS)
6 tk 108
 
69 tk 109
# rule to output project informations
110
projectinfo:
111
	@echo "-------------------------------------------------------------------------------"
112
	@echo "Application successfully built for:"
113
	@echo "Processor: $(PROCESSOR)"
114
	@echo "Family:    $(FAMILY)"
115
	@echo "Board:     $(BOARD)"
116
	@echo "LCD:       $(LCD)"
117
	@echo "-------------------------------------------------------------------------------"
118
	$(SIZE) $(PROJECT).elf
119
 
6 tk 120
# default rule for compiling .c programs
121
$(THUMB_OBJS) : %.o : %.c
122
	$(CC) -c $(CFLAGS) -mthumb $< -o $@
123
 
124
$(ARM_OBJS) : %.o : %.c
125
	$(CC) -c $(CFLAGS) $< -o $@
126
 
845 tk 127
# default rule for compiling .cpp programs
128
$(THUMB_CPP_OBJS) : %.o : %.cpp
129
	$(CPP) -c $(CFLAGS) $(CPPFLAGS) -mthumb $< -o $@
130
 
131
$(ARM_CPP_OBJS) : %.o : %.cpp
132
	$(CPP) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
133
 
6 tk 134
# default rule for compiling assembly programs
135
$(THUMB_AS_OBJS) : %.o : %.s
136
	$(CC) -c $(AFLAGS) -mthumb $< -o $@
137
 
138
$(ARM_AS_OBJS) : %.o : %.s
139
	$(CC) -c $(AFLAGS) $< -o $@
140
 
141
# clean temporary files
142
clean:
792 tk 143
	rm -f *.lss $(PROJECT).sym $(PROJECT).map $(PROJECT).elf
845 tk 144
	rm -f $(THUMB_OBJS) $(THUMB_CPP_OBJS) $(THUMB_CS_OBJS) $(THUMB_AS_LST) $(ARM_OBJS) $(ARM_CPP_OBJS) $(ARM_AS_OBJS)  $(ARM_AS_LST)
6 tk 145
 
146
# clean temporary files + project image
147
cleanall: clean
792 tk 148
	rm -f $(PROJECT).hex $(PROJECT).bin
400 stryd_one 149
 
150
 
151
# for use with graphviz and egypt
152
callgraph: egyptall egypt_tidy egypt_all egypt_project
153
 
154
 
155
egyptall: CFLAGS += -dr
156
egyptall: all
157
 
158
egypt_tidy:
159
	@rm -fR egypt
160
	@echo "-------------------------------------------------------------------------------"
161
	@echo "Generating call graphs in .dot files"
162
	@echo "-------------------------------------------------------------------------------"
163
	@mkdir egypt
164
	@mv *.expand egypt/
165
 
166
egypt_all:
167
	@perl $(MIOS32_PATH)/etc/egypt/egypt egypt/*.expand > egypt/$(PROJECT).dot
168
 
169
 
170
egypt_project: EGYPTFILES = find egypt/*.expand -maxdepth 1 ! -name "mios32_*.expand" ! -name "stm32f10x*.expand" ! -name "usb_*.expand" ! -name "printf-stdarg.c*.expand" ! -name "crt0_STM32x.c*.expand" ! -name "app_lcd.c*.expand" ! -name "heap_*.expand" ! -name "list.c*.expand" ! -name "port.c*.expand" ! -name "queue.c*.expand" ! -name "main.c*.expand"
171
egypt_project:
172
	@perl $(MIOS32_PATH)/etc/egypt/egypt `$(EGYPTFILES)` > egypt/$(PROJECT)_NoMIOS.dot
173
 
174
 
175
callgraph_convert:
176
	@$(MIOS32_SHELL) $(MIOS32_PATH)/etc/egypt/dot_output.sh
177
 
178
callgraph_all: callgraph callgraph_convert
179
 
180
callgraph_clean:
181
	@rm -fR egypt
182
 
183
# shortcut for impatient coders. If you don't know what this is don't use it!
184
notall: $(PROJECT).hex $(PROJECT).bin $(PROJECT).lss $(PROJECT).sym projectinfo