summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Hahn <George.Hahn.VHS@gmail.com>2022-05-29 20:30:02 -0600
committerGitHub <noreply@github.com>2022-05-29 22:30:02 -0400
commita4fc6204ce27a4fcce071515ee9e5757818b4af5 (patch)
treea3549820fdb7a9c7345883519c36f4b59b986dad
parent6ed757af2b7778e6944a5a8761672bc8d03620e2 (diff)
downloadSensor-Watch-a4fc6204ce27a4fcce071515ee9e5757818b4af5.tar.gz
Sensor-Watch-a4fc6204ce27a4fcce071515ee9e5757818b4af5.tar.bz2
Sensor-Watch-a4fc6204ce27a4fcce071515ee9e5757818b4af5.zip
Parallelize alternate fw builds (#66)
-rw-r--r--make.mk26
-rw-r--r--rules.mk11
2 files changed, 33 insertions, 4 deletions
diff --git a/make.mk b/make.mk
index ac5be775..d8e2bf8a 100644
--- a/make.mk
+++ b/make.mk
@@ -9,12 +9,38 @@ endif
##############################################################################
.PHONY: all directory clean size
+# OS detection, adapted from https://gist.github.com/sighingnow/deee806603ec9274fd47
+DETECTED_OS :=
+ifeq ($(OS),Windows_NT)
+ DETECTED_OS = WINDOWS
+else
+ UNAME_S := $(shell uname -s)
+ ifeq ($(UNAME_S),Linux)
+ DETECTED_OS = LINUX
+ endif
+ ifeq ($(UNAME_S),Darwin)
+ DETECTED_OS = OSX
+ endif
+endif
+$(if ${VERBOSE},$(info OS detected: $(DETECTED_OS)))
+
ifeq ($(OS), Windows_NT)
MKDIR = gmkdir
else
MKDIR = mkdir
endif
+ifeq ($(DETECTED_OS), LINUX)
+ MAKEFLAGS += -j `nproc`
+endif
+ifeq ($(DETECTED_OS), OSX)
+ NPROCS = $(shell sysctl hw.ncpu | grep -o '[0-9]\+')
+ MAKEFLAGS += -j $(NPROCS)
+endif
+ifeq ($(DETECTED_OS), WINDOWS)
+ MAKEFLAGS += -j $(NUMBER_OF_PROCESSORS)
+endif
+
ifndef EMSCRIPTEN
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
diff --git a/rules.mk b/rules.mk
index 2f2f3922..8de3fc1e 100644
--- a/rules.mk
+++ b/rules.mk
@@ -7,9 +7,9 @@ SUBMODULES = tinyusb
COBRA = cobra -f
ifndef EMSCRIPTEN
-all: directory $(SUBMODULES) $(BUILD)/$(BIN).elf $(BUILD)/$(BIN).hex $(BUILD)/$(BIN).bin $(BUILD)/$(BIN).uf2 size
+all: $(BUILD)/$(BIN).elf $(BUILD)/$(BIN).hex $(BUILD)/$(BIN).bin $(BUILD)/$(BIN).uf2 size
else
-all: directory $(SUBMODULES) $(BUILD)/$(BIN).html
+all: $(BUILD)/$(BIN).html
endif
$(BUILD)/$(BIN).html: $(OBJS)
@@ -35,13 +35,14 @@ $(BUILD)/$(BIN).uf2: $(BUILD)/$(BIN).bin
@echo UF2CONV $@
@$(UF2) $^ -co $@
+.phony: $(SUBMODULES)
$(SUBMODULES):
git submodule update --init
install:
@$(UF2) -D $(BUILD)/$(BIN).uf2
-%.o:
+$(BUILD)/%.o: | $(SUBMODULES) directory
@echo CC $@
@$(CC) $(CFLAGS) $(filter %/$(subst .o,.c,$(notdir $@)), $(SRCS)) -c -o $@
@@ -59,4 +60,6 @@ clean:
analyze:
@$(COBRA) basic $(INCLUDES) $(DEFINES) $(SRCS)
--include $(wildcard $(BUILD)/*.d)
+DEPFILES := $(SRCS:%.c=$(BUILD)/%.d)
+
+-include $(wildcard $(DEPFILES))