From 95b4ad119d6c205825ef74acd1ef74981674099d Mon Sep 17 00:00:00 2001
From: Daniel Friesel <derf@finalrewind.org>
Date: Fri, 12 Oct 2018 14:35:37 +0200
Subject: [PATCH] Makefiles: quiet mode, optional info output

---
 Makefile                               | 10 ++++++++-
 src/arch/arduino-nano-168/Makefile.inc | 31 +++++++++++++-------------
 src/arch/arduino-nano/Makefile.inc     | 23 ++++++++++++-------
 src/arch/blinkenrocket/Makefile.inc    |  7 +++++-
 src/arch/esp8266/Makefile.inc          |  4 +++-
 src/arch/msp430fr5969lp/Makefile.inc   | 31 ++++++++++++++++++--------
 src/arch/posix/Makefile.inc            |  4 +++-
 7 files changed, 73 insertions(+), 37 deletions(-)

diff --git a/Makefile b/Makefile
index 224b71f..baf00b5 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,12 @@ CXXFLAGS = -std=c++14
 
 TARGETS = src/app/${app}/main.cc src/os/object/cpp_helpers.cc src/os/object/outputstream.cc
 
+QUIET = @
+
+ifneq (${verbose}, )
+	QUIET =
+endif
+
 include src/app/${app}/Makefile.inc
 
 ifneq ($(findstring lm75,${drivers}), )
@@ -118,4 +124,6 @@ help: arch_help
 	@echo "Global architectures:"
 	@echo "    $(shell ls src/arch)"
 
-.PHONY: clean help
+info: arch_info
+
+.PHONY: clean help info
diff --git a/src/arch/arduino-nano-168/Makefile.inc b/src/arch/arduino-nano-168/Makefile.inc
index de4ac8b..534ac27 100644
--- a/src/arch/arduino-nano-168/Makefile.inc
+++ b/src/arch/arduino-nano-168/Makefile.inc
@@ -4,6 +4,8 @@ MCU = atmega168
 PORT = /dev/ttyUSB0
 BAUD = 19200
 
+cpu_freq ?= 16000000
+
 COMMON_FLAGS += -Werror=overflow
 COMMON_FLAGS += -mmcu=${MCU} -DF_CPU=16000000UL -DMULTIPASS_ARCH_arduino_nano
 COMMON_FLAGS += -flto
@@ -37,38 +39,35 @@ ifneq ($(findstring timer,${arch_drivers}), )
 	TARGETS += src/arch/arduino-nano/driver/timer.cc
 endif
 
-ifneq (${i2c_freq}, )
-	COMMON_FLAGS += -DF_I2C=${i2c_freq}
-endif
-
-ifneq (${timer_freq}, )
-	COMMON_FLAGS += -DF_TIMER=${timer_freq}
-endif
-
 OBJECTS = ${TARGETS:.cc=.o}
 
 .cc.o:
-	${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}
+	${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}
 
 build/system.elf: ${OBJECTS}
-	${CXX} ${COMMON_FLAGS} ${CXXFLAGS} -Wl,--gc-sections -o $@ ${OBJECTS}
-	avr-size --format=avr --mcu=${MCU} $@
+	${QUIET}${CXX} ${COMMON_FLAGS} ${CXXFLAGS} -Wl,--gc-sections -o $@ ${OBJECTS}
+	${QUIET}avr-size --format=avr --mcu=${MCU} $@
 
 build/system.hex: build/system.elf
-	${OBJCOPY} -O ihex ${@:.hex=.elf} $@
+	${QUIET}${OBJCOPY} -O ihex ${@:.hex=.elf} $@
 
 program: build/system.hex
-	avrdude -p ${MCU} -c arduino -P ${PORT} -b ${BAUD} -U flash:w:build/system.hex
+	${QUIET}avrdude -p ${MCU} -c arduino -P ${PORT} -b ${BAUD} -U flash:w:build/system.hex
 
 arch_clean:
-	rm -f ${OBJECTS} build/system.hex
+	${QUIET}rm -f ${OBJECTS} build/system.hex
 
 monitor:
