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 += ad_parser.c 109SRC += ancs_client.c 110SRC += att_db.c 111SRC += att_dispatch.c 112SRC += att_server.c 113SRC += battery_service_server.c 114SRC += btstack_em9304_spi_embedded.c 115SRC += btstack_linked_list.c 116SRC += btstack_memory.c 117SRC += btstack_memory_pool.c 118SRC += btstack_port.c 119SRC += btstack_ring_buffer.c 120SRC += btstack_run_loop.c 121SRC += btstack_run_loop_embedded.c 122SRC += btstack_tlv.c 123SRC += btstack_uart_block_embedded.c 124SRC += btstack_util.c 125SRC += device_information_service_server.c 126SRC += gatt_client.c 127SRC += hci.c 128SRC += hci_cmd.c 129SRC += hci_dump.c 130SRC += hci_transport_em9304_spi.c 131SRC += l2cap.c 132SRC += l2cap_signaling.c 133SRC += le_device_db_memory.c 134SRC += sm.c 135SRC += uECC.c 136 137SRC += $(TARGET).c 138 139SRC += am_util_delay.c 140SRC += am_util_faultisr.c 141SRC += am_util_stdio.c 142SRC += am_devices_button.c 143# SRC += am_devices_em9304.c 144SRC += startup_gcc.c 145 146CSRC = $(filter %.c,$(SRC)) 147ASRC = $(filter %.s,$(SRC)) 148 149OBJS = $(CSRC:%.c=$(CONFIG)/%.o) 150OBJS+= $(ASRC:%.s=$(CONFIG)/%.o) 151 152DEPS = $(CSRC:%.c=$(CONFIG)/%.d) 153DEPS+= $(ASRC:%.s=$(CONFIG)/%.d) 154 155LIBS = ${AM_SoftwareRoot}/boards/apollo2_evb_am_ble/bsp/gcc/bin/libam_bsp.a 156LIBS += ${AM_SoftwareRoot}/mcu/apollo2/hal/gcc/bin/libam_hal.a 157INCS = ${AM_SoftwareRoot}/boards/apollo2_evb_am_ble/bsp/am_bsp_gpio.h 158INCS += ${AM_SoftwareRoot}/mcu/apollo2/hal/am_hal_pin.h 159 160CFLAGS = -mthumb -mcpu=$(CPU) -mfpu=$(FPU) -mfloat-abi=$(FABI) 161CFLAGS+= -ffunction-sections -fdata-sections 162CFLAGS+= -MMD -MP -std=c99 -Wall -g 163CFLAGS+= -O0 164CFLAGS+= $(DEFINES) 165CFLAGS+= $(INCLUDES) 166CFLAGS+= -Dgcc 167 168AM_LFLAGS = -mthumb -mcpu=$(CPU) -mfpu=$(FPU) -mfloat-abi=$(FABI) 169AM_LFLAGS+= -nostartfiles -static 170AM_LFLAGS+= -Wl,--gc-sections,--entry,am_reset_isr,-Map,$(CONFIG)/$(TARGET).map 171AM_LFLAGS+= -Wl,--start-group -lm -lc -lgcc -Wl,--end-group 172AM_LFLAGS+= 173 174# Additional user specified CFLAGS 175CFLAGS+=$(EXTRA_CFLAGS) 176 177CPFLAGS = -Obinary 178 179ODFLAGS = -S 180 181#### Rules #### 182all: directories $(CONFIG)/$(TARGET).bin 183 184directories: $(CONFIG) 185 186$(CONFIG): 187 @mkdir -p $@ 188 189$(CONFIG)/%.o: %.c $(CONFIG)/%.d $(INCS) 190 @echo " Compiling $(COMPILERNAME) $<" ;\ 191 $(CC) -c $(CFLAGS) $< -o $@ 192 193$(CONFIG)/%.o: %.s $(CONFIG)/%.d $(INCS) 194 @echo " Assembling $(COMPILERNAME) $<" ;\ 195 $(CC) -c $(CFLAGS) $< -o $@ 196 197 198$(CONFIG)/$(TARGET).elf: $(OBJS) $(LIBS) 199 @echo " Linking $(COMPILERNAME) $@" ;\ 200 $(CC) -Wl,-T,$(LINKER_FILE) -o $@ $(OBJS) $(LIBS) $(AM_LFLAGS) 201 202$(CONFIG)/$(TARGET).bin: $(CONFIG)/$(TARGET).elf 203 @echo " Copying $(COMPILERNAME) $@..." ;\ 204 $(CP) $(CPFLAGS) $< $@ ;\ 205 $(OD) $(ODFLAGS) $< > $(CONFIG)/$(TARGET).lst 206 207clean: 208 @echo "Cleaning..." ;\ 209 $(RM) -f $(OBJS) $(DEPS) \ 210 $(CONFIG)/$(TARGET).bin $(CONFIG)/$(TARGET).elf \ 211 $(CONFIG)/$(TARGET).lst $(CONFIG)/$(TARGET).map \ 212 $(CONFIG)/$(TARGET).h 213 214$(CONFIG)/%.d: ; 215 216# Automatically include any generated dependencies 217-include $(DEPS) 218endif 219.PHONY: all clean directories 220 221