2022-02-12 14:28:17 +00:00
|
|
|
# Copyright (C) 2017-2022 Fredrik Öhrström (gpl-3.0-or-later)
|
2019-01-04 20:25:15 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-08-09 10:00:11 +00:00
|
|
|
|
|
|
|
# To compile for Raspberry PI ARM:
|
|
|
|
# make HOST=arm
|
|
|
|
#
|
|
|
|
# To build with debug information:
|
|
|
|
# make DEBUG=true
|
|
|
|
# make DEBUG=true HOST=arm
|
|
|
|
|
2020-03-01 19:41:19 +00:00
|
|
|
DESTDIR?=/
|
|
|
|
|
2019-04-15 19:00:53 +00:00
|
|
|
ifeq "$(HOST)" "arm"
|
2020-04-21 16:07:46 +00:00
|
|
|
CXX?=arm-linux-gnueabihf-g++
|
2020-03-01 19:41:19 +00:00
|
|
|
STRIP?=arm-linux-gnueabihf-strip
|
2019-04-15 19:00:53 +00:00
|
|
|
BUILD=build_arm
|
2020-04-21 16:44:19 +00:00
|
|
|
DEBARCH=armhf
|
2019-04-15 19:00:53 +00:00
|
|
|
else
|
2020-04-21 16:07:46 +00:00
|
|
|
CXX?=g++
|
2020-03-01 19:41:19 +00:00
|
|
|
STRIP?=strip
|
2019-04-15 19:00:53 +00:00
|
|
|
#--strip-unneeded --remove-section=.comment --remove-section=.note
|
|
|
|
BUILD=build
|
2020-04-21 16:44:19 +00:00
|
|
|
DEBARCH=amd64
|
2019-04-15 19:00:53 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq "$(DEBUG)" "true"
|
2020-01-17 15:13:02 +00:00
|
|
|
DEBUG_FLAGS=-O0 -ggdb -fsanitize=address -fno-omit-frame-pointer -fprofile-arcs -ftest-coverage
|
2019-04-15 19:00:53 +00:00
|
|
|
STRIP_BINARY=
|
2022-05-01 07:43:58 +00:00
|
|
|
STRIP_ADMIN=
|
2019-04-15 19:00:53 +00:00
|
|
|
BUILD:=$(BUILD)_debug
|
2020-04-21 16:25:25 +00:00
|
|
|
ifneq '' '$(findstring clang++,$(CXX))'
|
2020-04-21 16:44:19 +00:00
|
|
|
DEBUG_LDFLAGS=-fsanitize=address --coverage
|
|
|
|
GCOV?=llvm-cov gcov
|
|
|
|
else
|
|
|
|
DEBUG_LDFLAGS=-lasan -lgcov --coverage
|
|
|
|
GCOV?=gcov
|
2020-04-21 16:07:46 +00:00
|
|
|
endif
|
2019-04-15 19:00:53 +00:00
|
|
|
else
|
2021-08-08 21:07:34 +00:00
|
|
|
DEBUG_FLAGS=-Os -g
|
2021-08-13 08:09:20 +00:00
|
|
|
STRIP_BINARY=cp $(BUILD)/wmbusmeters $(BUILD)/wmbusmeters.g; $(STRIP) $(BUILD)/wmbusmeters
|
2022-05-01 07:43:58 +00:00
|
|
|
STRIP_ADMIN=cp $(BUILD)/wmbusmeters-admin $(BUILD)/wmbusmeters-admin.g; $(STRIP) $(BUILD)/wmbusmeters-admin
|
2020-01-17 15:13:02 +00:00
|
|
|
GCOV=To_run_gcov_add_DEBUG=true
|
2019-04-15 19:00:53 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
$(shell mkdir -p $(BUILD))
|
|
|
|
|
2022-05-01 07:43:58 +00:00
|
|
|
define DQUOTE
|
|
|
|
"
|
|
|
|
endef
|
|
|
|
|
|
|
|
#' make editor quote matching happy.
|
|
|
|
|
|
|
|
SUPRE=
|
|
|
|
SUPOST=
|
|
|
|
ifneq ($(SUDO_USER),)
|
|
|
|
# Git has a security check to prevent the wrong user from running inside the git repository.
|
|
|
|
# When we run "sudo make install" this will create problems since git is running as root instead.
|
|
|
|
# Use SUPRE/SUPOST to use su to switch back to the user for the git commands.
|
|
|
|
SUPRE=su -c $(DQUOTE)
|
|
|
|
SUPOST=$(DQUOTE) $(SUDO_USER)
|
|
|
|
endif
|
|
|
|
|
|
|
|
COMMIT_HASH?=$(shell $(SUPRE) git log --pretty=format:'%H' -n 1 $(SUPOST))
|
|
|
|
TAG?=$(shell $(SUPRE) git describe --tags $(SUPOST))
|
|
|
|
BRANCH?=$(shell $(SUPRE) git rev-parse --abbrev-ref HEAD $(SUPOST))
|
|
|
|
CHANGES?=$(shell $(SUPRE) git status -s | grep -v '?? ' $(SUPOST))
|
2019-04-13 20:58:40 +00:00
|
|
|
|
2020-03-22 13:36:03 +00:00
|
|
|
ifeq ($(BRANCH),master)
|
|
|
|
BRANCH:=
|
|
|
|
else
|
|
|
|
BRANCH:=$(BRANCH)_
|
|
|
|
endif
|
|
|
|
|
2021-04-13 18:56:42 +00:00
|
|
|
VERSION:=$(BRANCH)$(TAG)
|
|
|
|
DEBVERSION:=$(BRANCH)$(TAG)
|
2022-09-11 15:40:17 +00:00
|
|
|
LOCALCHANGES:=
|
2019-04-13 20:58:40 +00:00
|
|
|
|
|
|
|
ifneq ($(strip $(CHANGES)),)
|
2021-04-13 18:56:42 +00:00
|
|
|
# There are local un-committed changes.
|
2019-04-13 20:58:40 +00:00
|
|
|
VERSION:=$(VERSION) with local changes
|
2019-04-15 19:00:53 +00:00
|
|
|
COMMIT_HASH:=$(COMMIT_HASH) with local changes
|
2019-04-13 20:58:40 +00:00
|
|
|
DEBVERSION:=$(DEBVERSION)l
|
2022-09-11 15:40:17 +00:00
|
|
|
LOCALCHANGES:=true
|
2019-04-13 20:58:40 +00:00
|
|
|
endif
|
|
|
|
|
2019-04-15 19:00:53 +00:00
|
|
|
$(shell echo "#define VERSION \"$(VERSION)\"" > $(BUILD)/version.h.tmp)
|
|
|
|
$(shell echo "#define COMMIT \"$(COMMIT_HASH)\"" >> $(BUILD)/version.h.tmp)
|
2017-08-09 10:00:11 +00:00
|
|
|
|
2022-01-08 13:10:05 +00:00
|
|
|
PREV_VERSION:=$(shell cat -n $(BUILD)/version.h 2> /dev/null)
|
|
|
|
CURR_VERSION:=$(shell cat -n $(BUILD)/version.h.tmp 2>/dev/null)
|
2022-05-01 07:43:58 +00:00
|
|
|
|
2019-04-15 19:00:53 +00:00
|
|
|
ifneq ($(PREV_VERSION),$(CURR_VERSION))
|
|
|
|
$(shell mv $(BUILD)/version.h.tmp $(BUILD)/version.h)
|
2022-05-01 07:43:58 +00:00
|
|
|
$(info New version number generates new $(BUILD)/version.h)
|
2017-08-09 10:00:11 +00:00
|
|
|
else
|
2019-04-15 19:00:53 +00:00
|
|
|
$(shell rm $(BUILD)/version.h.tmp)
|
2017-08-09 10:00:11 +00:00
|
|
|
endif
|
|
|
|
|
2019-04-15 19:00:53 +00:00
|
|
|
$(info Building $(VERSION))
|
2017-08-09 10:00:11 +00:00
|
|
|
|
2021-08-09 09:06:30 +00:00
|
|
|
FUZZFLAGS ?= -DFUZZING=false
|
2022-06-24 09:07:27 +00:00
|
|
|
CXXFLAGS ?= $(DEBUG_FLAGS) $(FUZZFLAGS) -fPIC -std=c++11 -Wall -Werror=format-security -Wno-unused-function
|
2022-06-16 14:01:31 +00:00
|
|
|
# Additional fedora rpm package build flags
|
|
|
|
# -O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
|
2020-03-01 19:41:19 +00:00
|
|
|
CXXFLAGS += -I$(BUILD)
|
|
|
|
LDFLAGS ?= $(DEBUG_LDFLAGS)
|
2017-08-09 10:00:11 +00:00
|
|
|
|
2020-11-28 13:18:18 +00:00
|
|
|
USBLIB = -lusb-1.0
|
|
|
|
|
|
|
|
ifeq ($(shell uname -s),FreeBSD)
|
|
|
|
CXXFLAGS += -I/usr/local/include
|
|
|
|
LDFLAGS += -L/usr/local/lib
|
|
|
|
USBLIB = -lusb
|
|
|
|
endif
|
|
|
|
|
2019-02-23 12:53:52 +00:00
|
|
|
$(BUILD)/%.o: src/%.cc $(wildcard src/%.h)
|
2020-01-28 18:09:39 +00:00
|
|
|
$(CXX) $(CXXFLAGS) $< -c -E > $@.src
|
2019-03-15 12:59:26 +00:00
|
|
|
$(CXX) $(CXXFLAGS) $< -MMD -c -o $@
|
2017-08-09 10:00:11 +00:00
|
|
|
|
2022-01-08 13:10:05 +00:00
|
|
|
PROG_OBJS:=\
|
2017-08-09 10:00:11 +00:00
|
|
|
$(BUILD)/aes.o \
|
2020-01-28 15:15:11 +00:00
|
|
|
$(BUILD)/aescmac.o \
|
2021-03-09 21:00:11 +00:00
|
|
|
$(BUILD)/bus.o \
|
2017-08-31 08:58:39 +00:00
|
|
|
$(BUILD)/cmdline.o \
|
2019-02-23 12:41:17 +00:00
|
|
|
$(BUILD)/config.o \
|
2018-04-01 06:53:37 +00:00
|
|
|
$(BUILD)/dvparser.o \
|
2021-02-13 14:18:59 +00:00
|
|
|
$(BUILD)/mbus_rawtty.o \
|
2017-08-31 08:58:39 +00:00
|
|
|
$(BUILD)/meters.o \
|
2021-02-20 21:21:01 +00:00
|
|
|
$(BUILD)/manufacturer_specificities.o \
|
|
|
|
$(BUILD)/printer.o \
|
|
|
|
$(BUILD)/rtlsdr.o \
|
|
|
|
$(BUILD)/serial.o \
|
|
|
|
$(BUILD)/shell.o \
|
|
|
|
$(BUILD)/sha256.o \
|
|
|
|
$(BUILD)/threads.o \
|
2022-01-08 13:10:05 +00:00
|
|
|
$(BUILD)/translatebits.o \
|
2021-02-20 21:21:01 +00:00
|
|
|
$(BUILD)/util.o \
|
|
|
|
$(BUILD)/units.o \
|
|
|
|
$(BUILD)/wmbus.o \
|
|
|
|
$(BUILD)/wmbus_amb8465.o \
|
|
|
|
$(BUILD)/wmbus_im871a.o \
|
|
|
|
$(BUILD)/wmbus_cul.o \
|
|
|
|
$(BUILD)/wmbus_rtlwmbus.o \
|
|
|
|
$(BUILD)/wmbus_rtl433.o \
|
|
|
|
$(BUILD)/wmbus_simulator.o \
|
|
|
|
$(BUILD)/wmbus_rawtty.o \
|
|
|
|
$(BUILD)/wmbus_rc1180.o \
|
|
|
|
$(BUILD)/wmbus_utils.o \
|
2022-02-19 07:13:58 +00:00
|
|
|
$(BUILD)/lora_iu880b.o \
|
2021-03-07 17:52:36 +00:00
|
|
|
|
2022-02-17 19:42:20 +00:00
|
|
|
# If you run: "make DRIVER=minomess" then only driver_minomess.cc will be compiled into wmbusmeters.
|
|
|
|
# The old style drivers meter_xyz.cc must always be compiled in, but eventually they will be gone.
|
|
|
|
|
2022-01-13 08:51:08 +00:00
|
|
|
ifeq ($(DRIVER),)
|
2022-01-18 10:07:19 +00:00
|
|
|
DRIVER_OBJS:=$(wildcard src/meter_*.cc) $(wildcard src/driver_*.cc)
|
2022-01-13 08:51:08 +00:00
|
|
|
else
|
|
|
|
$(info Building a single driver $(DRIVER))
|
2022-02-17 19:42:20 +00:00
|
|
|
DRIVER_OBJS:=src/driver_auto.cc src/driver_unknown.cc $(wildcard src/meter_*.cc) src/driver_$(DRIVER).cc
|
2022-01-13 08:51:08 +00:00
|
|
|
endif
|
2022-01-08 13:10:05 +00:00
|
|
|
DRIVER_OBJS:=$(patsubst src/%.cc,$(BUILD)/%.o,$(DRIVER_OBJS))
|
|
|
|
|
2021-08-13 08:09:20 +00:00
|
|
|
all: $(BUILD)/wmbusmeters $(BUILD)/wmbusmetersd $(BUILD)/wmbusmeters.g $(BUILD)/wmbusmeters-admin $(BUILD)/testinternals
|
2019-01-04 20:25:15 +00:00
|
|
|
|
2022-04-28 13:30:07 +00:00
|
|
|
deb:
|
2022-09-11 15:40:17 +00:00
|
|
|
@if [ "$(RELEASE)" = "" ] ; then echo "Usage: make deb TAG=1.9.0" ; exit 1 ; fi
|
|
|
|
@rm -rf packaging
|
|
|
|
@mkdir -p packaging
|
|
|
|
@echo "Checking out tag $(RELEASE)..."
|
|
|
|
@(cd packaging ; git clone $(PWD) wmbusmeters-$(RELEASE) ; cd wmbusmeters-$(RELEASE) ; git -c advice.detachedHead=false checkout tags/$(RELEASE) )
|
|
|
|
@(cd packaging/wmbusmeters-$(RELEASE) ; git show -s --format=%ct > ../release_date )
|
|
|
|
@echo "Removing git history..."
|
|
|
|
@(cd packaging ; rm -rf wmbusmeters-$(RELEASE)/.git )
|
|
|
|
@echo "Setting file timestamps to commit date..."
|
|
|
|
@(cd packaging ; export UT=$$(cat ./release_date) ; find . -exec touch -d "@$$UT" \{\} \; )
|
|
|
|
@echo "Creating orig archive..."
|
|
|
|
@(cd packaging ; tar czf ./wmbusmeters_$(RELEASE).orig.tar.gz wmbusmeters-$(RELEASE) )
|
|
|
|
@echo "Running debbuild..."
|
2022-09-14 15:12:18 +00:00
|
|
|
@(cd packaging/wmbusmeters-$(RELEASE) ; cp -a deb debian; debuild )
|
2022-09-11 15:40:17 +00:00
|
|
|
|
2021-12-25 13:19:27 +00:00
|
|
|
|
|
|
|
# Check docs verifies that all options in the source have been mentioned in the README and in the man page.
|
|
|
|
# Also any option not in the source but mentioned in the docs is warned for as well.
|
2021-06-26 10:24:30 +00:00
|
|
|
check_docs:
|
2021-12-27 13:30:54 +00:00
|
|
|
@rm -f /tmp/options_in_*
|
2021-06-26 10:24:30 +00:00
|
|
|
@cat src/cmdline.cc | grep -o -- '--[a-z][a-z]*' | sort | uniq | grep -v internaltesting > /tmp/options_in_code
|
|
|
|
@cat wmbusmeters.1 | grep -o -- '--[a-z][a-z]*' | sort | uniq | grep -v internaltesting > /tmp/options_in_man
|
|
|
|
@cat README.md | grep -o -- '--[a-z][a-z]*' | sort | uniq | grep -v internaltesting > /tmp/options_in_readme
|
2022-05-01 15:05:30 +00:00
|
|
|
@$(BUILD)/wmbusmeters --help | grep -o -- '--[a-z][a-z]*' | sort | uniq | grep -v internaltesting > /tmp/options_in_binary
|
2021-06-29 14:54:12 +00:00
|
|
|
@diff /tmp/options_in_code /tmp/options_in_man || echo CODE_VS_MAN
|
|
|
|
@diff /tmp/options_in_code /tmp/options_in_readme || echo CODE_VS_README
|
|
|
|
@diff /tmp/options_in_code /tmp/options_in_binary || echo CODE_VS_BINARY
|
2021-06-26 10:28:17 +00:00
|
|
|
@echo "OK docs"
|
2021-06-26 10:24:30 +00:00
|
|
|
|
|
|
|
install: $(BUILD)/wmbusmeters check_docs
|
2022-05-01 15:05:30 +00:00
|
|
|
echo "Installing $(BUILD)/wmbusmeters"
|
2020-03-01 19:41:19 +00:00
|
|
|
@./install.sh $(BUILD)/wmbusmeters $(DESTDIR) $(EXTRA_INSTALL_OPTIONS)
|
2019-02-23 18:49:30 +00:00
|
|
|
|
|
|
|
uninstall:
|
|
|
|
@./uninstall.sh /
|
2019-01-04 20:25:15 +00:00
|
|
|
|
2020-05-28 05:51:34 +00:00
|
|
|
snapcraft:
|
2021-03-06 14:44:38 +00:00
|
|
|
snapcraft
|
2020-05-28 05:51:34 +00:00
|
|
|
|
2022-02-12 14:28:17 +00:00
|
|
|
$(BUILD)/main.o: $(BUILD)/short_manual.h $(BUILD)/version.h $(BUILD)/authors.h
|
|
|
|
|
|
|
|
$(BUILD)/authors.h:
|
|
|
|
./scripts/generate_authors.sh $(BUILD)/authors.h
|
2019-10-24 19:06:33 +00:00
|
|
|
|
2021-08-13 08:09:20 +00:00
|
|
|
# Build binary with debug information. ~15M size binary.
|
2022-01-08 13:10:05 +00:00
|
|
|
$(BUILD)/wmbusmeters.g: $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/main.o $(BUILD)/short_manual.h
|
|
|
|
$(CXX) -o $(BUILD)/wmbusmeters.g $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/main.o $(LDFLAGS) -lrtlsdr $(USBLIB) -lpthread
|
2021-08-13 08:09:20 +00:00
|
|
|
|
|
|
|
# Production build will have debug information stripped. ~1.5M size binary.
|
|
|
|
# DEBUG=true builds, which has address sanitizer code, will always keep the debug information.
|
|
|
|
$(BUILD)/wmbusmeters: $(BUILD)/wmbusmeters.g
|
|
|
|
cp $(BUILD)/wmbusmeters.g $(BUILD)/wmbusmeters
|
|
|
|
$(STRIP_BINARY)
|
|
|
|
|
|
|
|
$(BUILD)/wmbusmetersd: $(BUILD)/wmbusmeters
|
|
|
|
cp $(BUILD)/wmbusmeters $(BUILD)/wmbusmetersd
|
2018-12-28 17:35:32 +00:00
|
|
|
|
2021-02-03 11:00:00 +00:00
|
|
|
ifeq ($(shell uname -s),Darwin)
|
|
|
|
$(BUILD)/wmbusmeters-admin:
|
|
|
|
touch $(BUILD)/wmbusmeters-admin
|
|
|
|
else
|
2022-01-08 13:10:05 +00:00
|
|
|
$(BUILD)/wmbusmeters-admin: $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/admin.o $(BUILD)/ui.o $(BUILD)/short_manual.h
|
2022-09-23 08:28:54 +00:00
|
|
|
$(CXX) -o $(BUILD)/wmbusmeters-admin $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/admin.o $(BUILD)/ui.o $(LDFLAGS) -lmenu -lform -lncurses -lrtlsdr $(USBLIB) -lpthread
|
2022-05-01 07:43:58 +00:00
|
|
|
$(STRIP_ADMIN)
|
2021-02-03 11:00:00 +00:00
|
|
|
endif
|
2020-04-03 09:58:19 +00:00
|
|
|
|
2019-10-24 19:06:33 +00:00
|
|
|
$(BUILD)/short_manual.h: README.md
|
|
|
|
echo 'R"MANUAL(' > $(BUILD)/short_manual.h
|
|
|
|
sed -n '/wmbusmeters version/,/```/p' README.md \
|
2020-05-26 20:18:37 +00:00
|
|
|
| grep -v 'wmbusmeters version' \
|
|
|
|
| grep -v '```' >> $(BUILD)/short_manual.h
|
2019-10-24 19:06:33 +00:00
|
|
|
echo ')MANUAL";' >> $(BUILD)/short_manual.h
|
|
|
|
|
2022-01-08 13:10:05 +00:00
|
|
|
$(BUILD)/testinternals: $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/testinternals.o
|
|
|
|
$(CXX) -o $(BUILD)/testinternals $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/testinternals.o $(LDFLAGS) -lrtlsdr $(USBLIB) -lpthread
|
2017-08-09 10:00:11 +00:00
|
|
|
|
2022-01-08 13:10:05 +00:00
|
|
|
$(BUILD)/fuzz: $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/fuzz.o
|
|
|
|
$(CXX) -o $(BUILD)/fuzz $(PROG_OBJS) $(DRIVER_OBJS) $(BUILD)/fuzz.o $(LDFLAGS) -lrtlsdr -lpthread
|
2019-03-15 20:49:18 +00:00
|
|
|
|
2017-08-09 10:00:11 +00:00
|
|
|
clean:
|
2019-01-04 21:27:51 +00:00
|
|
|
rm -rf build/* build_arm/* build_debug/* build_arm_debug/* *~
|
2022-04-29 06:23:54 +00:00
|
|
|
$(RM) testaes/test_input.txt testaes/test_stderr.txt
|
|
|
|
$(RM) testoutput/test_expected.txt testoutput/test_input.txt \
|
|
|
|
testoutput/test_response.txt testoutput/test_responses.txt \
|
|
|
|
testoutput/test_stderr.txt
|
|
|
|
|
|
|
|
distclean: clean
|
|
|
|
$(RM) config.log
|
2017-09-02 21:26:57 +00:00
|
|
|
|
2020-01-17 15:13:02 +00:00
|
|
|
clean_cc:
|
|
|
|
find . -name "*.gcov" -delete
|
|
|
|
find . -name "*.gcda" -delete
|
|
|
|
|
2021-08-19 10:54:04 +00:00
|
|
|
# This generates annotated source files ending in .gcov
|
|
|
|
# inside the build_debug where non-executed source lines are marked #####
|
2020-01-17 15:13:02 +00:00
|
|
|
gcov:
|
2021-08-19 10:54:04 +00:00
|
|
|
@if [ "$(DEBUG)" = "" ]; then echo "You have to run \"make gcov DEBUG=true\""; exit 1; fi
|
2022-01-08 13:10:05 +00:00
|
|
|
$(GCOV) -o build_debug $(PROG_OBJS) $(DRIVER_OBJS)
|
2020-01-17 15:13:02 +00:00
|
|
|
mv *.gcov build_debug
|
|
|
|
|
2021-08-19 10:54:04 +00:00
|
|
|
lcov:
|
|
|
|
@if [ "$(DEBUG)" = "" ]; then echo "You have to run \"make lcov DEBUG=true\""; exit 1; fi
|
|
|
|
lcov --directory . -c --no-external --output-file build_debug/lcov.info
|
|
|
|
(cd build_debug; genhtml lcov.info)
|
|
|
|
xdg-open build_debug/src/index.html
|
|
|
|
|
2020-09-18 19:48:47 +00:00
|
|
|
test:
|
2019-11-03 21:00:18 +00:00
|
|
|
@./test.sh build/wmbusmeters
|
2018-01-05 16:46:10 +00:00
|
|
|
|
2020-09-18 19:48:47 +00:00
|
|
|
testd:
|
2019-11-03 21:00:18 +00:00
|
|
|
@./test.sh build_debug/wmbusmeters
|
2019-03-05 17:38:54 +00:00
|
|
|
|
2022-09-08 18:41:58 +00:00
|
|
|
testdriver:
|
|
|
|
@./tests/test_drivers.sh build/wmbusmeters driver_${DRIVER}.cc
|
|
|
|
|
2017-09-02 21:26:57 +00:00
|
|
|
update_manufacturers:
|
2019-04-01 21:22:09 +00:00
|
|
|
iconv -f utf-8 -t ascii//TRANSLIT -c DLMS_Flagids.csv -o tmp.flags
|
|
|
|
cat tmp.flags | grep -v ^# | cut -f 1 > list.flags
|
|
|
|
cat tmp.flags | grep -v ^# | cut -f 2 > names.flags
|
|
|
|
cat tmp.flags | grep -v ^# | cut -f 3 > countries.flags
|
|
|
|
cat countries.flags | sort -u | grep -v '^$$' > uniquec.flags
|
|
|
|
cat names.flags | tr -d "'" | tr -c 'a-zA-Z0-9\n' ' ' | tr -s ' ' | sed 's/^ //g' | sed 's/ $$//g' > ansi.flags
|
|
|
|
cat ansi.flags | sed 's/\(^.......[^0123456789]*\)[0123456789]\+.*/\1/g' > cleaned.flags
|
|
|
|
cat cleaned.flags | sed -e "$$(sed 's:.*:s/&//Ig:' uniquec.flags)" > cleanedc.flags
|
|
|
|
cat cleanedc.flags | sed \
|
|
|
|
-e 's/ ab\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ ag\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ a \?s\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ co\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ b \?v\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ bvba\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ corp\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ d \?o \?o\( \|$$\)/ /g' \
|
|
|
|
-e 's/ d \?d\( \|$$\)/ /g' \
|
|
|
|
-e 's/ gmbh//Ig' \
|
|
|
|
-e 's/ gbr//Ig' \
|
|
|
|
-e 's/ inc\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ kg\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ llc/ /Ig' \
|
|
|
|
-e 's/ ltd//Ig' \
|
|
|
|
-e 's/ limited//Ig' \
|
|
|
|
-e 's/ nv\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ oy//Ig' \
|
|
|
|
-e 's/ ood\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ooo\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ pvt\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ pte\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ pty\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ plc\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ private\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ s \?a\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ sarl\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ sagl\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ s c ul//Ig' \
|
|
|
|
-e 's/ s \?l\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ s \?p \?a\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ sp j\( \|$$\)/ /Ig' \
|
|
|
|
-e 's/ sp z o o//Ig' \
|
|
|
|
-e 's/ s r o//Ig' \
|
|
|
|
-e 's/ s \?r \?l//Ig' \
|
|
|
|
-e 's/ ug\( \|$$\)/ /Ig' \
|
|
|
|
> trimmed.flags
|
|
|
|
cat trimmed.flags | tr -s ' ' | sed 's/^ //g' | sed 's/ $$//g' > done.flags
|
|
|
|
paste -d '|,' list.flags done.flags countries.flags | sed 's/,/, /g' | sed 's/ |/|/g' > manufacturers.txt
|
2022-04-16 18:31:23 +00:00
|
|
|
echo "// Copyright (C) $$(date +%Y) Fredrik Öhrström (CC0)" > m.h
|
2022-02-12 14:28:17 +00:00
|
|
|
echo '#ifndef MANUFACTURERS_H' >> m.h
|
2018-01-05 16:46:10 +00:00
|
|
|
echo '#define MANUFACTURERS_H' >> m.h
|
2017-09-02 21:26:57 +00:00
|
|
|
echo '#define MANFCODE(a,b,c) ((a-64)*1024+(b-64)*32+(c-64))' >> m.h
|
2019-04-01 21:22:09 +00:00
|
|
|
echo "#define LIST_OF_MANUFACTURERS \\" >> m.h
|
2019-04-27 11:31:13 +00:00
|
|
|
cat manufacturers.txt | sed -e "s/\(.\)\(.\)\(.\).\(.*\)/X(\1\2\3,MANFCODE('\1','\2','\3'),\"\4\")\\\\/g" | sed 's/, ")/")/' >> m.h
|
2017-09-02 21:26:57 +00:00
|
|
|
echo >> m.h
|
2019-04-01 21:22:09 +00:00
|
|
|
cat manufacturers.txt | sed -e "s/\(.\)\(.\)\(.\).*/#define MANUFACTURER_\1\2\3 MANFCODE('\1','\2','\3')/g" >> m.h
|
2017-09-02 21:26:57 +00:00
|
|
|
echo >> m.h
|
|
|
|
echo '#endif' >> m.h
|
2019-03-15 12:05:54 +00:00
|
|
|
mv m.h src/manufacturers.h
|
2019-11-03 15:31:30 +00:00
|
|
|
rm *.flags manufacturers.txt
|
2019-03-15 12:59:26 +00:00
|
|
|
|
2021-08-01 16:24:19 +00:00
|
|
|
|
2021-08-21 19:13:47 +00:00
|
|
|
GCC_MAJOR_VERSION:=$(shell gcc --version | head -n 1 | sed 's/.* \([0-9]\)\.[0-9]\.[0-9]$$/\1/')
|
2021-08-01 16:24:19 +00:00
|
|
|
AFL_HOME:=AFLplusplus
|
|
|
|
|
|
|
|
$(AFL_HOME)/src/afl-cc.c:
|
|
|
|
mkdir -p AFLplusplus
|
|
|
|
if ! dpkg -s gcc-$(GCC_MAJOR_VERSION)-plugin-dev 2>/dev/null >/dev/null ; then echo "Please run: sudo apt install gcc-$(GCC_MAJOR_VERSION)-plugin-dev"; exit 1; fi
|
|
|
|
git clone https://github.com/AFLplusplus/AFLplusplus.git
|
|
|
|
|
|
|
|
afl_prepared: AFLplusplus/src/afl-cc.c
|
|
|
|
(cd AFLplusplus; make)
|
|
|
|
touch afl_prepared
|
|
|
|
|
|
|
|
build_fuzz: afl_prepared
|
2021-08-09 09:06:30 +00:00
|
|
|
$(MAKE) AFL_HARDEN=1 CXX=$(AFL_HOME)/afl-g++-fast FUZZFLAGS=-DFUZZING=true $(BUILD)/fuzz
|
|
|
|
$(MAKE) AFL_HARDEN=1 CXX=$(AFL_HOME)/afl-g++-fast FUZZFLAGS=-DFUZZING=true $(BUILD)/wmbusmeters
|
2019-03-15 20:49:18 +00:00
|
|
|
|
2019-10-28 21:27:08 +00:00
|
|
|
run_fuzz_difvifparser:
|
2021-08-09 09:28:39 +00:00
|
|
|
${AFL_HOME}/afl-fuzz -i fuzz_testcases/difvifparser -o fuzz_findings_difvifparser/ build/fuzz
|
2019-10-28 21:27:08 +00:00
|
|
|
|
2021-08-09 09:28:39 +00:00
|
|
|
run_fuzz_telegrams: extract_fuzz_telegram_seeds
|
|
|
|
${AFL_HOME}/afl-fuzz -i fuzz_testcases/telegrams -o fuzz_findings_telegrams/ build/wmbusmeters --listento=any stdin
|
|
|
|
|
|
|
|
extract_fuzz_telegram_seeds:
|
2022-09-04 14:20:16 +00:00
|
|
|
@cat src/driver_*.cc | grep "^// telegram=" | tr -d '|' | sed 's|^// telegram=\|||' > $(BUILD)/seeds
|
2021-08-09 09:28:39 +00:00
|
|
|
@mkdir -p fuzz_testcases/telegrams
|
|
|
|
@rm -f fuzz_testcases/telegrams/seed_*
|
|
|
|
@SEED=1; while read -r line; do echo "$${line}" | xxd -r -p - > "fuzz_testcases/telegrams/seed_$${SEED}"; SEED=$$((SEED + 1)); done < $(BUILD)/seeds; echo "Extracted $${SEED} seeds from simulations."
|
2019-03-15 12:59:26 +00:00
|
|
|
|
2021-09-02 09:22:21 +00:00
|
|
|
relay: utils/relay.c
|
|
|
|
gcc -g utils/relay.c -o relay -O0 -ggdb -fsanitize=address -fno-omit-frame-pointer -fprofile-arcs -ftest-coverage
|
|
|
|
|
2022-01-25 08:58:37 +00:00
|
|
|
# Bump major number
|
|
|
|
release_major:
|
|
|
|
@./scripts/release.sh major
|
|
|
|
|
|
|
|
# Bump minor number
|
|
|
|
release_minor:
|
|
|
|
@./scripts/release.sh minor
|
|
|
|
|
|
|
|
# Bump patch number
|
|
|
|
release_patch:
|
|
|
|
@./scripts/release.sh patch
|
|
|
|
|
|
|
|
# Bump release candidate number, ie a bug in the previous RC was found!
|
|
|
|
release_rc:
|
|
|
|
@./scripts/release.sh rc
|
|
|
|
|
|
|
|
deploy:
|
|
|
|
@./scripts/deploy.sh
|
|
|
|
|
2022-09-14 16:01:08 +00:00
|
|
|
collect_copyrights:
|
|
|
|
./scripts/collect_copyrights.sh deb/copyright
|
2022-02-12 14:28:17 +00:00
|
|
|
|
2019-03-15 12:59:26 +00:00
|
|
|
# Include dependency information generated by gcc in a previous compile.
|
2022-01-08 13:10:05 +00:00
|
|
|
include $(wildcard $(patsubst %.o,%.d,$(PROG_OBJS) $(DRIVER_OBJS)))
|
2022-04-28 13:30:07 +00:00
|
|
|
|
2022-09-27 17:27:37 +00:00
|
|
|
.PHONY: deb test testd deploy release_major release_minor release_rc collect_copyrights
|