Makefile 2.01 KB
Newer Older
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

#Build directory
BUILD = build

#project name
#doesn't need to be associated with any file names
PROJ = baremetal


# Selecting Core
CORTEX_M=0

# Use newlib-nano. To disable it, specify USE_NANO=
#USE_NANO=--specs=nano.specs
USE_NANO=

# Use seimhosting or not
USE_SEMIHOST=--specs=rdimon.specs
USE_NOHOST=--specs=nosys.specs

CORE=CM$(CORTEX_M)
BASE=.

# Compiler & Linker
CC=arm-none-eabi-gcc
CXX=arm-none-eabi-g++
OBJCOPY=arm-none-eabi-objcopy
SIZE=arm-none-eabi-size

# Options for specific architecture
ARCH_FLAGS=-mthumb -mcpu=cortex-m$(CORTEX_M)

# Startup code
STARTUP=$(BASE)/startup/startup_ARM$(CORE).S

# -Os -flto -ffunction-sections -fdata-sections to compile for code size
37
CFLAGS=$(ARCH_FLAGS) $(STARTUP_DEFS) -Os -flto -ffunction-sections -fdata-sections -g
38 39 40 41 42 43 44 45
CXXFLAGS=$(CFLAGS)

# Link for code size
GC=-Wl,--gc-sections

# Create map file
MAP=-Wl,-Map=$(BUILD)/$(PROJ).map

46
STARTUP_DEFS=-D__STARTUP_CLEAR_BSS -D__START=main -D__NO_SYSTEM_INIT
47 48 49 50

LDSCRIPTS=-L. -L$(BASE)/ldscripts -T nokeep.ld
LFLAGS=$(USE_NANO) $(USE_NOHOST) $(LDSCRIPTS) $(GC) $(MAP)

51 52 53 54 55 56
DEFINE+=\
	-DSTM32F072xB \
	-DF_CPU=8000000
INCLUDE=-I ./include
CFLAGS+= $(DEFINE) $(INCLUDE) 

57 58 59
SOURCES=$(wildcard source/**/*.c source/*.c)
OBJECTS=$(patsubst %.c,%.o,$(SOURCES))

60 61
#all: dir $(BUILD)/$(PROJ).axf $(BUILD)/$(PROJ).elf $(BUILD)/$(PROJ).hex $(BUILD)/$(PROJ).bin size 
all: dir $(BUILD)/$(PROJ).elf $(BUILD)/$(PROJ).hex $(BUILD)/$(PROJ).bin size 
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

#build axf file output (basically elf with DWARF debug info)
# $@ is shortcut for the target, $^ is shortcut for prereqs
#             TARGET: PREREQS
$(BUILD)/$(PROJ).axf: $(STARTUP) $(OBJECTS)
	$(CC) $^ $(CFLAGS) $(LFLAGS) -o $@

$(BUILD)/$(PROJ).elf: $(STARTUP) $(OBJECTS)
	$(CC) $^ $(CFLAGS) $(LFLAGS) -o $@

$(BUILD)/$(PROJ).hex: $(BUILD)/$(PROJ).elf
	$(OBJCOPY) -O ihex $^ $@

$(BUILD)/$(PROJ).bin: $(BUILD)/$(PROJ).elf
	$(OBJCOPY) -O binary $^ $@

dir:
	mkdir -p $(BUILD)

size:	$(BUILD)/$(PROJ).elf
	$(SIZE) -t $^

84 85 86
disassm:
	arm-none-eabi-objdump build\baremetal.elf -d -g 

87 88 89
clean: 
	rm -rf $(BUILD)
	rm -f $(OBJECTS)