parent
ae0f8749b5
commit
374a63bc0c
@ -1,139 +1,139 @@
|
|||||||
SHELL=/bin/bash
|
SHELL=/bin/bash
|
||||||
|
|
||||||
.PHONY: all build build-container cmake format format-linux flash-stlink flash-jlink format-container shell image build-container clean clean-image clean-all
|
.PHONY: all build build-container cmake format format-linux flash-stlink flash-jlink format-container shell image build-container clean clean-image clean-all
|
||||||
############################### Native Makefile ###############################
|
############################### Native Makefile ###############################
|
||||||
|
|
||||||
PROJECT_NAME ?= Probe
|
PROJECT_NAME ?= Probe
|
||||||
BUILD_DIR ?= build
|
BUILD_DIR ?= build
|
||||||
FIRMWARE := $(BUILD_DIR)/$(PROJECT_NAME).bin
|
FIRMWARE := $(BUILD_DIR)/$(PROJECT_NAME).bin
|
||||||
BUILD_TYPE ?= Debug
|
BUILD_TYPE ?= Debug
|
||||||
PLATFORM = $(if $(OS),$(OS),$(shell uname -s))
|
PLATFORM = $(if $(OS),$(OS),$(shell uname -s))
|
||||||
|
|
||||||
ifeq ($(PLATFORM),Windows_NT)
|
ifeq ($(PLATFORM),Windows_NT)
|
||||||
BUILD_SYSTEM ?= MinGW Makefiles
|
BUILD_SYSTEM ?= MinGW Makefiles
|
||||||
else
|
else
|
||||||
ifeq ($(PLATFORM),Linux)
|
ifeq ($(PLATFORM),Linux)
|
||||||
BUILD_SYSTEM ?= Unix Makefiles
|
BUILD_SYSTEM ?= Unix Makefiles
|
||||||
else
|
else
|
||||||
@echo "Unsuported platform"
|
@echo "Unsuported platform"
|
||||||
exit 1
|
exit 1
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: build
|
all: build
|
||||||
|
|
||||||
build: cmake
|
build: cmake
|
||||||
$(MAKE) -C $(BUILD_DIR) --no-print-directory
|
$(MAKE) -C $(BUILD_DIR) --no-print-directory
|
||||||
|
|
||||||
cmake: $(BUILD_DIR)/Makefile
|
cmake: $(BUILD_DIR)/Makefile
|
||||||
|
|
||||||
$(BUILD_DIR)/Makefile: CMakeLists.txt
|
$(BUILD_DIR)/Makefile: CMakeLists.txt
|
||||||
cmake \
|
cmake \
|
||||||
-G "$(BUILD_SYSTEM)" \
|
-G "$(BUILD_SYSTEM)" \
|
||||||
-B$(BUILD_DIR) \
|
-B$(BUILD_DIR) \
|
||||||
-DPROJECT_NAME=$(PROJECT_NAME) \
|
-DPROJECT_NAME=$(PROJECT_NAME) \
|
||||||
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
|
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
|
||||||
-DDUMP_ASM=OFF
|
-DDUMP_ASM=OFF
|
||||||
|
|
||||||
# Formats all user modified source files (add ones that are missing)
|
# Formats all user modified source files (add ones that are missing)
|
||||||
# SRCS := $(shell find Project -name '*.[ch]' -or -name '*.[ch]pp') Core/Src/main.c
|
# SRCS := $(shell find Project -name '*.[ch]' -or -name '*.[ch]pp') Core/Src/main.c
|
||||||
SRCS := $(shell find Core -name '*.[ch]' -or -name '*.[ch]pp') Core/Src/main.c
|
SRCS := $(shell find Core -name '*.[ch]' -or -name '*.[ch]pp') Core/Src/main.c
|
||||||
format: $(addsuffix .format,$(SRCS))
|
format: $(addsuffix .format,$(SRCS))
|
||||||
%.format: %
|
%.format: %
|
||||||
clang-format -i $<
|
clang-format -i $<
|
||||||
|
|
||||||
# Formats all CubeMX generated sources to unix style - removes \r from line endings
|
# Formats all CubeMX generated sources to unix style - removes \r from line endings
|
||||||
# Add any new directories, like Middlewares and hidden files
|
# Add any new directories, like Middlewares and hidden files
|
||||||
HIDDEN_FILES := .mxproject .project .cproject
|
HIDDEN_FILES := .mxproject .project .cproject
|
||||||
FOUND_HIDDEN_FILES := $(shell for f in $(HIDDEN_FILES);do if [[ -e $$f ]]; then echo $$f;fi; done)
|
FOUND_HIDDEN_FILES := $(shell for f in $(HIDDEN_FILES);do if [[ -e $$f ]]; then echo $$f;fi; done)
|
||||||
FORMAT_LINUX := $(shell find Core Drivers -name '*' -type f; find . -name '*.ioc') $(FOUND_HIDDEN_FILES)
|
FORMAT_LINUX := $(shell find Core Drivers -name '*' -type f; find . -name '*.ioc') $(FOUND_HIDDEN_FILES)
|
||||||
|
|
||||||
format-linux: $(addsuffix .format-linux,$(FORMAT_LINUX))
|
format-linux: $(addsuffix .format-linux,$(FORMAT_LINUX))
|
||||||
%.format-linux: %
|
%.format-linux: %
|
||||||
$(if $(filter $(PLATFORM),Linux),dos2unix -q $<,)
|
$(if $(filter $(PLATFORM),Linux),dos2unix -q $<,)
|
||||||
|
|
||||||
# Device specific!
|
# Device specific!
|
||||||
DEVICE ?= STM32F407VG
|
DEVICE ?= STM32F407VG
|
||||||
|
|
||||||
flash-st: build
|
flash-st: build
|
||||||
st-flash --reset write $(FIRMWARE) 0x08000000
|
st-flash --reset write $(FIRMWARE) 0x08000000
|
||||||
|
|
||||||
$(BUILD_DIR)/jlink-script:
|
$(BUILD_DIR)/jlink-script:
|
||||||
touch $@
|
touch $@
|
||||||
@echo device $(DEVICE) > $@
|
@echo device $(DEVICE) > $@
|
||||||
@echo si 1 >> $@
|
@echo si 1 >> $@
|
||||||
@echo speed 4000 >> $@
|
@echo speed 4000 >> $@
|
||||||
@echo loadfile $(FIRMWARE),0x08000000 >> $@
|
@echo loadfile $(FIRMWARE),0x08000000 >> $@
|
||||||
@echo -e "r\ng\nqc" >> $@
|
@echo -e "r\ng\nqc" >> $@
|
||||||
|
|
||||||
flash-jlink: build | $(BUILD_DIR)/jlink-script
|
flash-jlink: build | $(BUILD_DIR)/jlink-script
|
||||||
JLinkExe -commanderScript $(BUILD_DIR)/jlink-script
|
JLinkExe -commanderScript $(BUILD_DIR)/jlink-script
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(BUILD_DIR)
|
rm -rf $(BUILD_DIR)
|
||||||
|
|
||||||
################################## Container ##################################
|
################################## Container ##################################
|
||||||
|
|
||||||
UID ?= $(shell id -u)
|
UID ?= $(shell id -u)
|
||||||
GID ?= $(shell id -g)
|
GID ?= $(shell id -g)
|
||||||
USER ?= $(shell id -un)
|
USER ?= $(shell id -un)
|
||||||
GROUP ?= $(if $(filter $(PLATFORM), Windows_NT),$(shell id -un),$(shell id -gn))
|
GROUP ?= $(if $(filter $(PLATFORM), Windows_NT),$(shell id -un),$(shell id -gn))
|
||||||
|
|
||||||
ifeq ($(PLATFORM),Windows_NT)
|
ifeq ($(PLATFORM),Windows_NT)
|
||||||
WIN_PREFIX = winpty
|
WIN_PREFIX = winpty
|
||||||
WORKDIR_PATH = "//workdir"
|
WORKDIR_PATH = "//workdir"
|
||||||
WORKDIR_VOLUME = "/$$(pwd -W):/workdir"
|
WORKDIR_VOLUME = "/$$(pwd -W):/workdir"
|
||||||
else
|
else
|
||||||
WORKDIR_PATH = /workdir
|
WORKDIR_PATH = /workdir
|
||||||
WORKDIR_VOLUME = "$$(pwd):/workdir"
|
WORKDIR_VOLUME = "$$(pwd):/workdir"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CONTAINER_TOOL ?= docker
|
CONTAINER_TOOL ?= docker
|
||||||
CONTAINER_FILE := Dockerfile
|
CONTAINER_FILE := Dockerfile
|
||||||
IMAGE_NAME := fedora-arm-embedded-dev
|
IMAGE_NAME := fedora-arm-embedded-dev
|
||||||
CONTAINER_NAME := fedora-arm-embedded-dev
|
CONTAINER_NAME := fedora-arm-embedded-dev
|
||||||
|
|
||||||
NEED_IMAGE = $(shell $(CONTAINER_TOOL) image inspect $(IMAGE_NAME) 2> /dev/null > /dev/null || echo image)
|
NEED_IMAGE = $(shell $(CONTAINER_TOOL) image inspect $(IMAGE_NAME) 2> /dev/null > /dev/null || echo image)
|
||||||
# usefull if you have a always running container in the background: NEED_CONTAINER = $(shell $(CONTAINER_TOOL) container inspect $(CONTAINER_NAME) 2> /dev/null > /dev/null || echo container)
|
# usefull if you have a always running container in the background: NEED_CONTAINER = $(shell $(CONTAINER_TOOL) container inspect $(CONTAINER_NAME) 2> /dev/null > /dev/null || echo container)
|
||||||
PODMAN_ARG = $(if $(filter $(CONTAINER_TOOL), podman),--userns=keep-id,)
|
PODMAN_ARG = $(if $(filter $(CONTAINER_TOOL), podman),--userns=keep-id,)
|
||||||
CONTAINER_RUN = $(WIN_PREFIX) $(CONTAINER_TOOL) run \
|
CONTAINER_RUN = $(WIN_PREFIX) $(CONTAINER_TOOL) run \
|
||||||
--name $(CONTAINER_NAME) \
|
--name $(CONTAINER_NAME) \
|
||||||
--rm \
|
--rm \
|
||||||
-it \
|
-it \
|
||||||
$(PODMAN_ARG) \
|
$(PODMAN_ARG) \
|
||||||
-v $(WORKDIR_VOLUME) \
|
-v $(WORKDIR_VOLUME) \
|
||||||
-w $(WORKDIR_PATH) \
|
-w $(WORKDIR_PATH) \
|
||||||
--security-opt label=disable \
|
--security-opt label=disable \
|
||||||
--hostname $(CONTAINER_NAME) \
|
--hostname $(CONTAINER_NAME) \
|
||||||
$(IMAGE_NAME)
|
$(IMAGE_NAME)
|
||||||
|
|
||||||
build-container: $(NEED_IMAGE)
|
build-container: $(NEED_IMAGE)
|
||||||
$(CONTAINER_RUN) bash -lc 'make -j$(shell nproc)'
|
$(CONTAINER_RUN) bash -lc 'make -j$(shell nproc)'
|
||||||
|
|
||||||
format-container:
|
format-container:
|
||||||
$(CONTAINER_RUN) bash -lc 'make format -j$(shell nproc)'
|
$(CONTAINER_RUN) bash -lc 'make format -j$(shell nproc)'
|
||||||
|
|
||||||
format-linux-container:
|
format-linux-container:
|
||||||
$(CONTAINER_RUN) bash -lc 'make format-linux'
|
$(CONTAINER_RUN) bash -lc 'make format-linux'
|
||||||
|
|
||||||
shell:
|
shell:
|
||||||
$(CONTAINER_RUN) bash -l
|
$(CONTAINER_RUN) bash -l
|
||||||
|
|
||||||
image: $(CONTAINER_FILE)
|
image: $(CONTAINER_FILE)
|
||||||
$(CONTAINER_TOOL) build \
|
$(CONTAINER_TOOL) build \
|
||||||
-t $(IMAGE_NAME) \
|
-t $(IMAGE_NAME) \
|
||||||
-f=$(CONTAINER_FILE) \
|
-f=$(CONTAINER_FILE) \
|
||||||
--build-arg UID=$(UID) \
|
--build-arg UID=$(UID) \
|
||||||
--build-arg GID=$(GID) \
|
--build-arg GID=$(GID) \
|
||||||
--build-arg USERNAME=$(USER) \
|
--build-arg USERNAME=$(USER) \
|
||||||
--build-arg GROUPNAME=$(GROUP) \
|
--build-arg GROUPNAME=$(GROUP) \
|
||||||
.
|
.
|
||||||
|
|
||||||
clean-image:
|
clean-image:
|
||||||
$(CONTAINER_TOOL) container rm -f $(CONTAINER_NAME) 2> /dev/null > /dev/null || true
|
$(CONTAINER_TOOL) container rm -f $(CONTAINER_NAME) 2> /dev/null > /dev/null || true
|
||||||
$(CONTAINER_TOOL) image rmi -f $(IMAGE_NAME) 2> /dev/null > /dev/null || true
|
$(CONTAINER_TOOL) image rmi -f $(IMAGE_NAME) 2> /dev/null > /dev/null || true
|
||||||
|
|
||||||
clean-all: clean clean-image
|
clean-all: clean clean-image
|
||||||
|
|
||||||
flash:
|
flash:
|
||||||
openocd -f interface/stlink.cfg -f target/stm32l4x.cfg -c "program build/Probe.bin verify reset exit 0x08000000"
|
openocd -f interface/stlink.cfg -f target/stm32l4x.cfg -c "program build/Probe.bin verify reset exit 0x08000000"
|
||||||
|
Loading…
Reference in new issue