2020-09-06 08:41:04 +00:00
|
|
|
# Copyright (C) 2017-2020 Fredrik Öhrström
|
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=
|
|
|
|
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
|
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))
|
|
|
|
|
2020-03-01 19:41:19 +00:00
|
|
|
COMMIT_HASH?=$(shell git log --pretty=format:'%H' -n 1)
|
|
|
|
TAG?=$(shell git describe --tags)
|
2020-03-22 13:36:03 +00:00
|
|
|
BRANCH?=$(shell git rev-parse --abbrev-ref HEAD)
|
2020-03-01 19:41:19 +00:00
|
|
|
CHANGES?=$(shell git status -s | grep -v '?? ')
|
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)
|
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
|
|
|
|
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
|
|
|
|
2019-04-15 19:00:53 +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)
|
|
|
|
ifneq ($(PREV_VERSION),$(CURR_VERSION))
|
|
|
|
$(shell mv $(BUILD)/version.h.tmp $(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
|
|
|
|
CXXFLAGS ?= $(DEBUG_FLAGS) $(FUZZFLAGS) -fPIC -std=c++11 -Wall -Werror=format-security
|
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
|
|
|
|
2019-03-15 12:59:26 +00:00
|
|
|
METER_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 \
|
|
|
|
$(BUILD)/util.o \
|
|
|
|
$(BUILD)/units.o \
|
|
|
|
$(BUILD)/wmbus.o \
|
2021-03-07 18:52:21 +00:00
|
|
|
$(BUILD)/meter_auto.o \
|
|
|
|
$(BUILD)/meter_unknown.o \
|
2019-03-19 19:53:44 +00:00
|
|
|
$(BUILD)/meter_amiplus.o \
|
2021-02-20 21:21:01 +00:00
|
|
|
$(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 \
|
2020-02-23 12:55:37 +00:00
|
|
|
$(BUILD)/meter_apator08.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_apator162.o \
|
2021-07-02 12:39:07 +00:00
|
|
|
$(BUILD)/meter_aventieswm.o \
|
2021-07-05 18:58:57 +00:00
|
|
|
$(BUILD)/meter_aventieshca.o \
|
2021-10-24 15:54:36 +00:00
|
|
|
$(BUILD)/meter_bfw240radio.o \
|
2020-01-27 15:53:18 +00:00
|
|
|
$(BUILD)/meter_cma12w.o \
|
2020-07-26 12:40:25 +00:00
|
|
|
$(BUILD)/meter_compact5.o \
|
2021-04-10 15:58:32 +00:00
|
|
|
$(BUILD)/meter_dme_07.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_ebzwmbe.o \
|
2020-01-27 15:53:18 +00:00
|
|
|
$(BUILD)/meter_ehzp.o \
|
2020-01-29 06:42:24 +00:00
|
|
|
$(BUILD)/meter_esyswm.o \
|
2021-02-14 21:55:25 +00:00
|
|
|
$(BUILD)/meter_elf.o \
|
2020-09-24 17:49:45 +00:00
|
|
|
$(BUILD)/meter_em24.o \
|
2020-11-14 09:48:49 +00:00
|
|
|
$(BUILD)/meter_emerlin868.o \
|
|
|
|
$(BUILD)/meter_ev200.o \
|
2021-01-26 21:22:59 +00:00
|
|
|
$(BUILD)/meter_evo868.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_eurisii.o \
|
2020-02-11 21:35:57 +00:00
|
|
|
$(BUILD)/meter_fhkvdataiii.o \
|
2021-01-06 18:48:56 +00:00
|
|
|
$(BUILD)/meter_fhkvdataiv.o \
|
2020-10-25 18:48:07 +00:00
|
|
|
$(BUILD)/meter_flowiq2200.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_hydrus.o \
|
2020-12-09 21:12:56 +00:00
|
|
|
$(BUILD)/meter_hydrocalm3.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_hydrodigit.o \
|
2021-03-06 06:42:37 +00:00
|
|
|
$(BUILD)/meter_ei6500.o \
|
2020-05-26 20:18:37 +00:00
|
|
|
$(BUILD)/meter_iperl.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_izar.o \
|
2020-09-04 10:13:06 +00:00
|
|
|
$(BUILD)/meter_izar3.o \
|
2020-06-30 09:29:55 +00:00
|
|
|
$(BUILD)/meter_lansendw.o \
|
2020-06-22 08:44:47 +00:00
|
|
|
$(BUILD)/meter_lansensm.o \
|
2020-05-26 20:18:37 +00:00
|
|
|
$(BUILD)/meter_lansenth.o \
|
2020-06-30 14:02:38 +00:00
|
|
|
$(BUILD)/meter_lansenpu.o \
|
2021-04-13 09:00:57 +00:00
|
|
|
$(BUILD)/meter_lse_07_17.o \
|
2021-11-30 11:14:35 +00:00
|
|
|
$(BUILD)/meter_minomess.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_mkradio3.o \
|
2020-11-22 19:40:03 +00:00
|
|
|
$(BUILD)/meter_mkradio4.o \
|
2020-05-26 20:18:37 +00:00
|
|
|
$(BUILD)/meter_multical21.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_multical302.o \
|
2020-08-18 16:20:30 +00:00
|
|
|
$(BUILD)/meter_multical403.o \
|
2021-10-02 09:36:33 +00:00
|
|
|
$(BUILD)/meter_multical602.o \
|
2020-09-23 06:39:38 +00:00
|
|
|
$(BUILD)/meter_multical603.o \
|
2021-02-07 22:06:44 +00:00
|
|
|
$(BUILD)/meter_multical803.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_omnipower.o \
|
2021-02-24 19:20:04 +00:00
|
|
|
$(BUILD)/meter_piigth.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_q400.o \
|
|
|
|
$(BUILD)/meter_qcaloric.o \
|
2021-10-24 15:18:53 +00:00
|
|
|
$(BUILD)/meter_qheat.o \
|
2021-11-28 17:23:42 +00:00
|
|
|
$(BUILD)/meter_qsmoke.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_rfmamb.o \
|
2020-04-01 15:21:11 +00:00
|
|
|
$(BUILD)/meter_rfmtx1.o \
|
2021-02-12 19:12:46 +00:00
|
|
|
$(BUILD)/meter_sharky.o \
|
2021-12-31 16:23:34 +00:00
|
|
|
$(BUILD)/meter_sharky774.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_supercom587.o \
|
2020-10-31 14:16:14 +00:00
|
|
|
$(BUILD)/meter_sontex868.o \
|
2020-09-01 19:53:05 +00:00
|
|
|
$(BUILD)/meter_topaseskr.o \
|
2020-12-31 13:46:05 +00:00
|
|
|
$(BUILD)/meter_tsd2.o \
|
2020-11-03 04:23:48 +00:00
|
|
|
$(BUILD)/meter_ultrimis.o \
|
2020-02-06 12:14:46 +00:00
|
|
|
$(BUILD)/meter_vario451.o \
|
2020-07-08 19:16:26 +00:00
|
|
|
$(BUILD)/meter_waterstarm.o \
|
2020-12-28 18:20:31 +00:00
|
|
|
$(BUILD)/meter_whe46x.o \
|
2021-01-26 16:17:29 +00:00
|
|
|
$(BUILD)/meter_whe5x.o \
|
2020-11-10 13:20:04 +00:00
|
|
|
$(BUILD)/meter_sensostar.o \
|
2021-01-29 16:20:54 +00:00
|
|
|
$(BUILD)/meter_gransystems_ccx01.o \
|
2021-03-07 17:52:36 +00:00
|
|
|
$(BUILD)/meter_lse_08.o \
|
|
|
|
$(BUILD)/meter_weh_07.o \
|
2021-09-23 10:06:12 +00:00
|
|
|
$(BUILD)/meter_unismart.o \
|
2021-10-16 09:41:48 +00:00
|
|
|
$(BUILD)/meter_munia.o \
|
2021-03-07 17:52:36 +00:00
|
|
|
|
2017-08-09 10:00:11 +00:00
|
|
|
|
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
|
|
|
|
2020-11-25 10:34:14 +00:00
|
|
|
deb: wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb
|
2019-02-23 17:30:16 +00:00
|
|
|
|
2021-06-29 14:54:12 +00:00
|
|
|
check_deb:
|
|
|
|
lintian --no-tag-display-limit wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb
|
|
|
|
|
2021-12-25 13:19:27 +00:00
|
|
|
clean_deb:
|
|
|
|
rm -f wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb
|
|
|
|
|
|
|
|
# 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
|
2021-06-26 10:28:17 +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
|
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
|
|
|
|
2019-04-13 20:58:40 +00:00
|
|
|
wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb:
|
2021-06-26 15:49:21 +00:00
|
|
|
@./deb/create_deb.sh $(BUILD) $@ $(DEBVERSION) $(DEBARCH)
|
2017-08-09 10:00:11 +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
|
|
|
|
2020-05-25 18:31:22 +00:00
|
|
|
$(BUILD)/main.o: $(BUILD)/short_manual.h $(BUILD)/version.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.
|
|
|
|
$(BUILD)/wmbusmeters.g: $(METER_OBJS) $(BUILD)/main.o $(BUILD)/short_manual.h
|
|
|
|
$(CXX) -o $(BUILD)/wmbusmeters.g $(METER_OBJS) $(BUILD)/main.o $(LDFLAGS) -lrtlsdr $(USBLIB) -lpthread
|
|
|
|
|
|
|
|
# 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
|
2020-08-30 19:33:48 +00:00
|
|
|
$(BUILD)/wmbusmeters-admin: $(METER_OBJS) $(BUILD)/admin.o $(BUILD)/ui.o $(BUILD)/short_manual.h
|
2021-08-13 08:09:20 +00:00
|
|
|
$(CXX) -o $(BUILD)/wmbusmeters-admin.g $(METER_OBJS) $(BUILD)/admin.o $(BUILD)/ui.o $(LDFLAGS) -lmenu -lform -lncurses -lrtlsdr $(USBLIB) -lpthread
|
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
|
|
|
|
|
2019-03-15 12:59:26 +00:00
|
|
|
$(BUILD)/testinternals: $(METER_OBJS) $(BUILD)/testinternals.o
|
2020-11-28 13:18:18 +00:00
|
|
|
$(CXX) -o $(BUILD)/testinternals $(METER_OBJS) $(BUILD)/testinternals.o $(LDFLAGS) -lrtlsdr $(USBLIB) -lpthread
|
2017-08-09 10:00:11 +00:00
|
|
|
|
2019-03-15 20:49:18 +00:00
|
|
|
$(BUILD)/fuzz: $(METER_OBJS) $(BUILD)/fuzz.o
|
2020-09-27 17:40:05 +00:00
|
|
|
$(CXX) -o $(BUILD)/fuzz $(METER_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/* *~
|
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
|
2020-01-17 15:13:02 +00:00
|
|
|
$(GCOV) -o build_debug $(METER_OBJS)
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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:
|
|
|
|
@cat simulations/simulation_* | grep "^telegram=" | tr -d '|' | sed 's/^telegram=//' > $(BUILD)/seeds
|
|
|
|
@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
|
|
|
|
|
2019-03-15 12:59:26 +00:00
|
|
|
# Include dependency information generated by gcc in a previous compile.
|
|
|
|
include $(wildcard $(patsubst %.o,%.d,$(METER_OBJS)))
|