Skip to content

Commit

Permalink
TODO Add Makefile
Browse files Browse the repository at this point in the history
TODO
Add run instructions to README
- Include compile and flash targets
  • Loading branch information
jrvollmer committed Oct 28, 2023
1 parent b705efa commit 0d2ab74
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Allow the user to specify different values for 'PROFILE' and 'TOOLCHAIN'
PROFILE?=develop
TOOLCHAIN?=GCC_ARM

# Parse setup.yml to determine the build target
TARGET := $(shell grep -Po '(^\s+target:\s+)\K.+' setup.yml)
# Check that a value for 'target' was found in setup.yml
ifndef TARGET
$(error Did not find a value for 'target' in setup.yml)
endif
BUILD_DIR := cmake_build/$(TARGET)/$(PROFILE)/$(TOOLCHAIN)
BINARY := embedded-mbed.bin
# Search for files matching *.{cpp,h}, but don't search mbed-os/ or cmake_build/
SOURCES := $(shell find . -type d \( -path ./mbed-os -o -path ./cmake_build \) -prune -o -type f -regex '.*\.\(cpp\|h\)' -print)


.PHONY: flash
flash: mountpoint compile
cp $(BUILD_DIR)/$(BINARY) $(MOUNTPOINT)

.PHONY: compile
compile: $(BUILD_DIR)/$(BINARY)

$(BUILD_DIR)/$(BINARY): $(BUILD_DIR)/mbed_config.cmake setup.yml tests.yml CMakeLists.txt parseConfigs.py $(SOURCES)
./parseConfigs.py
cmake -S . -B $(BUILD_DIR) -GNinja
cmake --build $(BUILD_DIR)

.PHONY: configure
configure: $(BUILD_DIR)/mbed_config.cmake

$(BUILD_DIR)/mbed_config.cmake: mbed-os mbed_app.json
mbed-tools configure -t $(TOOLCHAIN) -m $(TARGET)

.PHONY: deploy
deploy: mbed-os

mbed-os: mbed-os.lib
mbed-tools deploy

# Check that MOUNTPOINT was defined as a CLA
.PHONY: mountpoint
mountpoint:
ifndef MOUNTPOINT
$(error variable 'MOUNTPOINT' not set)
endif

.PHONY: clean
clean:
rm -rf cmake_build/ mbed-os/ definitions.h

0 comments on commit 0d2ab74

Please sign in to comment.