diff mbox series

[5/5] package/gpsd: add option to enable/disable the daemon

Message ID e6e9df5fad92d96444cebc9ebc8c137b83f929a6.1720535037.git.yann.morin@orange.com
State Accepted
Headers show
Series [1/5] package/gpsd: condition python stuff to the proper kconfig option | expand

Commit Message

Yann E. MORIN July 9, 2024, 2:24 p.m. UTC
From: "Yann E. MORIN" <yann.morin@orange.com>

Some scenarii, like building an RTK base, does not require a gpsd
daemon, but just a few python based tools (e.g. the python scripts
to configure a GNSS device).

Add an option to enable or disable building and instaling the daemon.
We make it enabled by default, for legacy purposes.

When the daemon is installed, it also installs a few ancillary helpers,
which need some of the clients (e.g. the udev rule will use gpsdctl), so
ensure they are enabled with the daemon.

Speaking of the udev rule: without the daemon, it does not need to be
installed, so only try to fix its mode when the daemomn is installed.

Similarly for systemd, no need to install the drop-in when the daemon is
not installed. And for sysv init, no need for a startup script without
the daemon either.

Now that everything is optional, daemon, clients, and python stuff, we
need to ensure that at least something is installed. The obvious
solution would be to ensure that the daemon is installed, but that
causes conflicts in the Kconfig depencies (elided for readability):

    config BR2_PACAKGE_GPSD
        bool "gpsd:
        select BR2_PACKAGE_GPSD_DAEMON if ! BR2_PACKAGE_GPSD_CLIENTS \
                                       && ! BR2_PACKAGE_GPSD_PYTHON

    config BR2_PACKAGE_GPSD_DAEMON
        bool "daemon"
        select BR2_PACKAGE_GPSD_CLIENTS

would cause errors like:

    package/gpsd/Config.in:27:error: recursive dependency detected!
    package/gpsd/Config.in:27:      symbol BR2_PACKAGE_GPSD_DAEMON is selected by BR2_PACKAGE_GPSD_CLIENTS
    package/gpsd/Config.in:226:     symbol BR2_PACKAGE_GPSD_CLIENTS is selected by BR2_PACKAGE_GPSD_DAEMON

So we chose the next best option: ensure that the clients get built, if
nothing else does.

Signed-off-by: Yann E. MORIN <yann.morin@orange.com>
Cc: Bernd Kuhls <bernd@kuhls.net>
---
 package/gpsd/Config.in | 13 +++++++++
 package/gpsd/gpsd.mk   | 62 ++++++++++++++++++++++++------------------
 2 files changed, 49 insertions(+), 26 deletions(-)

Comments

Jan Havran July 14, 2024, 9:42 p.m. UTC | #1
Hi,

V Tue, Jul 09, 2024 at 04:24:01PM +0200, yann.morin@orange.com napsal(a):
> From: "Yann E. MORIN" <yann.morin@orange.com>
> 
> Some scenarii, like building an RTK base, does not require a gpsd
> daemon, but just a few python based tools (e.g. the python scripts
> to configure a GNSS device).
> 
> Add an option to enable or disable building and instaling the daemon.
> We make it enabled by default, for legacy purposes.
> 
> When the daemon is installed, it also installs a few ancillary helpers,
> which need some of the clients (e.g. the udev rule will use gpsdctl), so
> ensure they are enabled with the daemon.
> 
> Speaking of the udev rule: without the daemon, it does not need to be
> installed, so only try to fix its mode when the daemomn is installed.
> 
> Similarly for systemd, no need to install the drop-in when the daemon is
> not installed. And for sysv init, no need for a startup script without
> the daemon either.
> 
> Now that everything is optional, daemon, clients, and python stuff, we
> need to ensure that at least something is installed. The obvious
> solution would be to ensure that the daemon is installed, but that
> causes conflicts in the Kconfig depencies (elided for readability):
> 
>     config BR2_PACAKGE_GPSD
>         bool "gpsd:
>         select BR2_PACKAGE_GPSD_DAEMON if ! BR2_PACKAGE_GPSD_CLIENTS \
>                                        && ! BR2_PACKAGE_GPSD_PYTHON
> 
>     config BR2_PACKAGE_GPSD_DAEMON
>         bool "daemon"
>         select BR2_PACKAGE_GPSD_CLIENTS
> 
> would cause errors like:
> 
>     package/gpsd/Config.in:27:error: recursive dependency detected!
>     package/gpsd/Config.in:27:      symbol BR2_PACKAGE_GPSD_DAEMON is selected by BR2_PACKAGE_GPSD_CLIENTS
>     package/gpsd/Config.in:226:     symbol BR2_PACKAGE_GPSD_CLIENTS is selected by BR2_PACKAGE_GPSD_DAEMON
> 
> So we chose the next best option: ensure that the clients get built, if
> nothing else does.
> 
> Signed-off-by: Yann E. MORIN <yann.morin@orange.com>
> Cc: Bernd Kuhls <bernd@kuhls.net>

