2010-09-20 22:28:22 +02:00
|
|
|
# Hey Emacs, this is a -*- makefile -*-
|
2010-02-26 13:30:53 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
# Set up a default target in case the user didn't already have one.
|
|
|
|
# "all" means to build .bin for all defined targets for the currently-defined board
|
2010-09-25 00:27:14 +02:00
|
|
|
all: $(addsuffix _$(BOARD).bin, $(TARGETS) $(TARGETS_WITH_ROM_VARS))
|
2010-09-20 22:28:22 +02:00
|
|
|
.PHONY: all
|
2010-02-21 23:34:27 +01:00
|
|
|
|
2010-09-25 00:21:29 +02:00
|
|
|
# Pretty print output. Use "make Q=" to see full commands
|
|
|
|
Q ?= @
|
|
|
|
define pretty
|
|
|
|
@printf "%8s %s\n" "$1" "$2"
|
|
|
|
endef
|
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
# Don't delete intermediate targets
|
2010-02-23 00:58:45 +01:00
|
|
|
.SECONDARY:
|
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
#####
|
|
|
|
# Tools and flags
|
2010-03-01 22:27:58 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
# Set up cross compiler and toolchain definitions.
|
|
|
|
CROSS_COMPILE ?= arm-linux-
|
|
|
|
AS = $(CROSS_COMPILE)as
|
|
|
|
LD = $(CROSS_COMPILE)ld
|
|
|
|
CC = $(CROSS_COMPILE)gcc
|
|
|
|
CPP = $(CC) -E
|
|
|
|
AR = $(CROSS_COMPILE)ar
|
|
|
|
NM = $(CROSS_COMPILE)nm
|
|
|
|
STRIP = $(CROSS_COMPILE)strip
|
|
|
|
OBJCOPY = $(CROSS_COMPILE)objcopy
|
|
|
|
OBJDUMP = $(CROSS_COMPILE)objdump
|
|
|
|
RANLIB = $(CROSS_COMPILE)ranlib
|
|
|
|
|
|
|
|
# Build CFLAGS and prepend it to user-supplied CFLAGS
|
|
|
|
CFLAGS_PLAT ?= -march=armv4t -mtune=arm7tdmi-s -mlong-calls -msoft-float \
|
|
|
|
-mthumb-interwork -fno-strict-aliasing -fno-common -ffixed-r8 \
|
|
|
|
-ffunction-sections -ffreestanding -fno-builtin
|
|
|
|
CFLAGS_WARN ?= -Wcast-align -Wall -Wstrict-prototypes -Wextra
|
|
|
|
CFLAGS_OPT ?= -Os
|
|
|
|
CFLAGS_DEBUG ?= -g -DDEBUG -Werror
|
|
|
|
CFLAGS_MISC ?= -pipe
|
|
|
|
CFLAGS := $(CFLAGS_PLAT) $(CFLAGS_WARN) $(CFLAGS_OPT) $(CFLAGS_DEBUG) $(CFLAGS_MISC) $(CFLAGS)
|
|
|
|
|
|
|
|
# Thumb flags, used for building most objects
|
|
|
|
CFLAGS_THUMB ?= -mthumb -mcallee-super-interworking
|
|
|
|
|
|
|
|
# Linker flags
|
|
|
|
LINKERSCRIPT ?= $(MC1322X)/mc1322x.lds
|
2010-09-25 23:48:28 +02:00
|
|
|
LDFLAGS ?= -T $(LINKERSCRIPT) -nostartfiles -static -export-dynamic -u_start -Wl,-Map=$(@:.elf=.map)
|
2010-02-21 23:34:27 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
# Assembler flags
|
|
|
|
AFLAGS ?= -Wa,-gstabs $(CFLAGS)
|
2010-02-21 23:34:27 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
# Misc tool options
|
|
|
|
OBJCOPYFLAGS ?= --gap-fill=0xff
|
2010-09-25 00:21:29 +02:00
|
|
|
ARFLAGS = cr
|
2010-03-11 22:17:18 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
#####
|
2010-03-12 23:00:53 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
include $(MC1322X)/board/Makefile.board
|
|
|
|
include $(MC1322X)/lib/Makefile.lib
|
|
|
|
include $(MC1322X)/src/Makefile.src
|
|
|
|
|
|
|
|
#####
|
2010-09-25 00:27:14 +02:00
|
|
|
# Rule for building ELF files. We use both a wildcard rule that links
|
|
|
|
# $(SRCLIB) as well as target-specific rules that link $(SRCLIB_ROMVARS)
|
|
|
|
|
|
|
|
# Normal targets (wildcard rule):
|
|
|
|
%_$(BOARD).elf: $(OBJDIR)/%.o $(OBJDIR)/board.a $(MC1322X)/lib/libmc1322x.a $(SRCLIB)
|
|
|
|
$(call pretty,LINK,$@)
|
|
|
|
$Q$(CC) $(LDFLAGS) -o $@ -Wl,--start-group $^ -lm -Wl,--end-group
|
|
|
|
|
|
|
|
# Targets that need space for rom variables:
|
2010-09-20 22:28:22 +02:00
|
|
|
define build_elf_rule
|
2010-09-25 00:27:14 +02:00
|
|
|
$(1)_$$(BOARD).elf: $$(OBJDIR)/$(1).o $$(OBJDIR)/board.a $$(MC1322X)/lib/libmc1322x.a $$(SRCLIB_ROMVARS)
|
|
|
|
$$(call pretty,LINK (romvars),$$@)
|
2010-09-25 00:21:29 +02:00
|
|
|
$$Q$$(CC) $$(LDFLAGS) -o $$@ -Wl,--start-group $$^ -lm -Wl,--end-group
|
2010-09-20 22:28:22 +02:00
|
|
|
endef
|
2010-09-25 00:27:14 +02:00
|
|
|
$(foreach t, $(TARGETS_WITH_ROM_VARS), $(eval $(call build_elf_rule,$(t))))
|
|
|
|
|
2010-03-02 20:32:34 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
# Generic rules
|
|
|
|
%.srec: %.elf
|
2010-09-25 00:21:29 +02:00
|
|
|
$(call pretty,OBJCOPY,$@)
|
|
|
|
$Q$(OBJCOPY) $(OBJCOPYFLAGS) -O srec $< $@
|
2010-02-21 23:34:27 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
%.ihex: %.elf
|
2010-09-25 00:21:29 +02:00
|
|
|
$(call pretty,OBJCOPY,$@)
|
|
|
|
$Q$(OBJCOPY) $(OBJCOPYFLAGS) -O ihex $< $@
|
2010-02-23 21:53:00 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
%.bin: %.elf
|
2010-09-25 00:21:29 +02:00
|
|
|
$(call pretty,OBJCOPY,$@)
|
|
|
|
$Q$(OBJCOPY) $(OBJCOPYFLAGS) -O binary $< $@
|
2010-02-23 21:53:00 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
%.dis: %.elf
|
2010-09-25 00:21:29 +02:00
|
|
|
$(call pretty,OBJDUMP,$@)
|
|
|
|
$Q$(OBJDUMP) -Sd $< > $@ || rm -f $@
|
2010-02-23 21:53:00 +01:00
|
|
|
|
2010-09-27 23:32:59 +02:00
|
|
|
%.dis: %.o
|
|
|
|
$(call pretty,OBJDUMP,$@)
|
|
|
|
$Q$(OBJDUMP) -d $< > $@ || rm -f $@
|
|
|
|
|
2010-09-28 08:15:43 +02:00
|
|
|
%.o: %.c $(FORCE_C_DEPENDS)
|
2010-09-25 00:21:29 +02:00
|
|
|
$(call pretty,CC,$@)
|
|
|
|
$Q$(CC) $(CFLAGS) $(CFLAGS_THUMB) -MMD -c -o $@ $<
|
2010-09-20 22:28:22 +02:00
|
|
|
@$(FINALIZE_DEPENDENCY)
|
2010-02-23 21:53:00 +01:00
|
|
|
|
2010-03-02 16:38:32 +01:00
|
|
|
%.o: %.S
|
2010-09-25 00:21:29 +02:00
|
|
|
$(call pretty,AS,$@)
|
|
|
|
$Q$(CC) $(AFLAGS) -MMD -c -o $@ $<
|
2010-03-02 16:38:32 +01:00
|
|
|
@$(FINALIZE_DEPENDENCY)
|
2010-03-02 00:02:29 +01:00
|
|
|
|
2010-09-25 00:21:29 +02:00
|
|
|
(%): %
|
|
|
|
$(call pretty,AR,$@($<))
|
|
|
|
@$(AR) $(ARFLAGS) $@ $<
|
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
# Fix the dependencies generated for a particular target .o
|
|
|
|
# See http://make.paulandlesley.org/autodep.html#advanced
|
|
|
|
define FINALIZE_DEPENDENCY
|
|
|
|
cp $(@:.o=.d) $(@:.o=.$$$$); \
|
|
|
|
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
|
|
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.$$$$) >> $(@:.o=.d); \
|
|
|
|
rm -f $(@:.o=.$$$$)
|
|
|
|
endef
|
|
|
|
|
|
|
|
clean::
|
|
|
|
rm -f *.{o,d,a,bin,elf,ihex,srec,dis,map,bak} *~
|
2010-02-23 00:58:45 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
.PHONY: clean
|
2010-02-24 00:54:50 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
##############################
|
2010-02-24 00:27:12 +01:00
|
|
|
|
2010-09-20 22:28:22 +02:00
|
|
|
# If no single board was specified, invoke make recursively for each
|
|
|
|
# board in $(BOARDS), or $(ALL_BOARDS) if that wasn't specified either.
|
|
|
|
# This is at the end so that it can override all other targets.
|
|
|
|
ifndef BOARD
|
|
|
|
ifneq ($(MAKECMDGOALS),clean)
|
|
|
|
.DEFAULT_GOAL=mc1322x-default
|
|
|
|
BOARDS ?= $(ALL_BOARDS)
|
|
|
|
define build_board
|
|
|
|
@echo "Building for board: $(1)"
|
|
|
|
@$(MAKE) --no-print-directory BOARD=$(1) $(2)
|
|
|
|
|
|
|
|
endef
|
|
|
|
$(MAKECMDGOALS):
|
|
|
|
$(foreach b, $(BOARDS), $(call build_board,$(b),$@))
|
|
|
|
mc1322x-default:
|
|
|
|
$(foreach b, $(BOARDS), $(call build_board,$(b),))
|
|
|
|
endif
|
|
|
|
endif
|