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