mdebug

cortex m series debugger
git clone http://frotz.net/git/mdebug.git
Log | Files | Refs | README | LICENSE

build.mk (2250B)


      1 
      2 what_to_build:: all
      3 
      4 -include local.mk
      5 
      6 #TOOLCHAIN ?= arm-none-eabi-
      7 
      8 TARGET_CC := $(TOOLCHAIN)gcc
      9 TARGET_OBJCOPY := $(TOOLCHAIN)objcopy
     10 TARGET_OBJDUMP := $(TOOLCHAIN)objdump
     11 
     12 ARCH_M3_CFLAGS := -mcpu=cortex-m3 -mthumb
     13 ARCH_M3_LIBS := $(shell $(TARGET_CC) $(ARCH_M3_CFLAGS) -print-libgcc-file-name)
     14 
     15 ARCH_M0_CFLAGS := -mcpu=cortex-m0 -mthumb
     16 ARCH_M0_LIBS := $(shell $(TARGET_CC) $(ARCH_M0_CFLAGS) -print-libgcc-file-name)
     17 
     18 TARGET_CFLAGS := -g -Os -Wall
     19 TARGET_CFLAGS += -Wno-unused-but-set-variable
     20 TARGET_CFLAGS += -I. -Iinclude
     21 #TARGET_CFLAGS += -mcpu=cortex-m3 -mthumb -mthumb-interwork
     22 TARGET_CFLAGS += -ffunction-sections -fdata-sections
     23 TARGET_CFLAGS += -fno-builtin -nostdlib
     24 
     25 # tell gcc there's not a full libc it can depend on
     26 # so it won't do thinks like printf("...") -> puts("...")
     27 TARGET_CFLAGS += -ffreestanding
     28 
     29 QUIET := @
     30 
     31 UNAME := $(shell uname)
     32 UNAME_M := $(shell uname -m)
     33 
     34 HOST_CFLAGS := -g -O1 -Wall
     35 HOST_CFLAGS += -Itools -Iinclude
     36 HOST_CFLAGS += -DLINENOISE_INTERRUPTIBLE
     37 
     38 ifeq ($(UNAME),Darwin)
     39 HOST_CFLAGS += -I/opt/local/include -L/opt/local/lib
     40 HOST_LIBS += -lusb-1.0
     41 endif
     42 ifeq ($(UNAME),Linux)
     43 HOST_LIBS += -lusb-1.0 -lpthread -lrt
     44 endif
     45 
     46 AGENTS :=
     47 ALL :=
     48 DEPS :=
     49 
     50 out/agent-%.bin: out/agent-%.elf
     51 	@mkdir -p $(dir $@)
     52 	@echo generate $@
     53 	$(QUIET)$(TARGET_OBJCOPY) -O binary $< $@
     54 
     55 out/agent-%.lst: out/agent-%.elf
     56 	@mkdir -p $(dir $@)
     57 	@echo generate $@
     58 	$(QUIET)$(TARGET_OBJDUMP) -d $< > $@
     59 
     60 out/agent-%.elf: agents/%.c
     61 	@mkdir -p $(dir $@)
     62 	@echo compile $@
     63 	$(QUIET)$(TARGET_CC) $(TARGET_CFLAGS) $(ARCH_$(ARCH)_CFLAGS) -Wl,--script=build/agent.ld -Wl,-Ttext=$(LOADADDR) -o $@ $< $(ARCH_$(ARCH)_LIBS)
     64 
     65 out/%.o: %.c
     66 	@mkdir -p $(dir $@)
     67 	@echo compile $<
     68 	$(QUIET)gcc -MMD -MP -c $(HOST_CFLAGS) -o $@ $< 
     69 
     70 define _program
     71 ALL += bin/$1
     72 DEPS += $3
     73 bin/$1: $2
     74 	@mkdir -p $$(dir $$@)
     75 	@echo link $$@
     76 	$(QUIET)gcc $(HOST_CFLAGS) -o $$@ $2 $(HOST_LIBS)
     77 endef
     78 
     79 program = $(eval $(call _program,$1,$(patsubst %.c,out/%.o,$2),$(patsubst %.c,out/%.d,$2)))
     80 
     81 agent = $(eval AGENTS += $(strip $1))\
     82 $(eval ALL += $(patsubst %,out/agent-%.bin,$(strip $1)))\
     83 $(eval ALL += $(patsubst %,out/agent-%.lst,$(strip $1)))\
     84 $(eval out/agent-$(strip $1).elf: LOADADDR := $(strip $2))\
     85 $(eval out/agent-$(strip $1).elf: ARCH := $(strip $3))
     86