Tested this with Raspberry Pi 0w with U-Blox module. First time I enabled
Python tools only (tested ubxtool), then the daemon with clients.

Looks good to me.

Reviewed-by: Jan Havran <havran.jan@email.cz>
Tested-by: Jan Havran <havran.jan@email.cz>

> ---
>  package/gpsd/Config.in | 13 +++++++++
>  package/gpsd/gpsd.mk   | 62 ++++++++++++++++++++++++------------------
>  2 files changed, 49 insertions(+), 26 deletions(-)
> 
> diff --git a/package/gpsd/Config.in b/package/gpsd/Config.in
> index cbdcdb5725..92a124b8ac 100644
> --- a/package/gpsd/Config.in
> +++ b/package/gpsd/Config.in
> @@ -9,6 +9,8 @@ menuconfig BR2_PACKAGE_GPSD
>  	depends on BR2_TOOLCHAIN_HAS_THREADS
>  	# Always tries to build a shared library
>  	depends on !BR2_STATIC_LIBS
> +	select BR2_PACKAGE_GPSD_CLIENTS if !BR2_PACKAGE_GPSD_DAEMON \
> +				       && !BR2_PACKAGE_GPSD_PYTHON
>  	help
>  	  gpsd is a service daemon that monitors one or more GPSes or
>  	  AIS receivers attached to a host computer through serial or
> @@ -22,6 +24,15 @@ menuconfig BR2_PACKAGE_GPSD
>  
>  if BR2_PACKAGE_GPSD
>  
> +config BR2_PACKAGE_GPSD_DAEMON
> +	bool "gpsd daemon"
> +	default y # legacy
> +	select BR2_PACKAGE_GPSD_CLIENTS
> +	help
> +	  Build and install the gpsd daemon itself
> +
> +if BR2_PACKAGE_GPSD_DAEMON
> +
>  config BR2_PACKAGE_GPSD_DEVICES
>  	string "Where to look for GPSes"
>  	default "/dev/ttyS1"
> @@ -210,6 +221,8 @@ config BR2_PACKAGE_GPSD_UBX
>  	help
>  	  uBlox UBX binary support
>  
> +endif  # GPSD_DAEMON
> +
>  config BR2_PACKAGE_GPSD_CLIENTS
>  	bool "gpsd clients"
>  	default y # legacy
> diff --git a/package/gpsd/gpsd.mk b/package/gpsd/gpsd.mk
> index 77c6f6c562..8f87766dcc 100644
> --- a/package/gpsd/gpsd.mk
> +++ b/package/gpsd/gpsd.mk
> @@ -26,8 +26,7 @@ GPSD_SCONS_OPTS = \
>  	prefix=/usr \
>  	sysroot=$(STAGING_DIR) \
>  	strip=no \
> -	qt=no \
> -	systemd=$(if $(BR2_INIT_SYSTEMD),yes,no)
> +	qt=no
>  
>  ifeq ($(BR2_PACKAGE_NCURSES),y)
>  GPSD_DEPENDENCIES += ncurses
> @@ -178,6 +177,40 @@ ifeq ($(BR2_PACKAGE_GPSD_MAX_DEV),y)
>  GPSD_SCONS_OPTS += max_devices=$(BR2_PACKAGE_GPSD_MAX_DEV_VALUE)
>  endif
>  
> +ifeq ($(BR2_PACKAGE_GPSD_DAEMON),y)
> +GPSD_SCONS_OPTS += \
> +	gpsd=yes \
> +	systemd=$(if $(BR2_INIT_SYSTEMD),yes,no)
> +
> +GPSD_INSTALL_RULE = $(if $(BR2_PACKAGE_HAS_UDEV),udev-install,install)
> +
> +# When using chrony, wait for after Buildroot's chrony.service
> +ifeq ($(BR2_PACKAGE_CHRONY),y)
> +define GPSD_INSTALL_INIT_SYSTEMD
> +	$(INSTALL) -D -m 0644 $(GPSD_PKGDIR)/br-chrony.conf \
> +		$(TARGET_DIR)/usr/lib/systemd/system/gpsd.service.d/br-chrony.conf
> +endef
> +endif
> +
> +define GPSD_INSTALL_INIT_SYSV
> +	$(INSTALL) -m 0755 -D package/gpsd/S50gpsd $(TARGET_DIR)/etc/init.d/S50gpsd
> +	$(SED) 's,^DEVICES=.*,DEVICES=$(BR2_PACKAGE_GPSD_DEVICES),' $(TARGET_DIR)/etc/init.d/S50gpsd
> +endef
> +
> +# After the udev rule is installed, make it writable so that this
> +# package can be re-built/re-installed.
> +ifeq ($(BR2_PACKAGE_HAS_UDEV),y)
> +define GPSD_INSTALL_UDEV_RULES
> +	chmod u+w $(TARGET_DIR)/lib/udev/rules.d/25-gpsd.rules
> +endef
> +GPSD_POST_INSTALL_TARGET_HOOKS += GPSD_INSTALL_UDEV_RULES
> +endif
> +
> +else # GPSD_DAEMON
> +GPSD_SCONS_OPTS += gpsd=no systemd=no
> +GPSD_INSTALL_RULE = install
> +endif
> +
>  ifeq ($(BR2_PACKAGE_GPSD_CLIENTS),y)
>  GPSD_SCONS_OPTS += gpsdclients=yes
>  else
> @@ -211,22 +244,9 @@ define GPSD_INSTALL_TARGET_CMDS
>  		DESTDIR=$(TARGET_DIR) \
>  		$(SCONS) \
>  		$(GPSD_SCONS_OPTS) \
> -		$(if $(BR2_PACKAGE_HAS_UDEV),udev-install,install))
> +		$(GPSD_INSTALL_RULE))
>  endef
>  
> -define GPSD_INSTALL_INIT_SYSV
> -	$(INSTALL) -m 0755 -D package/gpsd/S50gpsd $(TARGET_DIR)/etc/init.d/S50gpsd
> -	$(SED) 's,^DEVICES=.*,DEVICES=$(BR2_PACKAGE_GPSD_DEVICES),' $(TARGET_DIR)/etc/init.d/S50gpsd
> -endef
> -
> -# When using chrony, wait for after Buildroot's chrony.service
> -ifeq ($(BR2_PACKAGE_CHRONY),y)
> -define GPSD_INSTALL_INIT_SYSTEMD
> -	$(INSTALL) -D -m 0644 $(GPSD_PKGDIR)/br-chrony.conf \
> -		$(TARGET_DIR)/usr/lib/systemd/system/gpsd.service.d/br-chrony.conf
> -endef
> -endif
> -
>  define GPSD_INSTALL_STAGING_CMDS
>  	(cd $(@D); \
>  		$(GPSD_SCONS_ENV) \
> @@ -236,14 +256,4 @@ define GPSD_INSTALL_STAGING_CMDS
>  		install)
>  endef
>  
> -# After the udev rule is installed, make it writable so that this
> -# package can be re-built/re-installed.
> -ifeq ($(BR2_PACKAGE_HAS_UDEV),y)
> -define GPSD_INSTALL_UDEV_RULES
> -	chmod u+w $(TARGET_DIR)/lib/udev/rules.d/25-gpsd.rules
> -endef
> -
> -GPSD_POST_INSTALL_TARGET_HOOKS += GPSD_INSTALL_UDEV_RULES
> -endif
> -
>  $(eval $(generic-package))
diff mbox series

