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 += uECC.c 113 114-include ${AM_SoftwareRoot}/third_party/btstack/src/Makefile.inc 115-include ${AM_SoftwareRoot}/third_party/btstack/src/ble/Makefile.inc 116-include ${AM_SoftwareRoot}/third_party/btstack/src/ble/gatt-service/Makefile.inc 117 118SRC += $(SRC_FILES) 119SRC += $(filter-out att_db_util.c le_device_db_tlv.c,$(SRC_BLE_FILES)) 120SRC += $(SRC_BLE_GATT_SERVICE_FILES) 121 122SRC += $(TARGET).c 123 124SRC += am_util_delay.c 125SRC += am_util_faultisr.c 126SRC += am_util_stdio.c 127SRC += am_devices_button.c 128# SRC += am_devices_em9304.c 129SRC += startup_gcc.c 130 131CSRC = $(filter %.c,$(SRC)) 132ASRC = $(filter %.s,$(SRC)) 133 134OBJS = $(CSRC:%.c=$(CONFIG)/%.o) 135OBJS+= $(ASRC:%.s=$(CONFIG)/%.o) 136 137DEPS = $(CSRC:%.c=$(CONFIG)/%.d) 138DEPS+= $(ASRC:%.s=$(CONFIG)/%.d) 139 140LIBS = ${AM_SoftwareRoot}/boards/apollo2_evb_am_ble/bsp/gcc/bin/libam_bsp.a 141LIBS += ${AM_SoftwareRoot}/mcu/apollo2/hal/gcc/bin/libam_hal.a 142INCS = ${AM_SoftwareRoot}/boards/apollo2_evb_am_ble/bsp/am_bsp_gpio.h 143INCS += ${AM_SoftwareRoot}/mcu/apollo2/hal/am_hal_pin.h 144 145CFLAGS = -mthumb -mcpu=$(CPU) -mfpu=$(FPU) -mfloat-abi=$(FABI) 146CFLAGS+= -ffunction-sections -fdata-sections 147CFLAGS+= -MMD -MP -std=c99 -Wall -g 148CFLAGS+= -O0 149CFLAGS+= $(DEFINES) 150CFLAGS+= $(INCLUDES) 151CFLAGS+= -Dgcc 152 153AM_LFLAGS = -mthumb -mcpu=$(CPU) -mfpu=$(FPU) -mfloat-abi=$(FABI) 154AM_LFLAGS+= -nostartfiles -static 155AM_LFLAGS+= -Wl,--gc-sections,--entry,am_reset_isr,-Map,$(CONFIG)/$(TARGET).map 156AM_LFLAGS+= -Wl,--start-group -lm -lc -lgcc -Wl,--end-group 157AM_LFLAGS+= 158 159# Additional user specified CFLAGS 160CFLAGS+=$(EXTRA_CFLAGS) 161 162CPFLAGS = -Obinary 163 164ODFLAGS = -S 165 166#### Rules #### 167all: directories $(CONFIG)/$(TARGET).bin 168 169directories: $(CONFIG) 170 171$(CONFIG): 172 @mkdir -p $@ 173 174$(CONFIG)/%.o: %.c $(CONFIG)/%.d $(INCS) 175 @echo " Compiling $(COMPILERNAME) $<" ;\ 176 $(CC) -c $(CFLAGS) $< -o $@ 177 178$(CONFIG)/%.o: %.s $(CONFIG)/%.d $(INCS) 179 @echo " Assembling $(COMPILERNAME) $<" ;\ 180 $(CC) -c $(CFLAGS) $< -o $@ 181 182 183$(CONFIG)/$(TARGET).elf: $(OBJS) $(LIBS) 184 @echo " Linking $(COMPILERNAME) $@" ;\ 185 $(CC) -Wl,-T,$(LINKER_FILE) -o $@ $(OBJS) $(LIBS) $(AM_LFLAGS) 186 187$(CONFIG)/$(TARGET).bin: $(CONFIG)/$(TARGET).elf 188 @echo " Copying $(COMPILERNAME) $@..." ;\ 189 $(CP) $(CPFLAGS) $< $@ ;\ 190 $(OD) $(ODFLAGS) $< > $(CONFIG)/$(TARGET).lst 191 192clean: 193 @echo "Cleaning..." ;\ 194 $(RM) -f $(OBJS) $(DEPS) \ 195 $(CONFIG)/$(TARGET).bin $(CONFIG)/$(TARGET).elf \ 196 $(CONFIG)/$(TARGET).lst $(CONFIG)/$(TARGET).map \ 197 $(CONFIG)/$(TARGET).h 198 199$(CONFIG)/%.d: ; 200 201# Automatically include any generated dependencies 202-include $(DEPS) 203endif 204.PHONY: all clean directories 205 206