contiki/cpu/mc1322x/Makefile.mc1322x
Peter A. Bigot 5fc0575e99 Makefile.include: support make clean all
Historically $(OBJECTDIR) was created when Makefile.include is read.  A
consequence is that combining "clean" with "all" (or any other build
target) results in an error because the clean removes the object
directory that is required to exist when building dependencies.
Creating $(OBJECTDIR) on-demand ensures it is present when needed.

Removed creation of $(OBJECTDIR) on initial read, and added an order-only
dependency forcing its creation all Makefile* rules where the target is
explicitly or implicitly in $(OBJECTDIR).
2013-06-20 17:45:41 -05:00

120 lines
3.5 KiB
Makefile

# -*- makefile -*-
# Adapted from Makefile.msp430
# Adapted from Makefile.at91sam7
### Define the CPU directory
CONTIKI_CPU=$(CONTIKI)/cpu/mc1322x
### Define the source files we have in the AT91SAM7S port
CONTIKI_CPU_DIRS = . lib src board dev ../arm/common/dbg-io
MC1322X = debug-uart.c rtimer-arch.c watchdog.c contiki-maca.c contiki-misc.c leds-arch.c leds.c contiki-uart.c slip-uart1.c init.c config.c
DBG_IO = dbg-printf.c dbg-snprintf.c dbg-sprintf.c strformat.c
CPU_LIBS = $(notdir $(wildcard $(CONTIKI_CPU)/lib/*.c))
CPU_SRCS = $(notdir $(wildcard $(CONTIKI_CPU)/src/*.c)) $(notdir $(wildcard $(CONTIKI_CPU)/src/*.S))
CONTIKI_TARGET_SOURCEFILES += $(MC1322X) $(DBG_IO) $(CPU_LIBS) $(CPU_SRCS) $(SYSAPPS) $(ELFLOADER) \
$(TARGETLIBS) $(UIPDRIVERS) $(USB)
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
THREADS =
CROSS_COMPILE ?= arm-none-eabi-
CROSS ?= $(CROSS_COMPILE)
### Compiler definitions
CC = $(CROSS)gcc
LD = $(CROSS)gcc
AS = $(CROSS)as
AR = $(CROSS)ar
NM = $(CROSS)nm
OBJCOPY = $(CROSS)objcopy
STRIP = $(CROSS)strip
PROJECT_OBJECTFILES += ${addprefix $(OBJECTDIR)/,$(CONTIKI_TARGET_MAIN:.c=.o)}
TEXT_BASE = 0x00400000
export TEXT_BASE
LINKERSCRIPT = $(OBJECTDIR)/mc1322x.lds
STARTUP=$(OBJECTDIR)/start.o
ARCH_FLAGS= -mcpu=arm7tdmi-s -mthumb-interwork -march=armv4t -mtune=arm7tdmi-s -DCONFIG_ARM -D__ARM__ #-Wcast-align
THUMB_FLAGS= -mthumb -mcallee-super-interworking
ARM_FLAGS= -marm
CFLAGSNO = -I. -I$(CONTIKI)/core -I$(CONTIKI_CPU) -I$(CONTIKI_CPU)/loader \
-I$(CONTIKI_CPU)/dbg-io \
-I$(CONTIKI)/platform/$(TARGET) \
-I$(CONTIKI_CPU)/lib/include \
-I$(CONTIKI_CPU)/src \
-I$(CONTIKI_CPU)/board \
${addprefix -I,$(APPDIRS)} \
-DWITH_ASCII -DMCK=$(MCK) \
-Werror $(ARCH_FLAGS) -g
CFLAGS += $(CFLAGSNO) -Os -DRUN_AS_SYSTEM -DROM_RUN -fno-strict-aliasing -fno-common -ffixed-r8 -msoft-float -DTEXT_BASE=$(TEXT_BASE) -fno-builtin-printf -fno-builtin-sprintf -ffunction-sections -fdata-sections -MMD
LDFLAGS += -T $(LINKERSCRIPT) -nostartfiles -static -u_start -Wl,-Map=contiki-$(TARGET).map,-export-dynamic,--gc-sections
AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) -gstabs
CDEPFLAGS = $(CFLAGS) -D __MAKING_DEPS__
### Setup directory search path for source files
CUSTOM_RULE_C_TO_OBJECTDIR_O=yes
CUSTOM_RULE_C_TO_O=yes
CFLAGS += -I$(OBJECTDIR) -I$(CONTIKI_CPU)/board -DBOARD=$(TARGET)
CPPFLAGS += -P -C ${addprefix -D,${subst $(COMMA), ,$(DEFINES)}}
$(OBJECTDIR)/board.h: $(CONTIKI_CPU)/board/board.h | $(OBJECTDIR)
ifeq ($(HOST_OS),Windows)
ln -f $< $@
else
ln -sf ../$< $@
endif
$(OBJECTDIR)/%.lds: $(CONTIKI_CPU)/%.lds.S | $(OBJECTDIR)
$(CPP) $(CPPFLAGS) $< > $@
$(OBJECTDIR)/isr.o: $(CONTIKI_CPU)/src/isr.c | $(OBJECTDIR)
$(CC) $(CFLAGS) $(ARM_FLAGS) $< -c -o $@
%.o: %.c
$(CC) $(CFLAGS) $(THUMB_FLAGS) $< -c
$(OBJECTDIR)/%.o: %.c | $(OBJECTDIR)
$(CC) $(CFLAGS) $(THUMB_FLAGS) -c $< -o $@
CUSTOM_RULE_S_TO_OBJECTDIR_O = yes
$(OBJECTDIR)/%.o: %.S | $(OBJECTDIR)
$(CC) $(CFLAGS) $(AFLAGS) $(ARM_FLAGS) $< -c -o $@
CUSTOM_RULE_C_TO_CO=yes
%.co: %.c
$(CC) $(CFLAGS) -DAUTOSTART_ENABLE $(THUMB_FLAGS) $< -c -o $@
.PRECIOUS: %.bin %_$(TARGET).bin
%.ihex: %.$(TARGET)
$(OBJCOPY) $^ -O ihex $@
%_$(TARGET).bin: %.elf
$(OBJCOPY) -O binary $< $@
%.$(TARGET): %_$(TARGET).bin
@
%.elf: $(OBJECTDIR)/board.h %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a $(STARTUP) $(OBJECTDIR)/mc1322x.lds
$(CC) $(LDFLAGS) $(CFLAGS) -nostartfiles -o $@ $(filter-out %.a %.lds,$^) $(filter %.a,$^) $(filter %.a,$^)