From b812365d1ade1c86284851fe97416c74552a293d Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Thu, 22 Sep 2022 21:33:41 +0100 Subject: [PATCH 1/7] Respect LDFLAGS variable when building --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f2b9a41..08ad6b8 100644 --- a/Makefile +++ b/Makefile @@ -80,11 +80,11 @@ CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" all: $(TARGETS) ot-recorder: recorder.o $(OTR_OBJS) $(OTR_EXTRA_OBJS) - $(CC) $(CFLAGS) -o ot-recorder recorder.o $(OTR_OBJS) $(OTR_EXTRA_OBJS) $(LIBS) + $(CC) $(CFLAGS) $(LDFLAGS) -o ot-recorder recorder.o $(OTR_OBJS) $(OTR_EXTRA_OBJS) $(LIBS) if test -r codesign.sh; then /bin/sh codesign.sh; fi ocat: ocat.o $(OTR_OBJS) - $(CC) $(CFLAGS) -o ocat ocat.o $(OTR_OBJS) $(LIBS) + $(CC) $(CFLAGS) $(LDFLAGS) -o ocat ocat.o $(OTR_OBJS) $(LIBS) $(OTR_OBJS): config.mk Makefile From 5ca1924ace0aebe3964e7109b2d6d674be1475bd Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Thu, 22 Sep 2022 21:37:41 +0100 Subject: [PATCH 2/7] Respect PKG_CONFIG variable when building This is particularly useful in cross-compile situations, where a wrapper around pkg-config is sometimes needed. --- Makefile | 2 ++ config.mk.in | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 08ad6b8..97461f6 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,8 @@ TARGETS += ot-recorder ocat GIT_VERSION := $(shell git describe --long --abbrev=10 --dirty --tags 2>/dev/null || echo "tarball") CFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\" +PKG_CONFIG ?= pkg-config + all: $(TARGETS) ot-recorder: recorder.o $(OTR_OBJS) $(OTR_EXTRA_OBJS) diff --git a/config.mk.in b/config.mk.in index 6fd674d..1243b69 100644 --- a/config.mk.in +++ b/config.mk.in @@ -105,8 +105,8 @@ GEOCODE_TIMEOUT = 4000 # and in particular could require you to add the lua+version (e.g lua-5.2) # to both pkg-config invocations -LUA_CFLAGS = `pkg-config --cflags lua` -LUA_LIBS = `pkg-config --libs lua` +LUA_CFLAGS = `$(PKG_CONFIG) --cflags lua` +LUA_LIBS = `$(PKG_CONFIG) --libs lua` -SODIUM_CFLAGS = `pkg-config --cflags libsodium` -SODIUM_LIBS = `pkg-config --libs libsodium` +SODIUM_CFLAGS = `$(PKG_CONFIG) --cflags libsodium` +SODIUM_LIBS = `$(PKG_CONFIG) --libs libsodium` From cac1b95be0e50e668d217a066f278d2e11fc9209 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Thu, 22 Sep 2022 22:29:55 +0100 Subject: [PATCH 3/7] Automatically detect when -luuid is needed (on Linux with tours enabled) This is done in a cross-compile-friendly manner with cpp rather than uname. printf is used rather than echo due to inconsistent handling of the -e option across different shells. --- Makefile | 14 ++++++++++++++ config.mk.in | 6 +----- etc/centos/config.mk.in | 1 - etc/debian/config.mk.in | 1 - etc/raspbian/config.mk.in | 1 - 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 97461f6..9a1612c 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,14 @@ CFLAGS += -DGHASHPREC=$(GHASHPREC) LIBS += -llmdb LIBS += -lpthread +define CPP_CONDITION +printf '#if $(1) \n +true \n +#else \n +#error false \n +#endif' | $(CPP) -P - >/dev/null 2>&1 && echo yes +endef + ifeq ($(WITH_MQTT),yes) CFLAGS += -DWITH_MQTT=1 CFLAGS += $(MOSQUITTO_INC) @@ -56,6 +64,12 @@ endif ifeq ($(WITH_TOURS),yes) CFLAGS += -DWITH_TOURS OTR_EXTRA_OBJS += + + # Debian requires uuid-dev + # RHEL/CentOS needs libuuid-devel + ifeq ($(shell $(call CPP_CONDITION,__linux__)),yes) + LIBS += -luuid + endif endif ifeq ($(WITH_GREENWICH),yes) diff --git a/config.mk.in b/config.mk.in index 1243b69..cba2d10 100644 --- a/config.mk.in +++ b/config.mk.in @@ -40,7 +40,7 @@ WITH_MQTT ?= yes WITH_HTTP ?= yes # Do you want recorder support for shared views? Requires WITH_HTTP -# also requires -luuid on Linux (see below at MORELIBS) +# also requires -luuid on Linux. WITH_TOURS ?= yes # Do you have Lua libraries installed and want the Lua hook integration? @@ -93,10 +93,6 @@ CONFIGFILE = /etc/default/ot-recorder MOSQUITTO_INC = -I/usr/include MOSQUITTO_LIB = -L/usr/lib -# Debian requires uuid-dev -# RHEL/CentOS needs libuuid-devel -MORELIBS += -luuid # -lssl - # Milliseconds (ms) timeout for reverse geocoding GEOCODE_TIMEOUT = 4000 diff --git a/etc/centos/config.mk.in b/etc/centos/config.mk.in index 3d552db..b224bf3 100644 --- a/etc/centos/config.mk.in +++ b/etc/centos/config.mk.in @@ -19,7 +19,6 @@ GHASHPREC = 7 JSON_INDENT ?= no MOSQUITTO_INC = -I/usr/include MOSQUITTO_LIB = -L/usr/lib -MORELIBS = -luuid # -lssl LUA_CFLAGS = `pkg-config --cflags lua` LUA_LIBS = `pkg-config --libs lua` diff --git a/etc/debian/config.mk.in b/etc/debian/config.mk.in index 8e4cc1a..4cd128a 100644 --- a/etc/debian/config.mk.in +++ b/etc/debian/config.mk.in @@ -19,7 +19,6 @@ GHASHPREC = 7 JSON_INDENT ?= no MOSQUITTO_INC = -I/usr/include MOSQUITTO_LIB = -L/usr/lib -MORELIBS = -luuid # -lssl LUA_CFLAGS = `pkg-config --cflags lua` LUA_LIBS = `pkg-config --libs lua` SODIUM_CFLAGS = `pkg-config --cflags libsodium` diff --git a/etc/raspbian/config.mk.in b/etc/raspbian/config.mk.in index eefece1..dd9926c 100644 --- a/etc/raspbian/config.mk.in +++ b/etc/raspbian/config.mk.in @@ -20,7 +20,6 @@ GHASHPREC = 7 JSON_INDENT ?= no MOSQUITTO_INC = -I/usr/include MOSQUITTO_LIB = -L/usr/lib -MORELIBS = -luuid # -lssl LUA_CFLAGS = `pkg-config --cflags lua` LUA_LIBS = `pkg-config --libs lua` From 0439a9e667e90264d976a36291e2713998758da7 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Thu, 22 Sep 2022 22:45:26 +0100 Subject: [PATCH 4/7] Use Mosquitto's pkg-config file It has provided one since version 1.5. It erroneously hardcodes the libdir as "lib" (it may be lib64), but OwnTracks defaulted to "lib" anyway. I will fix Mosquitto shortly. --- Makefile | 4 ++-- config.mk.in | 4 ++-- etc/centos/config.mk.in | 4 ++-- etc/debian/config.mk.in | 4 ++-- etc/raspbian/config.mk.in | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 9a1612c..28ab45b 100644 --- a/Makefile +++ b/Makefile @@ -33,8 +33,8 @@ endef ifeq ($(WITH_MQTT),yes) CFLAGS += -DWITH_MQTT=1 - CFLAGS += $(MOSQUITTO_INC) - LIBS += $(MOSQUITTO_LIB) -lmosquitto -lm + CFLAGS += $(MOSQUITTO_CFLAGS) + LIBS += $(MOSQUITTO_LIBS) -lm endif ifeq ($(WITH_PING),yes) diff --git a/config.mk.in b/config.mk.in index cba2d10..9def768 100644 --- a/config.mk.in +++ b/config.mk.in @@ -90,8 +90,8 @@ JSON_INDENT ?= no CONFIGFILE = /etc/default/ot-recorder # Optionally specify the path to the Mosquitto libs, include here -MOSQUITTO_INC = -I/usr/include -MOSQUITTO_LIB = -L/usr/lib +MOSQUITTO_CFLAGS = `$(PKG_CONFIG) --cflags libmosquitto` +MOSQUITTO_LIBS = `$(PKG_CONFIG) --libs libmosquitto` # Milliseconds (ms) timeout for reverse geocoding GEOCODE_TIMEOUT = 4000 diff --git a/etc/centos/config.mk.in b/etc/centos/config.mk.in index b224bf3..61da631 100644 --- a/etc/centos/config.mk.in +++ b/etc/centos/config.mk.in @@ -17,8 +17,8 @@ STORAGEDEFAULT = /var/spool/owntracks/recorder/store DOCROOT = /var/spool/owntracks/recorder/htdocs GHASHPREC = 7 JSON_INDENT ?= no -MOSQUITTO_INC = -I/usr/include -MOSQUITTO_LIB = -L/usr/lib +MOSQUITTO_CFLAGS = +MOSQUITTO_LIBS = -lmosquitto LUA_CFLAGS = `pkg-config --cflags lua` LUA_LIBS = `pkg-config --libs lua` diff --git a/etc/debian/config.mk.in b/etc/debian/config.mk.in index 4cd128a..4bceabf 100644 --- a/etc/debian/config.mk.in +++ b/etc/debian/config.mk.in @@ -17,8 +17,8 @@ STORAGEDEFAULT = /var/spool/owntracks/recorder/store DOCROOT = /usr/share/owntracks/recorder/htdocs GHASHPREC = 7 JSON_INDENT ?= no -MOSQUITTO_INC = -I/usr/include -MOSQUITTO_LIB = -L/usr/lib +MOSQUITTO_CFLAGS = +MOSQUITTO_LIBS = -lmosquitto LUA_CFLAGS = `pkg-config --cflags lua` LUA_LIBS = `pkg-config --libs lua` SODIUM_CFLAGS = `pkg-config --cflags libsodium` diff --git a/etc/raspbian/config.mk.in b/etc/raspbian/config.mk.in index dd9926c..ebf3fd2 100644 --- a/etc/raspbian/config.mk.in +++ b/etc/raspbian/config.mk.in @@ -18,8 +18,8 @@ STORAGEDEFAULT = /var/spool/owntracks/recorder/store DOCROOT = /usr/share/owntracks/recorder/htdocs GHASHPREC = 7 JSON_INDENT ?= no -MOSQUITTO_INC = -I/usr/include -MOSQUITTO_LIB = -L/usr/lib +MOSQUITTO_CFLAGS = +MOSQUITTO_LIBS = -lmosquitto LUA_CFLAGS = `pkg-config --cflags lua` LUA_LIBS = `pkg-config --libs lua` From 8ae8df60fbed2e7fbfc3da0a714ee16bfd32ce9d Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Sun, 25 Sep 2022 14:56:00 +0100 Subject: [PATCH 5/7] Don't create the "last" storage subdirectory ot-record creates it automatically. Other directories are also created automatically, so we should be consistent here. Note that some package managers need special handling for empty directories at build time, but they don't care about directories created at runtime. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 28ab45b..ae5f67a 100644 --- a/Makefile +++ b/Makefile @@ -130,7 +130,7 @@ install: ot-recorder ocat mkdir -p $(DESTDIR)$(INSTALLDIR)/bin mkdir -p $(DESTDIR)$(INSTALLDIR)/sbin mkdir -p $(DESTDIR)$(DOCROOT) - mkdir -p $(DESTDIR)$(STORAGEDEFAULT)/last + mkdir -p $(DESTDIR)$(STORAGEDEFAULT) cp -R docroot/* $(DESTDIR)$(DOCROOT)/ install -m 0755 ot-recorder $(DESTDIR)$(INSTALLDIR)/sbin install -m 0755 ocat $(DESTDIR)$(INSTALLDIR)/bin From c350d8ca852a9bebc15c2097bbde2f0a115db664 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Sun, 25 Sep 2022 14:59:26 +0100 Subject: [PATCH 6/7] Don't build with -Werror by default As the Linux kernel experiment with this flag has shown, it's just a bad idea unless you regularly do development work on the project. Different compilers and compiler versions will emit different warnings, which will cause headaches for users. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ae5f67a..8bbe251 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ include config.mk -CFLAGS +=-Wall -Werror -DNS_ENABLE_IPV6 +CFLAGS += -Wall -DNS_ENABLE_IPV6 LIBS = $(MORELIBS) -lm LIBS += -lcurl -lconfig From f0c1c6fbd50839461d0a393526bd5bb66dd5a5f0 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Sun, 25 Sep 2022 15:48:58 +0100 Subject: [PATCH 7/7] Install docroot files with correct permissions, excluding .gitignore --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8bbe251..546dd58 100644 --- a/Makefile +++ b/Makefile @@ -131,7 +131,7 @@ install: ot-recorder ocat mkdir -p $(DESTDIR)$(INSTALLDIR)/sbin mkdir -p $(DESTDIR)$(DOCROOT) mkdir -p $(DESTDIR)$(STORAGEDEFAULT) - cp -R docroot/* $(DESTDIR)$(DOCROOT)/ + cd docroot && find ! -type d ! -name .gitignore -exec install -m0644 -D {} $(DESTDIR)$(DOCROOT)/{} \; install -m 0755 ot-recorder $(DESTDIR)$(INSTALLDIR)/sbin install -m 0755 ocat $(DESTDIR)$(INSTALLDIR)/bin mkdir -p `dirname $(DESTDIR)/$(CONFIGFILE)`