]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Makefile.am: allow installing from separate build directory
authorLukas Rusak <lorusak@gmail.com>
Tue, 5 Jul 2022 22:12:14 +0000 (15:12 -0700)
committerLukas Rusak <lorusak@gmail.com>
Tue, 5 Jul 2022 22:22:10 +0000 (15:22 -0700)
Makefile.am

index 6054e284ca751326d63205d3b0b4a9df4dff32c1..a03a8689b5f66933085a4ea542f053dd934a317c 100644 (file)
@@ -199,59 +199,98 @@ shairport_sync_mpris_test_client_SOURCES = shairport-sync-mpris-test-client.c
 shairport_sync_mpris_test_client_LDADD = lib_mpris_interface.a
 endif
 
-install-exec-hook:
+if INSTALL_CONFIG_FILES
+
+configdir = $(sysconfdir)
+config_DATA = scripts/shairport-sync.conf
+
 if BUILD_FOR_LINUX
-DBUS_POLICY_DIR=$(DESTDIR)/etc/dbus-1/system.d
+dbusdir = /etc/dbus-1/system.d
 else
-DBUS_POLICY_DIR=$(DESTDIR)$(sysconfdir)/dbus-1/system.d
+dbusdir = $(sysconfdir)/dbus-1/system.d
 endif
-if INSTALL_CONFIG_FILES
-       [ -e $(DESTDIR)$(sysconfdir) ] || mkdir $(DESTDIR)$(sysconfdir)
-       cp scripts/shairport-sync.conf $(DESTDIR)$(sysconfdir)/shairport-sync.conf.sample
-       [ -f $(DESTDIR)$(sysconfdir)/shairport-sync.conf ] || cp scripts/shairport-sync.conf $(DESTDIR)$(sysconfdir)/shairport-sync.conf
+
 if USE_DBUS
-       [ -e $(DBUS_POLICY_DIR) ] || mkdir -p $(DBUS_POLICY_DIR)
+
 if INSTALL_CYGWIN_SERVICE
-       cp scripts/shairport-sync-dbus-policy-cygwin.conf $(DBUS_POLICY_DIR)/shairport-sync-dbus.conf
+dbus_DATA = scripts/shairport-sync-dbus-policy-cygwin.conf
 else
-       cp scripts/shairport-sync-dbus-policy.conf $(DBUS_POLICY_DIR)/shairport-sync-dbus.conf
-endif
-endif
+dbus_DATA = scripts/shairport-sync-dbus-policy.conf
+endif # INSTALL_CYGWIN_SERVIC
+
+endif # USE_DBUS
+
 if USE_MPRIS
-       [ -e $(DBUS_POLICY_DIR) ] || mkdir -p $(DBUS_POLICY_DIR)
+
+mprisdir = $(dbusdir)
+
 if INSTALL_CYGWIN_SERVICE
-       cp scripts/shairport-sync-mpris-policy-cygwin.conf $(DBUS_POLICY_DIR)/shairport-sync-mpris.conf
+mpris_DATA = scripts/shairport-sync-mpris-policy-cygwin.conf
 else
-       cp scripts/shairport-sync-mpris-policy.conf $(DBUS_POLICY_DIR)/shairport-sync-mpris.conf
-endif
-endif
-endif
-if INSTALL_SYSTEMV
+mpris_DATA = scripts/shairport-sync-mpris-policy.conf
+endif # INSTALL_CYGWIN_SERVICE
+
+endif # USE_MPRIS
+
+endif # INSTALL_CONFIG_FILES
+
+INSTALL_GROUP_TARGET = install-group-local
+
+$(INSTALL_GROUP_TARGET):
        getent group shairport-sync &>/dev/null || groupadd -r shairport-sync >/dev/null
+
+INSTALL_USER_TARGET = install-user-local
+
+$(INSTALL_USER_TARGET): $(INSTALL_GROUP_TARGET)
        getent passwd shairport-sync &> /dev/null || useradd -r -M -g shairport-sync -s /usr/sbin/nologin -G audio shairport-sync >/dev/null
