TITLE: Makefile for building retargeted hello world
AUTHOR: Chuck McManis
LAST UPDATE: 25-Jun-2014

Description

This is the makefile used in the retarget article. It is a mix of the makefile from the gcc distribution and adding in pointers to libopencm3

The Source Code

# Use newlib-nano. 
USE_NANO=--specs=nano.specs
USE_NOHOST=--specs=nosys.specs

# SET THIS to where you installed the gcc embedded distribution
BASE=/home/cmcmanis/gcc-arm-none-eabi-4_8-2014q1/share/gcc-arm-none-eabi/samples

# Compiler & Linker
CC=arm-none-eabi-gcc
CXX=arm-none-eabi-g++

# Options for specific architecture
ARCH_FLAGS=-mthumb -mcpu=cortex-m4

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

# -Os -flto -ffunction-sections -fdata-sections to compile for code size
CFLAGS=$(ARCH_FLAGS) $(STARTUP_DEFS) -Os -flto -ffunction-sections -fdata-sections
CXXFLAGS=$(CFLAGS)

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

# Create map file
MAP=-Wl,-Map=$(NAME).map
NAME=retarget

STARTUP_DEFS=-D__STARTUP_CLEAR_BSS -D__START=main

# Need following option for LTO as LTO will treat retarget functions as
# unused without following option
CFLAGS+=-fno-builtin
CFLAGS+= -I../../libopencm3/include -DSTM32F4
CFLAGS+= -mfloat-abi=hard -mfpu=fpv4-sp-d16
CFLAGS+= -g

LDSCRIPTS=-L. -L$(BASE)/ldscripts -T gcc.ld -L../../libopencm3/lib -lopencm3_stm32f4

LFLAGS=$(USE_NANO) $(USE_NOHOST) $(LDSCRIPTS) $(GC) $(MAP)

$(NAME).axf: main.c $(NAME).c $(STARTUP)
    $(CC) $^ $(CFLAGS) $(LFLAGS) -o $@

clean:
    rm -f *.axf *.map *.o

License

Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License. You are free to play around with it and modify it but you are not licensed to use it for commercial purposes. Click the link above for more details on your rights under this license.