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