-       [ -e $(DESTDIR)$(sysconfdir)/init.d ] || mkdir -p $(DESTDIR)$(sysconfdir)/init.d
-       [ -e $(DESTDIR)$(sysconfdir)/init.d/shairport-sync ] || cp scripts/shairport-sync $(DESTDIR)$(sysconfdir)/init.d/
-endif
+
+if INSTALL_SYSTEMV
+
+INSTALL_SYSTEMV_TARGET = install-systemv-local
+
+$(INSTALL_SYSTEMV_TARGET): scripts/shairport-sync $(INSTALL_USER_TARGET)
+       install -d $(DESTDIR)$(sysconfdir)/init.d
+       install -m 0644 $< $(DESTDIR)$(sysconfdir)/init.d
+
+endif # INSTALL_SYSTEMV
+
 if INSTALL_SYSTEMD
-       getent group shairport-sync &>/dev/null || groupadd -r shairport-sync >/dev/null
-       getent passwd shairport-sync &> /dev/null || useradd -r -M -g shairport-sync -s /usr/sbin/nologin -G audio shairport-sync >/dev/null
-       [ -e $(DESTDIR)$(systemdsystemunitdir) ] || mkdir -p $(DESTDIR)$(systemdsystemunitdir)
+
 if USE_AVAHI
-       [ -e $(DESTDIR)$(systemdsystemunitdir)/shairport-sync.service ] || cp scripts/shairport-sync.service-avahi $(DESTDIR)$(systemdsystemunitdir)/shairport-sync.service
+SYSTEMD_SERVICE = shairport-sync.service-avahi
 else
-       [ -e $(DESTDIR)$(systemdsystemunitdir)/shairport-sync.service ] || cp scripts/shairport-sync.service $(DESTDIR)$(systemdsystemunitdir)
-endif
-endif
+SYSTEMD_SERVICE = shairport-sync.service
+endif # USE_AVAHI
+
+INSTALL_SYSTEMD_TARGET = install-systemd-local
+
+$(INSTALL_SYSTEMD_TARGET): scripts/$(SYSTEMD_SERVICE) $(INSTALL_USER_TARGET)
+       install -d $(DESTDIR)$(systemdsystemunitdir)
+       install -m 0644 $< $(DESTDIR)$(systemdsystemunitdir)/shairport-sync.service
+
+endif # INSTALL_SYSTEMD
+
 if INSTALL_FREEBSD_SERVICE
-  # Choose a uid and gid of 801 completely arbitrarity, except that it should be below 1000. FreeBSD doesn't seem to allow you to say "an ID in the range of..."
+
+# Choose a uid and gid of 801 completely arbitrarity, except that it should be below 1000. FreeBSD doesn't seem to allow you to say "an ID in the range of..."
+install-freebsd-user-local:
        pw showgroup shairport-sync > /dev/null 2>&1 || pw addgroup -n shairport-sync -g 801 > /dev/null 2>&1
        pw showuser shairport-sync > /dev/null 2>&1 || pw adduser -c "shairport-sync unprivileged user" -n shairport-sync -u 801 -s /usr/sbin/nologin -d /nonexistent > /dev/null 2>&1
-       [ -e /var/run/shairport-sync ] || mkdir -p /var/run/shairport-sync
-       chown shairport-sync:shairport-sync /var/run/shairport-sync
-  # Always update the startup script -- this is different to the Linux systemd situation, where the startup script is untouched if it exists.
-       cp scripts/shairport-sync.freebsd /usr/local/etc/rc.d/shairport_sync
-       chmod 555 /usr/local/etc/rc.d/shairport_sync
-endif
+
+INSTALL_FREEBSD_TARGET = install-freebsd-local
+
+$(INSTALL_FREEBSD_TARGET): scripts/shairport-sync.freebsd install-freebsd-user-local
+       install -d -o shairport-sync -g shairport-sync $(DESTDIR)/var/run/shairport-sync
+       install -d $(DESTDIR)/usr/local/etc/rc.d/
+       install -m 0555 $< $(DESTDIR)/usr/local/etc/rc.d/shairport_sync
+
+endif # INSTALL_FREEBSD_SERVICE
+
 if INSTALL_CYGWIN_SERVICE
-       [ -e /usr/local/bin/shairport-sync-config ] || cp scripts/shairport-sync-config /usr/local/bin
-endif
+cygwindir = /usr/local/bin
+cygwin_DATA = scripts/shairport-sync-config
+endif # INSTALL_CYGWIN_SERVICE
+
+install-exec-hook: $(INSTALL_SYSTEMV_TARGET) \
+                   $(INSTALL_SYSTEMD_TARGET) \
+                   $(INSTALL_FREEBSD_TARGET)