-	screen ${PORT} 115200
+	${QUIET}screen ${PORT} 115200
 
 arch_help:
 	@echo "arduino-nano specific flags:"
 	@echo "    PORT = ${PORT}"
 	@echo "    BAUD = ${BAUD} (only used for programming)"
 
-.PHONY: arch_clean arch_help monitor program
+arch_info:
+	@echo "CPU   Freq: ${cpu_freq} Hz"
+	@echo "Timer Freq: ${timer_freq} Hz"
+	@echo "I2C   Freq: ${i2c_freq} Hz"
+
+.PHONY: arch_clean arch_help arch_info monitor program
diff --git a/src/arch/arduino-nano/Makefile.inc b/src/arch/arduino-nano/Makefile.inc
index 6dbd95e..bb51b6c 100644
--- a/src/arch/arduino-nano/Makefile.inc
+++ b/src/arch/arduino-nano/Makefile.inc
@@ -4,6 +4,8 @@ MCU = atmega328p
 PORT = /dev/ttyUSB0
 BAUD = 57600
 
+cpu_freq ?= 16000000
+
 COMMON_FLAGS += -Werror=overflow
 COMMON_FLAGS += -mmcu=${MCU} -DF_CPU=16000000UL -DMULTIPASS_ARCH_arduino_nano
 COMMON_FLAGS += -flto
@@ -40,27 +42,32 @@ endif
 OBJECTS = ${TARGETS:.cc=.o}
 
 .cc.o:
-	${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}
+	${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}
 
 build/system.elf: ${OBJECTS}
-	${CXX} ${COMMON_FLAGS} ${CXXFLAGS} -Wl,--gc-sections -o $@ ${OBJECTS}
-	avr-size --format=avr --mcu=${MCU} $@
+	${QUIET}${CXX} ${COMMON_FLAGS} ${CXXFLAGS} -Wl,--gc-sections -o $@ ${OBJECTS}
+	${QUIET}avr-size --format=avr --mcu=${MCU} $@
 
 build/system.hex: build/system.elf
-	${OBJCOPY} -O ihex ${@:.hex=.elf} $@
+	${QUIET}${OBJCOPY} -O ihex ${@:.hex=.elf} $@
 
 program: build/system.hex
-	avrdude -p ${MCU} -c arduino -P ${PORT} -b ${BAUD} -U flash:w:build/system.hex
+	${QUIET}avrdude -p ${MCU} -c arduino -P ${PORT} -b ${BAUD} -U flash:w:build/system.hex
 
 arch_clean:
-	rm -f ${OBJECTS} build/system.hex
+	${QUIET}rm -f ${OBJECTS} build/system.hex
 
 monitor:
-	screen ${PORT} 115200
+	${QUIET}screen ${PORT} 115200
 
 arch_help:
 	@echo "arduino-nano specific flags:"
 	@echo "    PORT = ${PORT}"
 	@echo "    BAUD = ${BAUD} (only used for programming)"
 
-.PHONY: arch_clean arch_help monitor program
+arch_info:
+	@echo "CPU   Freq: ${cpu_freq} Hz"
+	@echo "Timer Freq: ${timer_freq} Hz"
+	@echo "I2C   Freq: ${i2c_freq} Hz"
+
+.PHONY: arch_clean arch_help arch_info monitor program
diff --git a/src/arch/blinkenrocket/Makefile.inc b/src/arch/blinkenrocket/Makefile.inc
index 1d99d0b..1d596fd 100644
--- a/src/arch/blinkenrocket/Makefile.inc
+++ b/src/arch/blinkenrocket/Makefile.inc
@@ -52,4 +52,9 @@ arch_help:
 	@echo "blinkenrocket specific flags:"
 	@echo "    PORT = ${PORT}"
 
-.PHONY: arch_clean arch_help monitor program
+arch_info:
+	@echo "CPU   Freq: ${cpu_freq} Hz"
+	@echo "Timer Freq: ${timer_freq} Hz"
+	@echo "I2C   Freq: ${i2c_freq} Hz"
+
+.PHONY: arch_clean arch_help arch_info monitor program
diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc
index 8deaa95..71ac350 100644
--- a/src/arch/esp8266/Makefile.inc
+++ b/src/arch/esp8266/Makefile.inc
@@ -65,4 +65,6 @@ arch_help:
 	@echo "esp8266 specific flags:"
 	@echo "    - none -"
 
