The makefile:
CHIP = at91sam9260
BOARD = at91sam9260-ek
Trace level used for compilation
(can be overriden by adding TRACE_LEVEL=#number to the command-line)
TRACE_LEVEL = 4
Optimization level, put in comment for debugging
OPTIMIZATION = -Os
AT91 library directory
AT91LIB = ../at91lib
Output file basename
OUTPUT = basic-ssc-i2s-at73c213-project-$(BOARD)-$(CHIP)
Compile for all memories available on the board (this sets $(MEMORIES))
include $(AT91LIB)/boards/$(BOARD)/board.mak
Output directories
BIN = bin
OBJ = obj
-------------------------------------------------------------------------------
Tools
-------------------------------------------------------------------------------
Tool suffix when cross-compiling
CROSS_COMPILE = arm-none-eabi-
Compilation tools
CC = $(CROSS_COMPILE)gcc
SIZE = $(CROSS_COMPILE)size
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
Flags
INCLUDES = -I$(AT91LIB)/boards/$(BOARD) -I$(AT91LIB)/peripherals
INCLUDES += -I$(AT91LIB)/components -I$(AT91LIB) -I.
CFLAGS = -Wall -mlong-calls -mstructure-size-boundary=8 -ffunction-sections
CFLAGS += -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL)
ASFLAGS = -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D_ASSEMBLY_
LDFLAGS = -g $(OPTIMIZATION) -nostartfiles -Wl,--gc-sections
-------------------------------------------------------------------------------
Files
-------------------------------------------------------------------------------
Directories where source files can be found
PERIPH = $(AT91LIB)/peripherals
BOARDS = $(AT91LIB)/boards
UTILITY = $(AT91LIB)/utility
COMP = $(AT91LIB)/components
uIP library directory
UIPLIB = ../external_libs/ethernet/uip
VPATH += $(COMP)/dac-at73c213
VPATH += $(COMP)/ethernet/dm9161
VPATH += $(UTILITY)
VPATH += $(PERIPH)/dbgu $(PERIPH)/pio $(PERIPH)/aic $(PERIPH)/ssc $(PERIPH)/spi $(PERIPH)/pmc
VPATH += $(PERIPH)/cp15 $(PERIPH)/emac $(PERIPH)/rstc $(PERIPH)/usart $(PERIPH)/tc
VPATH += $(BOARDS)/$(BOARD) $(BOARDS)/$(BOARD)/$(CHIP)
VPATH += $(UIPLIB)/uip
VPATH += $(UIPLIB)/lib
VPATH += $(UIPLIB)/apps/dhcpc
VPATH += $(UIPLIB)/apps/telnetd
INCLUDES += -I$(UTILITY)
INCLUDES += -I$(UIPLIB)/uip
INCLUDES += -I$(UIPLIB)/lib
INCLUDES += -I$(UIPLIB)/apps/dhcpc
INCLUDES += -I$(UIPLIB)/apps/telnetd
Objects built from C source files
C_OBJECTS = main.o
C_OBJECTS += at73c213.o dm9161.o protocol.o
C_OBJECTS += wav.o stdio.o math.o emac.o rstc.o tc.o usart.o
C_OBJECTS += dbgu.o pio.o ssc.o aic.o spi.o pmc.o cp15.o
C_OBJECTS += board_memories.o board_lowlevel.o
UIP:
lib
C_OBJECTS += memb.o
uip
C_OBJECTS += psock.o timer.o uip.o uip_arp.o
main
C_OBJECTS += clock-arch.o tapdev.o
dhcp
C_OBJECTS += dhcpc.o
telnetd
C_OBJECTS += shell.o telnetd.o
Objects built from Assembly source files
ASM_OBJECTS = board_cstartup.o
ASM_OBJECTS += cp15_asm.o
Append OBJ and BIN directories to output filename
OUTPUT := $(BIN)/$(OUTPUT)
-------------------------------------------------------------------------------
Rules
-------------------------------------------------------------------------------
all: $(BIN) $(OBJ) $(MEMORIES)
$(BIN) $(OBJ):
mkdir $@
define RULES
C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS))
ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS))
$(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1))
$(CC) $(LDFLAGS) -T"$(AT91LIB)/boards/$(BOARD)/$(CHIP)/[email protected]" -o $(OUTPUT)[email protected] $$^
$(OBJCOPY) -O binary $(OUTPUT)[email protected] $(OUTPUT)[email protected]
$(SIZE) $$^ $(OUTPUT)[email protected]
$$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN)
$(CC) $(CFLAGS) -D$(1) -c -o $$@ $$<
$$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN)
$(CC) $(ASFLAGS) -D$(1) -c -o $$@ $$<
debug_$(1): $(1)
perl ../resources/gdb/debug.pl $(OUTPUT)-$(1).elf
endef
$(foreach MEMORY, $(MEMORIES), $(eval $(call RULES,$(MEMORY))))
clean:
-rm -f $(OBJ)/.o $(BIN)/.bin $(BIN)/*.elf