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 HOST=arm
DESTDIR?=/
ifeq "$(HOST)" "arm"
CXX=arm-linux-gnueabihf-g++
STRIP=arm-linux-gnueabihf-strip
STRIP?=arm-linux-gnueabihf-strip
BUILD=build_arm
DEBARCH=armhf
else
CXX=g++
STRIP=strip
STRIP?=strip
#--strip-unneeded --remove-section=.comment --remove-section=.note
BUILD=build
DEBARCH=amd64
@ -47,10 +49,10 @@ endif
$(shell mkdir -p $(BUILD))
COMMIT_HASH:=$(shell git log --pretty=format:'%H' -n 1)
TAG:=$(shell git describe --tags)
CHANGES:=$(shell git status -s | grep -v '?? ')
TAG_COMMIT_HASH:=$(shell git show-ref --tags | grep $(TAG) | cut -f 1 -d ' ')
COMMIT_HASH?=$(shell git log --pretty=format:'%H' -n 1)
TAG?=$(shell git describe --tags)
CHANGES?=$(shell git status -s | grep -v '?? ')
TAG_COMMIT_HASH?=$(shell git show-ref --tags | grep $(TAG) | cut -f 1 -d ' ')
ifeq ($(COMMIT),$(TAG_COMMIT))
# Exactly on the tagged commit. The version is the tag!
@ -81,7 +83,10 @@ endif
$(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)
$(CXX) $(CXXFLAGS) $< -c -E > $@.src
@ -139,7 +144,7 @@ all: $(BUILD)/wmbusmeters $(BUILD)/testinternals
dist: wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb
install: $(BUILD)/wmbusmeters
@./install.sh $(BUILD)/wmbusmeters /
@./install.sh $(BUILD)/wmbusmeters $(DESTDIR) $(EXTRA_INSTALL_OPTIONS)
uninstall:
@./uninstall.sh /
@ -162,7 +167,7 @@ wmbusmeters_$(DEBVERSION)_$(DEBARCH).deb:
$(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
echo 'R"MANUAL(' > $(BUILD)/short_manual.h
@ -172,10 +177,10 @@ $(BUILD)/short_manual.h: README.md
echo ')MANUAL";' >> $(BUILD)/short_manual.h
$(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
$(CXX) -o $(BUILD)/fuzz $(METER_OBJS) $(BUILD)/fuzz.o $(DEBUG_LDFLAGS) -lpthread
$(CXX) -o $(BUILD)/fuzz $(METER_OBJS) $(BUILD)/fuzz.o $(LDFLAGS) -lpthread
clean:
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
if [ -f "$ROOT"/etc/systemd/system/wmbusmeters.service ]
if [ -f "$ROOT"/lib/systemd/system/wmbusmeters.service ]
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
cp "$ROOT"/etc/systemd/system/wmbusmeters.service ~/old.wmbusmeters@.service.backup
rm "$ROOT"/etc/systemd/system/wmbusmeters.service
cp "$ROOT"/lib/systemd/system/wmbusmeters.service ~/old.wmbusmeters@.service.backup
rm "$ROOT"/lib/systemd/system/wmbusmeters.service
SYSTEMD_NEEDS_RELOAD=true
fi
if [ -f "$ROOT"/etc/systemd/system/wmbusmeters@.service ]
if [ -f "$ROOT"/lib/systemd/system/wmbusmeters@.service ]
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
cp "$ROOT"/etc/systemd/system/wmbusmeters@.service ~/old.wmbusmeters@.service.backup
rm "$ROOT"/etc/systemd/system/wmbusmeters@.service
cp "$ROOT"/lib/systemd/system/wmbusmeters@.service ~/old.wmbusmeters@.service.backup
rm "$ROOT"/lib/systemd/system/wmbusmeters@.service
SYSTEMD_NEEDS_RELOAD=true
fi
if [ ! -f "$ROOT"/etc/systemd/system/wmbusmeters@.service ]
if [ ! -f "$ROOT"/lib/systemd/system/wmbusmeters@.service ]
then
mkdir -p "$ROOT"/etc/systemd/system/
mkdir -p "$ROOT"/lib/systemd/system/
# Create service file
cat <<EOF > "$ROOT"/etc/systemd/system/wmbusmeters@.service
cat <<EOF > "$ROOT"/lib/systemd/system/wmbusmeters@.service
[Unit]
Description="wmbusmeters service on %I"
After=network.target
@ -265,9 +265,9 @@ PIDFile=/var/run/wmbusmeters/wmbusmeters-%i.pid
WantedBy=multi-user.target
EOF
echo systemd: installed "$ROOT"/etc/systemd/system/wmbusmeters@.service
echo systemd: installed "$ROOT"/lib/systemd/system/wmbusmeters@.service
else
echo systemd: "$ROOT"/etc/systemd/system/wmbusmeters@.service unchanged
echo systemd: "$ROOT"/lib/systemd/system/wmbusmeters@.service unchanged
fi
@ -308,7 +308,7 @@ fi
if [ "$SYSTEMD_NEEDS_RELOAD" = "true" ]
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" != "" ]
then
echo

Wyświetl plik

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