Patch

diff --git a/package/gpsd/Config.in b/package/gpsd/Config.in
index cbdcdb5725..92a124b8ac 100644
--- a/package/gpsd/Config.in
+++ b/package/gpsd/Config.in
@@ -9,6 +9,8 @@  menuconfig BR2_PACKAGE_GPSD
 	depends on BR2_TOOLCHAIN_HAS_THREADS
 	# Always tries to build a shared library
 	depends on !BR2_STATIC_LIBS
+	select BR2_PACKAGE_GPSD_CLIENTS if !BR2_PACKAGE_GPSD_DAEMON \
+				       && !BR2_PACKAGE_GPSD_PYTHON
 	help
 	  gpsd is a service daemon that monitors one or more GPSes or
 	  AIS receivers attached to a host computer through serial or
@@ -22,6 +24,15 @@  menuconfig BR2_PACKAGE_GPSD
 
 if BR2_PACKAGE_GPSD
 
+config BR2_PACKAGE_GPSD_DAEMON
+	bool "gpsd daemon"
+	default y # legacy
+	select BR2_PACKAGE_GPSD_CLIENTS
+	help
+	  Build and install the gpsd daemon itself
+
+if BR2_PACKAGE_GPSD_DAEMON
+
 config BR2_PACKAGE_GPSD_DEVICES
 	string "Where to look for GPSes"
 	default "/dev/ttyS1"
@@ -210,6 +221,8 @@  config BR2_PACKAGE_GPSD_UBX
 	help
 	  uBlox UBX binary support
 
+endif  # GPSD_DAEMON
+
 config BR2_PACKAGE_GPSD_CLIENTS
 	bool "gpsd clients"
 	default y # legacy
