Make easier to packaging wmbumeters for linux

Makefile:
 - Allow to disable stripping of executables as this prevents from
   properly creating debug information sub packages,

 - Don't invoke any git commands when building from released
   tarball. Moreover, when creating an rpm package with additional
   patches then the created git repository is the one in which rpm
   applies patches and not the original one.

 - Allow to pass CXXFLAGS and LDFLAGS as distributions requires all
   packages to be compiled with the same set of flags.

 - Support to override DESTDIR when installing files.

 - Allow to pass additional arguments (EXTRA_INSTALL_OPTION)
   for install.sh script from Makefile.

Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
pull/87/head
Damian Wrobel 2020-03-01 20:41:19 +01:00
rodzic 97c2c61f39
commit 7d74511dcb
3 zmienionych plików z 34 dodań i 29 usunięć

Wyświetl plik

@ -20,14 +20,16 @@
# make DEBUG=true # make DEBUG=true
# make DEBUG=true HOST=arm # make DEBUG=true HOST=arm
DESTDIR?=/
ifeq "$(HOST)" "arm" ifeq "$(HOST)" "arm"
CXX=arm-linux-gnueabihf-g++ CXX=arm-linux-gnueabihf-g++
STRIP=arm-linux-gnueabihf-strip STRIP?=arm-linux-gnueabihf-strip
BUILD=build_arm BUILD=build_arm
DEBARCH=armhf DEBARCH=armhf
else else
CXX=g++ CXX=g++
STRIP=strip STRIP?=strip
#--strip-unneeded --remove-section=.comment --remove-section=.note #--strip-unneeded --remove-section=.comment --remove-section=.note
BUILD=build BUILD=build
DEBARCH=amd64 DEBARCH=amd64
@ -47,10 +49,10 @@ endif
$(shell mkdir -p $(BUILD)) $(shell mkdir -p $(BUILD))
COMMIT_HASH:=$(shell git log --pretty=format:'%H' -n 1) COMMIT_HASH?=$(shell git log --pretty=format:'%H' -n 1)
TAG:=$(shell git describe --tags) TAG?=$(shell git describe --tags)
CHANGES:=$(shell git status -s | grep -v '?? ') CHANGES?=$(shell git status -s | grep -v '?? ')
TAG_COMMIT_HASH:=$(shell git show-ref --tags | grep $(TAG) | cut -f 1 -d ' ') TAG_COMMIT_HASH?=$(shell git show-ref --tags | grep $(TAG) | cut -f 1 -d ' ')
ifeq ($(COMMIT),$(TAG_COMMIT)) ifeq ($(COMMIT),$(TAG_COMMIT))
# Exactly on the tagged commit. The version is the tag! # Exactly on the tagged commit. The version is the tag!
@ -81,7 +83,10 @@ endif
$(info Building $(VERSION)) $(info Building $(VERSION))
CXXFLAGS := $(DEBUG_FLAGS) -fPIC -fmessage-length=0 -std=c++11 -Wall -Wno-unused-function -I$(BUILD) CXXFLAGS ?= $(DEBUG_FLAGS) -fPIC -fmessage-length=0 -std=c++11 -Wall -Wno-unused-function
CXXFLAGS += -I$(BUILD)
LDFLAGS ?= $(DEBUG_LDFLAGS)
$(BUILD)/%.o: src/%.cc $(wildcard src/%.h) $(BUILD)/%.o: src/%.cc $(wildcard src/%.h)
$(CXX) $(CXXFLAGS) $< -c -E > $@.src $(CXX) $(CXXFLAGS) $< -c -E > $@.src
@ -139,7 +144,7 @@ all: $(BUILD)/wmbusmeters $(BUILD)/testinternals
dist: wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb dist: wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb
install: $(BUILD)/wmbusmeters install: $(BUILD)/wmbusmeters
@./install.sh $(BUILD)/wmbusmeters / @./install.sh $(BUILD)/wmbusmeters $(DESTDIR) $(EXTRA_INSTALL_OPTIONS)
uninstall: uninstall:
@./uninstall.sh / @./uninstall.sh /
@ -162,7 +167,7 @@ wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb:
$(BUILD)/main.o: $(BUILD)/short_manual.h $(BUILD)/main.o: $(BUILD)/short_manual.h
$(BUILD)/wmbusmeters: $(METER_OBJS) $(BUILD)/main.o $(BUILD)/short_manual.h $(BUILD)/wmbusmeters: $(METER_OBJS) $(BUILD)/main.o $(BUILD)/short_manual.h
$(CXX) -o $(BUILD)/wmbusmeters $(METER_OBJS) $(BUILD)/main.o $(DEBUG_LDFLAGS) -lpthread $(CXX) -o $(BUILD)/wmbusmeters $(METER_OBJS) $(BUILD)/main.o $(LDFLAGS) -lpthread
$(BUILD)/short_manual.h: README.md $(BUILD)/short_manual.h: README.md
echo 'R"MANUAL(' > $(BUILD)/short_manual.h echo 'R"MANUAL(' > $(BUILD)/short_manual.h
@ -172,10 +177,10 @@ $(BUILD)/short_manual.h: README.md
echo ')MANUAL";' >> $(BUILD)/short_manual.h echo ')MANUAL";' >> $(BUILD)/short_manual.h
$(BUILD)/testinternals: $(METER_OBJS) $(BUILD)/testinternals.o $(BUILD)/testinternals: $(METER_OBJS) $(BUILD)/testinternals.o
$(CXX) -o $(BUILD)/testinternals $(METER_OBJS) $(BUILD)/testinternals.o $(DEBUG_LDFLAGS) -lpthread $(CXX) -o $(BUILD)/testinternals $(METER_OBJS) $(BUILD)/testinternals.o $(LDFLAGS) -lpthread
$(BUILD)/fuzz: $(METER_OBJS) $(BUILD)/fuzz.o $(BUILD)/fuzz: $(METER_OBJS) $(BUILD)/fuzz.o
$(CXX) -o $(BUILD)/fuzz $(METER_OBJS) $(BUILD)/fuzz.o $(DEBUG_LDFLAGS) -lpthread $(CXX) -o $(BUILD)/fuzz $(METER_OBJS) $(BUILD)/fuzz.o $(LDFLAGS) -lpthread
clean: clean:
rm -rf build/* build_arm/* build_debug/* build_arm_debug/* *~ rm -rf build/* build_arm/* build_debug/* build_arm_debug/* *~

Wyświetl plik

@ -205,34 +205,34 @@ fi
#################################################################### ####################################################################
## ##
## Create /etc/systemd/system/wmbusmeters.service ## Create /lib/systemd/system/wmbusmeters.service
## ##
SYSTEMD_NEEDS_RELOAD=false SYSTEMD_NEEDS_RELOAD=false
if [ -f "$ROOT"/etc/systemd/system/wmbusmeters.service ] if [ -f "$ROOT"/lib/systemd/system/wmbusmeters.service ]
then then
echo systemd: removing "$ROOT"/etc/systemd/system/wmbusmeters.service echo systemd: removing "$ROOT"/lib/systemd/system/wmbusmeters.service
echo systemd: backup stored here: ~/old.wmbusmeters.service.backup echo systemd: backup stored here: ~/old.wmbusmeters.service.backup
cp "$ROOT"/etc/systemd/system/wmbusmeters.service ~/old.wmbusmeters@.service.backup cp "$ROOT"/lib/systemd/system/wmbusmeters.service ~/old.wmbusmeters@.service.backup
rm "$ROOT"/etc/systemd/system/wmbusmeters.service rm "$ROOT"/lib/systemd/system/wmbusmeters.service
SYSTEMD_NEEDS_RELOAD=true SYSTEMD_NEEDS_RELOAD=true
fi fi
if [ -f "$ROOT"/etc/systemd/system/wmbusmeters@.service ] if [ -f "$ROOT"/lib/systemd/system/wmbusmeters@.service ]
then then
echo systemd: removing "$ROOT"/etc/systemd/system/wmbusmeters@.service echo systemd: removing "$ROOT"/lib/systemd/system/wmbusmeters@.service
echo systemd: backup stored here: ~/old.wmbusmeters@.service.backup echo systemd: backup stored here: ~/old.wmbusmeters@.service.backup
cp "$ROOT"/etc/systemd/system/wmbusmeters@.service ~/old.wmbusmeters@.service.backup cp "$ROOT"/lib/systemd/system/wmbusmeters@.service ~/old.wmbusmeters@.service.backup
rm "$ROOT"/etc/systemd/system/wmbusmeters@.service rm "$ROOT"/lib/systemd/system/wmbusmeters@.service
SYSTEMD_NEEDS_RELOAD=true SYSTEMD_NEEDS_RELOAD=true
fi fi
if [ ! -f "$ROOT"/etc/systemd/system/wmbusmeters@.service ] if [ ! -f "$ROOT"/lib/systemd/system/wmbusmeters@.service ]
then then
mkdir -p "$ROOT"/etc/systemd/system/ mkdir -p "$ROOT"/lib/systemd/system/
# Create service file # Create service file
cat <<EOF > "$ROOT"/etc/systemd/system/wmbusmeters@.service cat <<EOF > "$ROOT"/lib/systemd/system/wmbusmeters@.service
[Unit] [Unit]
Description="wmbusmeters service on %I" Description="wmbusmeters service on %I"
After=network.target After=network.target
@ -265,9 +265,9 @@ PIDFile=/var/run/wmbusmeters/wmbusmeters-%i.pid
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
echo systemd: installed "$ROOT"/etc/systemd/system/wmbusmeters@.service echo systemd: installed "$ROOT"/lib/systemd/system/wmbusmeters@.service
else else
echo systemd: "$ROOT"/etc/systemd/system/wmbusmeters@.service unchanged echo systemd: "$ROOT"/lib/systemd/system/wmbusmeters@.service unchanged
fi fi
@ -308,7 +308,7 @@ fi
if [ "$SYSTEMD_NEEDS_RELOAD" = "true" ] if [ "$SYSTEMD_NEEDS_RELOAD" = "true" ]
then then
D=$(diff "$ROOT"/etc/systemd/system/wmbusmeters@.service ~/old.wmbusmeters@.service.backup) D=$(diff "$ROOT"/lib/systemd/system/wmbusmeters@.service ~/old.wmbusmeters@.service.backup)
if [ "$D" != "" ] if [ "$D" != "" ]
then then
echo echo

Wyświetl plik

@ -52,10 +52,10 @@ then
echo conf dir: removed "$ROOT"/etc/wmbusmeters.d echo conf dir: removed "$ROOT"/etc/wmbusmeters.d
fi fi
if [ -f "$ROOT"/etc/systemd/system/wmbusmeters.service ] if [ -f "$ROOT"/lib/systemd/system/wmbusmeters.service ]
then then
rm "$ROOT"/etc/systemd/system/wmbusmeters.service rm "$ROOT"/lib/systemd/system/wmbusmeters.service
echo systemd: removed "$ROOT"/etc/systemd/system/wmbusmeters.service echo systemd: removed "$ROOT"/lib/systemd/system/wmbusmeters.service
fi fi
if [ -f "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules ] if [ -f "$ROOT"/etc/udev/rules.d/99-wmbus-usb-serial.rules ]