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