diff --git a/package/gpsd/gpsd.mk b/package/gpsd/gpsd.mk
index 77c6f6c562..8f87766dcc 100644
--- a/package/gpsd/gpsd.mk
+++ b/package/gpsd/gpsd.mk
@@ -26,8 +26,7 @@  GPSD_SCONS_OPTS = \
 	prefix=/usr \
 	sysroot=$(STAGING_DIR) \
 	strip=no \
-	qt=no \
-	systemd=$(if $(BR2_INIT_SYSTEMD),yes,no)
+	qt=no
 
 ifeq ($(BR2_PACKAGE_NCURSES),y)
 GPSD_DEPENDENCIES += ncurses
@@ -178,6 +177,40 @@  ifeq ($(BR2_PACKAGE_GPSD_MAX_DEV),y)
 GPSD_SCONS_OPTS += max_devices=$(BR2_PACKAGE_GPSD_MAX_DEV_VALUE)
 endif
 
+ifeq ($(BR2_PACKAGE_GPSD_DAEMON),y)
+GPSD_SCONS_OPTS += \
+	gpsd=yes \
+	systemd=$(if $(BR2_INIT_SYSTEMD),yes,no)
+
+GPSD_INSTALL_RULE = $(if $(BR2_PACKAGE_HAS_UDEV),udev-install,install)
+
+# When using chrony, wait for after Buildroot's chrony.service
+ifeq ($(BR2_PACKAGE_CHRONY),y)
+define GPSD_INSTALL_INIT_SYSTEMD
+	$(INSTALL) -D -m 0644 $(GPSD_PKGDIR)/br-chrony.conf \
+		$(TARGET_DIR)/usr/lib/systemd/system/gpsd.service.d/br-chrony.conf
+endef
+endif
+
+define GPSD_INSTALL_INIT_SYSV
+	$(INSTALL) -m 0755 -D package/gpsd/S50gpsd $(TARGET_DIR)/etc/init.d/S50gpsd
+	$(SED) 's,^DEVICES=.*,DEVICES=$(BR2_PACKAGE_GPSD_DEVICES),' $(TARGET_DIR)/etc/init.d/S50gpsd
+endef
+
+# After the udev rule is installed, make it writable so that this
+# package can be re-built/re-installed.
+ifeq ($(BR2_PACKAGE_HAS_UDEV),y)
+define GPSD_INSTALL_UDEV_RULES
+	chmod u+w $(TARGET_DIR)/lib/udev/rules.d/25-gpsd.rules
+endef
+GPSD_POST_INSTALL_TARGET_HOOKS += GPSD_INSTALL_UDEV_RULES
+endif
+
+else # GPSD_DAEMON
+GPSD_SCONS_OPTS += gpsd=no systemd=no
+GPSD_INSTALL_RULE = install
+endif
+
 ifeq ($(BR2_PACKAGE_GPSD_CLIENTS),y)
 GPSD_SCONS_OPTS += gpsdclients=yes
 else
@@ -211,22 +244,9 @@  define GPSD_INSTALL_TARGET_CMDS
 		DESTDIR=$(TARGET_DIR) \
 		$(SCONS) \
 		$(GPSD_SCONS_OPTS) \
-		$(if $(BR2_PACKAGE_HAS_UDEV),udev-install,install))
+		$(GPSD_INSTALL_RULE))
 endef
 
-define GPSD_INSTALL_INIT_SYSV
-	$(INSTALL) -m 0755 -D package/gpsd/S50gpsd $(TARGET_DIR)/etc/init.d/S50gpsd
-	$(SED) 's,^DEVICES=.*,DEVICES=$(BR2_PACKAGE_GPSD_DEVICES),' $(TARGET_DIR)/etc/init.d/S50gpsd
-endef
-
-# When using chrony, wait for after Buildroot's chrony.service
-ifeq ($(BR2_PACKAGE_CHRONY),y)
-define GPSD_INSTALL_INIT_SYSTEMD
-	$(INSTALL) -D -m 0644 $(GPSD_PKGDIR)/br-chrony.conf \
-		$(TARGET_DIR)/usr/lib/systemd/system/gpsd.service.d/br-chrony.conf
-endef
-endif
-
 define GPSD_INSTALL_STAGING_CMDS
 	(cd $(@D); \
 		$(GPSD_SCONS_ENV) \
@@ -236,14 +256,4 @@  define GPSD_INSTALL_STAGING_CMDS
 		install)
 endef
 
-# After the udev rule is installed, make it writable so that this
-# package can be re-built/re-installed.
-ifeq ($(BR2_PACKAGE_HAS_UDEV),y)
-define GPSD_INSTALL_UDEV_RULES
-	chmod u+w $(TARGET_DIR)/lib/udev/rules.d/25-gpsd.rules
-endef
-
-GPSD_POST_INSTALL_TARGET_HOOKS += GPSD_INSTALL_UDEV_RULES
-endif
-
 $(eval $(generic-package))