-.PHONY: arch_clean arch_help monitor program
+arch_info:
+
+.PHONY: arch_clean arch_help arch_info monitor program
diff --git a/src/arch/msp430fr5969lp/Makefile.inc b/src/arch/msp430fr5969lp/Makefile.inc
index 037c9cd..2eb9dc9 100644
--- a/src/arch/msp430fr5969lp/Makefile.inc
+++ b/src/arch/msp430fr5969lp/Makefile.inc
@@ -3,9 +3,10 @@
 CPU = 430x
 MCU = msp430fr5969
 
+cpu_freq ?= 16000000
+
 INCLUDES += -I/opt/msp430/ti/gcc/include
 COMMON_FLAGS += -mcpu=${CPU} -mmcu=${MCU} -DMULTIPASS_ARCH_msp430fr5969lp
-COMMON_FLAGS += -DF_CPU=16000000UL
 COMMON_FLAGS += -DMULTIPASS_ARCH_HAS_I2C
 
 CC = /opt/msp430/ti/gcc/bin/msp430-elf-gcc
@@ -47,33 +48,45 @@ ifneq ($(findstring timer,${arch_drivers}), )
 	TARGETS += src/arch/msp430fr5969lp/driver/timer.cc
 endif
 
+ifneq (${cpu_freq}, )
+	COMMON_FLAGS += -DF_CPU=${cpu_freq}UL
+else
+	COMMON_FLAGS += -DF_CPU=16000000UL
+endif
+
+
 OBJECTS = ${TARGETS:.cc=.o}
 
 .cc.o:
-	${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}
+	${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}
 
 build/system.elf: ${OBJECTS}
-	${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} \
+	${QUIET}${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} \
 		-Wl,--library-path=/opt/msp430/ti/gcc/include/ \
 		-flto -o $@ ${OBJECTS}
 
 build/system.hex: build/system.elf
-	${OBJCOPY} -O ihex ${@:.hex=.elf} $@
+	${QUIET}${OBJCOPY} -O ihex ${@:.hex=.elf} $@
 
 program: build/system.hex
-	LD_LIBRARY_PATH=/home/derf/var/projects/msp430/MSP430Flasher_1.3.7 \
+	${QUIET}LD_LIBRARY_PATH=/home/derf/var/projects/msp430/MSP430Flasher_1.3.7 \
 	/home/derf/var/projects/msp430/MSP430Flasher_1.3.7/MSP430Flasher \
 	-w build/system.hex -v -g -z '[VCC]'
 
 arch_clean:
-	rm -f ${OBJECTS}
-	rm -f build/system.hex
+	${QUIET}rm -f ${OBJECTS}
+	${QUIET}rm -f build/system.hex
 
 monitor:
-	screen /dev/ttyACM1 115200
+	${QUIET}screen /dev/ttyACM1 115200
 
 arch_help:
 	@echo "msp430fR5969lp specific flags:"
 	@echo "    - none -"
 
-.PHONY: arch_clean arch_help monitor program
+arch_info:
+	@echo "CPU   Freq: ${cpu_freq} Hz"
+	@echo "Timer Freq: ${timer_freq} Hz"
+	@echo "I2C   Freq: ${i2c_freq} Hz"
+
+.PHONY: arch_clean arch_help arch_info monitor program
diff --git a/src/arch/posix/Makefile.inc b/src/arch/posix/Makefile.inc
index cb4b46f..9e27b3e 100644
--- a/src/arch/posix/Makefile.inc
+++ b/src/arch/posix/Makefile.inc
@@ -35,4 +35,6 @@ arch_help:
 	@echo "posix specific flags:"
 	@echo "    - none -"
 
-.PHONY: arch_clean arch_help monitor program run
+arch_info:
+
+.PHONY: arch_clean arch_help arch_info monitor program run
-- 
GitLab