From db4fe082e8bb6c29982f5cfca0be5722b0d937d3 Mon Sep 17 00:00:00 2001 From: Erwan Martin Date: Tue, 21 Apr 2020 12:40:25 +0200 Subject: [PATCH 1/4] Use /bin/sh instead of /bin/bash to support systems that do not have bash. --- test.sh | 2 +- tests/rtlwmbus_water.sh | 2 +- tests/test_additional_json.sh | 2 +- tests/test_aes.sh | 2 +- tests/test_apas.sh | 2 +- tests/test_c1_meters.sh | 2 +- tests/test_config1.sh | 2 +- tests/test_config4.sh | 2 +- tests/test_conversions.sh | 2 +- tests/test_elements.sh | 2 +- tests/test_linkmodes.sh | 2 +- tests/test_listen_to_all.sh | 2 +- tests/test_logfile.sh | 2 +- tests/test_meterfiles.sh | 2 +- tests/test_multiple_ids.sh | 2 +- tests/test_oneshot.sh | 2 +- tests/test_rtlwmbus.sh | 2 +- tests/test_serial_bads.sh | 2 +- tests/test_shell.sh | 2 +- tests/test_shell2.sh | 2 +- tests/test_stdin_and_file.sh | 2 +- tests/test_t1_meters.sh | 2 +- tests/test_wrongkeys.sh | 2 +- 23 files changed, 23 insertions(+), 23 deletions(-) diff --git a/test.sh b/test.sh index 6588c6b..c892763 100755 --- a/test.sh +++ b/test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" TESTINTERNAL=$(dirname $PROG)/testinternals diff --git a/tests/rtlwmbus_water.sh b/tests/rtlwmbus_water.sh index 6020539..aee68c2 100755 --- a/tests/rtlwmbus_water.sh +++ b/tests/rtlwmbus_water.sh @@ -1,3 +1,3 @@ -#!/bin/bash +#!/bin/sh echo "T1;1;1;2019-04-03 19:00:42.000;97;148;88888888;0x6e4401068888888805077a85006085bc2630713819512eb4cd87fba554fb43f67cf9654a68ee8e194088160df752e716238292e8af1ac20986202ee561d743602466915e42f1105d9c6782a54504e4f099e65a7656b930c73a30775122d2fdf074b5035cfaa7e0050bf32faae03a77" #{"media":"water","meter":"apator162","name":"ApWater","id":"88888888","total_m3":4.848,"timestamp":"1111-11-11T11:11:11Z"} diff --git a/tests/test_additional_json.sh b/tests/test_additional_json.sh index 2eff00b..f90d7ff 100755 --- a/tests/test_additional_json.sh +++ b/tests/test_additional_json.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" TEST=testoutput diff --git a/tests/test_aes.sh b/tests/test_aes.sh index 4b41274..d872bab 100755 --- a/tests/test_aes.sh +++ b/tests/test_aes.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_apas.sh b/tests/test_apas.sh index f5c7413..a3c67ac 100755 --- a/tests/test_apas.sh +++ b/tests/test_apas.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_c1_meters.sh b/tests/test_c1_meters.sh index 253a411..13cd1f6 100755 --- a/tests/test_c1_meters.sh +++ b/tests/test_c1_meters.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_config1.sh b/tests/test_config1.sh index 6dcafcd..439bbc2 100755 --- a/tests/test_config1.sh +++ b/tests/test_config1.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" TEST=testoutput diff --git a/tests/test_config4.sh b/tests/test_config4.sh index f08226a..5101622 100755 --- a/tests/test_config4.sh +++ b/tests/test_config4.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" TEST=testoutput diff --git a/tests/test_conversions.sh b/tests/test_conversions.sh index 6b6b23b..10b2b9f 100755 --- a/tests/test_conversions.sh +++ b/tests/test_conversions.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_elements.sh b/tests/test_elements.sh index b5cfcdc..78208a2 100755 --- a/tests/test_elements.sh +++ b/tests/test_elements.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" TEST=testoutput diff --git a/tests/test_linkmodes.sh b/tests/test_linkmodes.sh index 38544ad..d5de8ed 100755 --- a/tests/test_linkmodes.sh +++ b/tests/test_linkmodes.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_listen_to_all.sh b/tests/test_listen_to_all.sh index 89c45bb..39d4d1b 100755 --- a/tests/test_listen_to_all.sh +++ b/tests/test_listen_to_all.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_logfile.sh b/tests/test_logfile.sh index b16beeb..92ad211 100755 --- a/tests/test_logfile.sh +++ b/tests/test_logfile.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" TEST=testoutput diff --git a/tests/test_meterfiles.sh b/tests/test_meterfiles.sh index 8d0ea78..3920493 100755 --- a/tests/test_meterfiles.sh +++ b/tests/test_meterfiles.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_multiple_ids.sh b/tests/test_multiple_ids.sh index 9955ce8..46d37c1 100755 --- a/tests/test_multiple_ids.sh +++ b/tests/test_multiple_ids.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_oneshot.sh b/tests/test_oneshot.sh index f29dbd7..93c4574 100755 --- a/tests/test_oneshot.sh +++ b/tests/test_oneshot.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_rtlwmbus.sh b/tests/test_rtlwmbus.sh index dc6b721..f76981f 100755 --- a/tests/test_rtlwmbus.sh +++ b/tests/test_rtlwmbus.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_serial_bads.sh b/tests/test_serial_bads.sh index c725d5c..4d6cc78 100755 --- a/tests/test_serial_bads.sh +++ b/tests/test_serial_bads.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_shell.sh b/tests/test_shell.sh index 0c739e9..5798e56 100755 --- a/tests/test_shell.sh +++ b/tests/test_shell.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_shell2.sh b/tests/test_shell2.sh index e9a8dcc..2caa8d5 100755 --- a/tests/test_shell2.sh +++ b/tests/test_shell2.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" TEST=testoutput diff --git a/tests/test_stdin_and_file.sh b/tests/test_stdin_and_file.sh index c75d776..a1de107 100755 --- a/tests/test_stdin_and_file.sh +++ b/tests/test_stdin_and_file.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_t1_meters.sh b/tests/test_t1_meters.sh index 1d491bc..1b97bd2 100755 --- a/tests/test_t1_meters.sh +++ b/tests/test_t1_meters.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" diff --git a/tests/test_wrongkeys.sh b/tests/test_wrongkeys.sh index d6ab2e6..4aa35d8 100755 --- a/tests/test_wrongkeys.sh +++ b/tests/test_wrongkeys.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh PROG="$1" From 6f323b30e6cbf999040de6f16f2c4b83998968d9 Mon Sep 17 00:00:00 2001 From: Erwan Martin Date: Tue, 21 Apr 2020 18:07:46 +0200 Subject: [PATCH 2/4] Add support for FreeBSD. --- Makefile | 13 +++++++++---- README.md | 6 ++++-- src/meters.cc | 1 + src/shell.cc | 6 +++--- 4 files changed, 17 insertions(+), 9 deletions(-) mode change 100644 => 100755 src/meters.cc diff --git a/Makefile b/Makefile index 290e753..d8df33d 100644 --- a/Makefile +++ b/Makefile @@ -21,12 +21,12 @@ # make DEBUG=true HOST=arm ifeq "$(HOST)" "arm" - CXX=arm-linux-gnueabihf-g++ + CXX?=arm-linux-gnueabihf-g++ STRIP=arm-linux-gnueabihf-strip BUILD=build_arm DEBARCH=armhf else - CXX=g++ + CXX?=g++ STRIP=strip #--strip-unneeded --remove-section=.comment --remove-section=.note BUILD=build @@ -37,8 +37,13 @@ ifeq "$(DEBUG)" "true" DEBUG_FLAGS=-O0 -ggdb -fsanitize=address -fno-omit-frame-pointer -fprofile-arcs -ftest-coverage STRIP_BINARY= BUILD:=$(BUILD)_debug - DEBUG_LDFLAGS=-lasan -lgcov --coverage - GCOV=gcov + ifeq '' '$(findstring clang++,$(CXX))' + DEBUG_LDFLAGS=-fsanitize=address --coverage + GCOV?=llvm-cov gcov + else + DEBUG_LDFLAGS=-lasan -lgcov --coverage + GCOV?=gcov + endif else DEBUG_FLAGS=-Os STRIP_BINARY=$(STRIP) $(BUILD)/wmbusmeters diff --git a/README.md b/README.md index 183075c..8c7dfbd 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ MQTT, curled to a REST api, inserted into a database or stored in a log file. [FAQ/WIKI/MANUAL pages](https://weetmuts.github.io/wmbusmeterswiki/) -The program runs on GNU/Linux, MacOSX and Raspberry Pi. +The program runs on GNU/Linux, MacOSX, FreeBSD, and Raspberry Pi. | OS | Status | | ------------ |:-------------:| @@ -321,7 +321,7 @@ With an rtlwmbus or amb8465 dongle: `wmbusmeters --listento=c1,t1 auto` With an imst871a dongle: `wmbusmeters --listento=c1 auto` -# Builds and runs on GNU/Linux and MacOSX (with recent XCode) +# Builds and runs on GNU/Linux MacOSX (with recent XCode), and FreeBSD `make && make test` @@ -335,6 +335,8 @@ Binary generated: `./build_arm/wmbusmeters` Binary generated: `./build_debug/wmbusmeters` +Debug builds only work on FreeBSD if the compiler is LLVM. If your system default compiler is gcc, set `CXX=clang++` to the build environment to force LLVM to be used. + `make DEBUG=true HOST=arm` Binary generated: `./build_arm_debug/wmbusmeters` diff --git a/src/meters.cc b/src/meters.cc old mode 100644 new mode 100755 index bf06334..468370f --- a/src/meters.cc +++ b/src/meters.cc @@ -23,6 +23,7 @@ #include #include +#include MeterCommonImplementation::MeterCommonImplementation(WMBus *bus, MeterInfo &mi, MeterType type, int manufacturer) : diff --git a/src/shell.cc b/src/shell.cc index 5774c94..ac0a00b 100644 --- a/src/shell.cc +++ b/src/shell.cc @@ -23,7 +23,7 @@ #include #include #include -#if defined(__APPLE__) && defined(__MACH__) +#if defined(__APPLE__) && defined(__MACH__) or defined(__FreeBSD__) #include #else #include @@ -61,7 +61,7 @@ void invokeShell(string program, vector args, vector envs) if (pid == 0) { // I am the child! close(0); // Close stdin -#if defined(__APPLE__) && defined(__MACH__) +#if (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) execve(program.c_str(), (char*const*)&argv[0], (char*const*)&env[0]); #else execvpe(program.c_str(), (char*const*)&argv[0], (char*const*)&env[0]); @@ -130,7 +130,7 @@ bool invokeBackgroundShell(string program, vector args, vector e close(link[1]); close(0); // Close stdin -#if defined(__APPLE__) && defined(__MACH__) +#if (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__) execve(program.c_str(), (char*const*)&argv[0], (char*const*)&env[0]); #else execvpe(program.c_str(), (char*const*)&argv[0], (char*const*)&env[0]); From c6f3f2336e1cd8a69f01777da6dff53a76ba61ac Mon Sep 17 00:00:00 2001 From: Erwan Martin Date: Tue, 21 Apr 2020 18:25:25 +0200 Subject: [PATCH 3/4] Fix wrong if directive in the Makefile. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d8df33d..aac75d6 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,7 @@ ifeq "$(DEBUG)" "true" DEBUG_FLAGS=-O0 -ggdb -fsanitize=address -fno-omit-frame-pointer -fprofile-arcs -ftest-coverage STRIP_BINARY= BUILD:=$(BUILD)_debug - ifeq '' '$(findstring clang++,$(CXX))' + ifneq '' '$(findstring clang++,$(CXX))' DEBUG_LDFLAGS=-fsanitize=address --coverage GCOV?=llvm-cov gcov else From 37149f17776865c26a3564adc171cf7a2433b423 Mon Sep 17 00:00:00 2001 From: Erwan Martin Date: Tue, 21 Apr 2020 18:44:19 +0200 Subject: [PATCH 4/4] Fix whitespace in the Makefile --- Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 389c788..6fa1560 100644 --- a/Makefile +++ b/Makefile @@ -26,13 +26,13 @@ ifeq "$(HOST)" "arm" CXX?=arm-linux-gnueabihf-g++ STRIP?=arm-linux-gnueabihf-strip BUILD=build_arm - DEBARCH=armhf + DEBARCH=armhf else CXX?=g++ STRIP?=strip #--strip-unneeded --remove-section=.comment --remove-section=.note BUILD=build - DEBARCH=amd64 + DEBARCH=amd64 endif ifeq "$(DEBUG)" "true" @@ -40,11 +40,11 @@ ifeq "$(DEBUG)" "true" STRIP_BINARY= BUILD:=$(BUILD)_debug ifneq '' '$(findstring clang++,$(CXX))' - DEBUG_LDFLAGS=-fsanitize=address --coverage - GCOV?=llvm-cov gcov - else - DEBUG_LDFLAGS=-lasan -lgcov --coverage - GCOV?=gcov + DEBUG_LDFLAGS=-fsanitize=address --coverage + GCOV?=llvm-cov gcov + else + DEBUG_LDFLAGS=-lasan -lgcov --coverage + GCOV?=gcov endif else DEBUG_FLAGS=-Os