1#****************************************************************************** 2# 3# Makefile - Rules for building the libraries, examples and docs. 4# 5# Copyright (c) 2017, Ambiq Micro 6# All rights reserved. 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions are met: 10# 11# 1. Redistributions of source code must retain the above copyright notice, 12# this list of conditions and the following disclaimer. 13# 14# 2. Redistributions in binary form must reproduce the above copyright 15# notice, this list of conditions and the following disclaimer in the 16# documentation and/or other materials provided with the distribution. 17# 18# 3. Neither the name of the copyright holder nor the names of its 19# contributors may be used to endorse or promote products derived from this 20# software without specific prior written permission. 21# 22# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32# POSSIBILITY OF SUCH DAMAGE. 33# 34# This is part of revision 1.2.11 of the AmbiqSuite Development Package. 35# 36#****************************************************************************** 37TARGET := EXAMPLE 38COMPILERNAME := gcc 39PROJECT := btstack_template_gcc 40CONFIG := bin 41AM_SoftwareRoot ?= ../../../../.. 42 43SHELL:=/bin/bash 44#### Setup #### 45 46TOOLCHAIN ?= arm-none-eabi 47PART = apollo2 48CPU = cortex-m4 49FPU = fpv4-sp-d16 50FABI = softfp 51 52LINKER_FILE := ./btstack_template.ld 53STARTUP_FILE := ./startup_$(COMPILERNAME).c 54 55#### Required Executables #### 56CC = $(TOOLCHAIN)-gcc 57GCC = $(TOOLCHAIN)-gcc 58CPP = $(TOOLCHAIN)-cpp 59LD = $(TOOLCHAIN)-ld 60CP = $(TOOLCHAIN)-objcopy 61OD = $(TOOLCHAIN)-objdump 62RD = $(TOOLCHAIN)-readelf 63AR = $(TOOLCHAIN)-ar 64SIZE = $(TOOLCHAIN)-size 65RM = $(shell which rm 2>/dev/null) 66 67EXECUTABLES = CC LD CP OD AR RD SIZE GCC 68K := $(foreach exec,$(EXECUTABLES),\ 69 $(if $(shell which $($(exec)) 2>/dev/null),,\ 70 $(info $(exec) not found on PATH ($($(exec))).)$(exec))) 71$(if $(strip $(value K)),$(info Required Program(s) $(strip $(value K)) not found)) 72 73ifneq ($(strip $(value K)),) 74all clean: 75 $(info Tools $(TOOLCHAIN)-$(COMPILERNAME) not installed.) 76 $(RM) -rf bin 77else 78 79DEFINES = -DPART_$(PART) 80DEFINES+= -DAM_PACKAGE_BGA 81DEFINES += -DAM_PART_APOLLO2 82 83INCLUDES = -I../src 84INCLUDES += -I${AM_SoftwareRoot}/boards/apollo2_evb_am_ble/bsp 85INCLUDES += -I${AM_SoftwareRoot}/utils 86INCLUDES += -I${AM_SoftwareRoot}/devices 87INCLUDES += -I${AM_SoftwareRoot}/mcu/apollo2 88INCLUDES += -I${AM_SoftwareRoot} 89 90VPATH = ${AM_SoftwareRoot}/utils 91VPATH +=:${AM_SoftwareRoot}/devices 92VPATH +=:../src 93 94# BTstack 95INCLUDES += -I${AM_SoftwareRoot}/third_party/btstack/src 96INCLUDES += -I${AM_SoftwareRoot}/third_party/btstack/platform/embedded 97INCLUDES += -I${AM_SoftwareRoot}/third_party/btstack/port/apollo2-em9304 98INCLUDES += -I${AM_SoftwareRoot}/third_party/btstack/3rd-party/micro-ecc 99 100VPATH += ${AM_SoftwareRoot}/third_party/btstack/3rd-party/micro-ecc 101VPATH += ${AM_SoftwareRoot}/third_party/btstack/example 102VPATH += ${AM_SoftwareRoot}/third_party/btstack/platform/embedded 103VPATH += ${AM_SoftwareRoot}/third_party/btstack/port/apollo2-em9304 104VPATH += ${AM_SoftwareRoot}/third_party/btstack/src 105VPATH += ${AM_SoftwareRoot}/third_party/btstack/src/ble 106VPATH += ${AM_SoftwareRoot}/third_party/btstack/src/ble/gatt-service 107 108SRC += btstack_em9304_spi_embedded.c 109SRC += btstack_port.c 110SRC += btstack_run_loop_embedded.c 111SRC += btstack_uart_block_embedded.c 112SRC += hci_dump_embedded_stdout.c 113SRC += uECC.c 114 115-include ${AM_SoftwareRoot}/third_party/btstack/src/Makefile.inc 116-include ${AM_SoftwareRoot}/third_party/btstack/src/ble/Makefile.inc 117-include ${AM_SoftwareRoot}/third_party/btstack/src/ble/gatt-service/Makefile.inc 118 119SRC += $(SRC_FILES) 120SRC += $(filter-out att_db_util.c le_device_db_tlv.c,$(SRC_BLE_FILES)) 121SRC += $(SRC_BLE_GATT_SERVICE_FILES) 122 123SRC += $(TARGET).c 124 125SRC += am_util_delay.c 126SRC += am_util_faultisr.c 127SRC += am_util_stdio.c 128SRC += am_devices_button.c 129# SRC += am_devices_em9304.c 130SRC += startup_gcc.c 131 132CSRC = $(filter %.c,$(SRC)) 133ASRC = $(filter %.s,$(SRC)) 134 135OBJS = $(CSRC:%.c=$(CONFIG)/%.o) 136OBJS+= $(ASRC:%.s=$(CONFIG)/%.o) 137 138DEPS = $(CSRC:%.c=$(CONFIG)/%.d) 139DEPS+= $(ASRC:%.s=$(CONFIG)/%.d) 140 141LIBS = ${AM_SoftwareRoot}/boards/apollo2_evb_am_ble/bsp/gcc/bin/libam_bsp.a 142LIBS += ${AM_SoftwareRoot}/mcu/apollo2/hal/gcc/bin/libam_hal.a 143INCS = ${AM_SoftwareRoot}/boards/apollo2_evb_am_ble/bsp/am_bsp_gpio.h 144INCS += ${AM_SoftwareRoot}/mcu/apollo2/hal/am_hal_pin.h 145 146CFLAGS = -mthumb -mcpu=$(CPU) -mfpu=$(FPU) -mfloat-abi=$(FABI) 147CFLAGS+= -ffunction-sections -fdata-sections 148CFLAGS+= -MMD -MP -std=c99 -Wall -g 149CFLAGS+= -O0 150CFLAGS+= $(DEFINES) 151CFLAGS+= $(INCLUDES) 152CFLAGS+= -Dgcc 153 154AM_LFLAGS = -mthumb -mcpu=$(CPU) -mfpu=$(FPU) -mfloat-abi=$(FABI) 155AM_LFLAGS+= -nostartfiles -static 156AM_LFLAGS+= -Wl,--gc-sections,--entry,am_reset_isr,-Map,$(CONFIG)/$(TARGET).map 157AM_LFLAGS+= -Wl,--start-group -lm -lc -lgcc -Wl,--end-group 158AM_LFLAGS+= 159 160# Additional user specified CFLAGS 161CFLAGS+=$(EXTRA_CFLAGS) 162 163CPFLAGS = -Obinary 164 165ODFLAGS = -S 166 167#### Rules #### 168all: directories $(CONFIG)/$(TARGET).bin 169 170directories: $(CONFIG) 171 172$(CONFIG): 173 @mkdir -p $@ 174 175$(CONFIG)/%.o: %.c $(CONFIG)/%.d $(INCS) 176 @echo " Compiling $(COMPILERNAME) $<" ;\ 177 $(CC) -c $(CFLAGS) $< -o $@ 178 179$(CONFIG)/%.o: %.s $(CONFIG)/%.d $(INCS) 180 @echo " Assembling $(COMPILERNAME) $<" ;\ 181 $(CC) -c $(CFLAGS) $< -o $@ 182 183 184$(CONFIG)/$(TARGET).elf: $(OBJS) $(LIBS) 185 @echo " Linking $(COMPILERNAME) $@" ;\ 186 $(CC) -Wl,-T,$(LINKER_FILE) -o $@ $(OBJS) $(LIBS) $(AM_LFLAGS) 187 188$(CONFIG)/$(TARGET).bin: $(CONFIG)/$(TARGET).elf 189 @echo " Copying $(COMPILERNAME) $@..." ;\ 190 $(CP) $(CPFLAGS) $< $@ ;\ 191 $(OD) $(ODFLAGS) $< > $(CONFIG)/$(TARGET).lst 192 193clean: 194 @echo "Cleaning..." ;\ 195 $(RM) -f $(OBJS) $(DEPS) \ 196 $(CONFIG)/$(TARGET).bin $(CONFIG)/$(TARGET).elf \ 197 $(CONFIG)/$(TARGET).lst $(CONFIG)/$(TARGET).map \ 198 $(CONFIG)/$(TARGET).h 199 200$(CONFIG)/%.d: ; 201 202# Automatically include any generated dependencies 203-include $(DEPS) 204endif 205.PHONY: all clean directories 206 207