mirror of
https://github.com/cesanta/mongoose.git
synced 2024-12-21 05:21:03 +08:00
8d72c2a7b2
PUBLISHED_FROM=d9d979057d5269ac32d16545dd2489485bda642a
300 lines
11 KiB
Makefile
300 lines
11 KiB
Makefile
.PHONY: all clean flash gdbserver gdb jlinkexe rtt
|
|
|
|
APP_ROOT=.
|
|
MONGOOSE_ROOT=../..
|
|
|
|
BUILD_DIR=.build
|
|
OUT_DIR=out
|
|
PROJECT=example
|
|
|
|
NRF_IOT_SDK_ROOT=/opt/nrf5_iot_sdk
|
|
GNU_PREFIX := arm-none-eabi
|
|
|
|
LD_PATH=$(APP_ROOT)/ld
|
|
|
|
#echo suspend
|
|
ifeq ("$(VERBOSE)","1")
|
|
V :=
|
|
else
|
|
V := @
|
|
endif
|
|
|
|
# Toolchain commands
|
|
CC := '$(GNU_PREFIX)-gcc'
|
|
AS := '$(GNU_PREFIX)-as'
|
|
AR := '$(GNU_PREFIX)-ar' -r
|
|
LD := '$(GNU_PREFIX)-ld'
|
|
NM := '$(GNU_PREFIX)-nm'
|
|
OBJDUMP := '$(GNU_PREFIX)-objdump'
|
|
OBJCOPY := '$(GNU_PREFIX)-objcopy'
|
|
SIZE := '$(GNU_PREFIX)-size'
|
|
|
|
IPATH_SDK = . \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/errno \
|
|
$(NRF_IOT_SDK_ROOT)/components/softdevice/s1xx_iot/headers \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/common \
|
|
$(NRF_IOT_SDK_ROOT)/components/softdevice/common/softdevice_handler \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/include \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/ble_6lowpan \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/hal \
|
|
$(NRF_IOT_SDK_ROOT)/components/ble/common \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/port \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/fifo \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/trace \
|
|
$(NRF_IOT_SDK_ROOT)/components/device \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/uart \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/rng \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/medium \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/config \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/mem_manager \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/uart \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/ble_ipsp \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/scheduler \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/iot_timer \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/tls/mbedtls/tls/config \
|
|
$(NRF_IOT_SDK_ROOT)/external/mbedtls/include \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/include/netif \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/medium/commissioning \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/tls \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/include \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/pstorage \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/tls \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/context_manager \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot_timer \
|
|
$(NRF_IOT_SDK_ROOT)/components/toolchain/gcc \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/delay \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/medium/ble_ncfgs \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/gpiote \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/mqtt \
|
|
$(NRF_IOT_SDK_ROOT)/components/softdevice/s1xx_iot/headers/nrf52 \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/include/lwip \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/common \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/timer \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/port/arch \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/button \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/util \
|
|
$(NRF_IOT_SDK_ROOT)/examples/bsp \
|
|
$(NRF_IOT_SDK_ROOT)/components/toolchain \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/medium/include \
|
|
|
|
IPATH_RTT = $(APP_ROOT)/rtt/RTT
|
|
|
|
IPATH_APP = $(APP_ROOT) $(APP_ROOT)/config
|
|
|
|
IPATH = . $(IPATH_APP) $(IPATH_RTT) $(IPATH_SDK)
|
|
|
|
SOURCES_NRF_IOT_SDK = \
|
|
$(NRF_IOT_SDK_ROOT)/examples/bsp/bsp.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/button/app_button.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/util/app_error.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/fifo/app_fifo.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/timer/app_timer.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/timer/app_timer_appsh.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/trace/app_trace.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/mem_manager/mem_manager.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/util/nrf_assert.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/uart/retarget.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/def.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/dhcp.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/dhcp6.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/dns.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv4/icmp.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/icmp6.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/inet6.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/inet_chksum.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/init.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv4/ip4.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv4/ip4_addr.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/ip6.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/ip6_addr.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/memp.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/mld6.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/ipv6/nd6.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/netif.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/port/nrf_platform_port.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/pbuf.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/raw.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/sys.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/tcp.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/tcp_in.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/tcp_out.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/timers.c \
|
|
$(NRF_IOT_SDK_ROOT)/external/lwip/src/core/udp.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/libraries/uart/app_uart_fifo.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/delay/nrf_delay.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/common/nrf_drv_common.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/gpiote/nrf_drv_gpiote.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/uart/nrf_drv_uart.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/drivers_nrf/pstorage/pstorage.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/ble/common/ble_advdata.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/ble/common/ble_conn_params.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/ble/common/ble_srv_common.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/errno/errno.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/context_manager/iot_context_manager.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/iot_timer/iot_timer.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/medium/ipv6_medium_ble.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/common/ipv6_parse.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/toolchain/system_nrf52.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/medium/ble_ncfgs/ble_ncfgs.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/iot/medium/commissioning/commissioning.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/softdevice/common/softdevice_handler/softdevice_handler.c \
|
|
$(NRF_IOT_SDK_ROOT)/components/softdevice/common/softdevice_handler/softdevice_handler_appsh.c \
|
|
|
|
SOURCES_RTT = \
|
|
$(APP_ROOT)/rtt/RTT/SEGGER_RTT.c \
|
|
$(APP_ROOT)/rtt/RTT/SEGGER_RTT_printf.c \
|
|
$(APP_ROOT)/rtt/Syscalls/RTT_Syscalls_GCC.c \
|
|
|
|
SOURCES_APP = \
|
|
$(APP_ROOT)/main.c \
|
|
$(APP_ROOT)/bleconfig.c \
|
|
$(MONGOOSE_ROOT)/mongoose.c \
|
|
|
|
SOURCES = $(SOURCES_APP) $(SOURCES_NRF_IOT_SDK) $(SOURCES_RTT)
|
|
|
|
LIBS = $(NRF_IOT_SDK_ROOT)/components/iot/ble_6lowpan/lib/ble_6lowpan.a
|
|
|
|
ASM_SOURCES = $(APP_ROOT)/gcc_startup_nrf52.s
|
|
|
|
LINKER_SCRIPT = $(LD_PATH)/mongoose_example_nrf52.ld
|
|
|
|
C_SOURCE_FILE_NAMES = $(notdir $(SOURCES))
|
|
C_PATHS = $(sort $(dir $(SOURCES) ) )
|
|
ASM_PATHS = $(sort $(dir $(ASM_SOURCES) ))
|
|
C_OBJECTS = $(addprefix $(BUILD_DIR)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
|
|
|
|
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCES))
|
|
ASM_PATHS = $(sort $(dir $(ASM_SOURCES) ))
|
|
ASM_OBJECTS = $(addprefix $(BUILD_DIR)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )
|
|
|
|
INCDIRS = $(addprefix -I,$(IPATH))
|
|
|
|
vpath %.c $(C_PATHS)
|
|
vpath %.s $(ASM_PATHS)
|
|
|
|
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
|
|
|
|
# Mongoose features
|
|
MG_FEATURES_TINY = \
|
|
-DMG_DISABLE_HTTP_DIGEST_AUTH \
|
|
-DMG_DISABLE_MD5 \
|
|
-DMG_DISABLE_HTTP_KEEP_ALIVE \
|
|
-DMG_ENABLE_HTTP_SSI=0 \
|
|
-DMG_ENABLE_HTTP_STREAMING_MULTIPART \
|
|
-DMG_NO_BSD_SOCKETS
|
|
|
|
#flags common to all targets
|
|
CFLAGS = -D__HEAP_SIZE=512
|
|
CFLAGS += -DSWI_DISABLE0
|
|
CFLAGS += -DSOFTDEVICE_PRESENT
|
|
CFLAGS += -DBOARD_PCA10040
|
|
CFLAGS += -DNRF52
|
|
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
|
|
CFLAGS += -DBLE_STACK_SUPPORT_REQD
|
|
CFLAGS += -Ds1xx
|
|
|
|
CFLAGS += -mcpu=cortex-m4
|
|
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
|
|
CFLAGS += -w -g3 -Os
|
|
|
|
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
|
|
|
|
# keep every function in separate section. This will allow linker to dump
|
|
# unused functions
|
|
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
|
|
CFLAGS += -fno-builtin --short-enums
|
|
|
|
CFLAGS += -DCS_ENABLE_STDIO
|
|
#CFLAGS += -DCS_ENABLE_DEBUG
|
|
|
|
# This macro is needed for stdout to be retargeted to either UART or RTT
|
|
CFLAGS += -DENABLE_DEBUG_LOG_SUPPORT
|
|
|
|
# Don't retarget stdout to UART; it'll be retargeted to RTT
|
|
CFLAGS += -DNRF_LOG_USES_RTT
|
|
|
|
# Mongoose flags
|
|
CFLAGS += -DCS_PLATFORM=CS_P_NRF52 $(MG_FEATURES_TINY) -DMG_MODULE_LINES
|
|
|
|
LDFLAGS += -Xlinker -Map=$(OUT_DIR)/$(PROJECT).map
|
|
LDFLAGS += -mthumb -mabi=aapcs -L $(LD_PATH) -T$(LINKER_SCRIPT)
|
|
LDFLAGS += -mcpu=cortex-m4
|
|
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
|
|
# let linker to dump unused sections
|
|
LDFLAGS += -Wl,--gc-sections
|
|
# use newlib in nano version
|
|
LDFLAGS += --specs=nano.specs -lc -lnosys
|
|
|
|
# Assembler flags
|
|
ASMFLAGS += -x assembler-with-cpp
|
|
ASMFLAGS += -D__HEAP_SIZE=512
|
|
ASMFLAGS += -DSWI_DISABLE0
|
|
ASMFLAGS += -DSOFTDEVICE_PRESENT
|
|
ASMFLAGS += -DBOARD_PCA10040
|
|
ASMFLAGS += -DNRF52
|
|
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
|
|
ASMFLAGS += -DENABLE_DEBUG_LOG_SUPPORT
|
|
ASMFLAGS += -DBLE_STACK_SUPPORT_REQD
|
|
ASMFLAGS += -Ds1xx
|
|
ASMFLAGS += -g3
|
|
|
|
INC_PATHS=$(addprefix -I,$(IPATH))
|
|
|
|
BUILD_DIRECTORIES := $(BUILD_DIR) $(OUT_DIR)
|
|
|
|
# Create objects from C SRC files
|
|
$(BUILD_DIR)/%.o: %.c
|
|
@echo Compiling file: $(notdir $<)
|
|
$(V)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<
|
|
|
|
# Assemble files
|
|
$(BUILD_DIR)/%.o: %.s
|
|
@echo Assembly file: $(notdir $<)
|
|
$(V)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $<
|
|
|
|
# Create binary .hex file from the .out file
|
|
%.hex: %.out
|
|
@echo Generating HEX file: $@
|
|
$(V)$(OBJCOPY) -O ihex $< $@
|
|
|
|
OUT_FILENAME=$(OUT_DIR)/$(PROJECT).out
|
|
HEX_FILENAME=$(OUT_DIR)/$(PROJECT).hex
|
|
|
|
all: $(OUT_FILENAME) $(HEX_FILENAME)
|
|
|
|
$(OUT_FILENAME): $(BUILD_DIRECTORIES) $(OBJECTS)
|
|
@echo Linking target: $(OUT_FILENAME)
|
|
$(V)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUT_FILENAME)
|
|
|
|
## Create build directories
|
|
$(BUILD_DIRECTORIES):
|
|
mkdir $@
|
|
|
|
clean:
|
|
rm -rf $(BUILD_DIR) $(OUT_DIR) \
|
|
|
|
# Flash the program
|
|
flash: $(HEX_FILENAME)
|
|
@echo Flashing: $<
|
|
/opt/nordic/nrfjprog/nrfjprog --program $< -f nrf52 --sectorerase
|
|
/opt/nordic/nrfjprog/nrfjprog --reset -f nrf52
|
|
|
|
# start GDB server. It is needed to be done in a separate terminal before we
|
|
# can invoke `gdb` target
|
|
gdbserver:
|
|
/opt/SEGGER/JLink_V610g/JLinkGDBServer -device NRF52 -speed 4000 -if SWD
|
|
|
|
# run GDB (for that to work, `make gdbserver` should run in parallel)
|
|
gdb:
|
|
arm-none-eabi-gdb
|
|
|
|
# start JLinkExe; it is needed to be done in a separate terminal before we
|
|
# can invoke `rtt` target
|
|
jlinkexe:
|
|
/opt/SEGGER/JLink_V610g/JLinkExe -device NRF52 -speed 4000 -if SWD
|
|
|
|
# run RTT client (for that to work, `make jlinkexe` should run in parallel)
|
|
rtt:
|
|
/opt/SEGGER/JLink_V610g/JLinkRTTClient
|