aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2017-01-05 16:30:50 +0100
committerGravatar Christian Hesse <mail@eworm.de>2017-01-05 16:30:50 +0100
commitf58f74d21a0555574158ab5ee8b331a4a38d36d5 (patch)
tree6b8030da0d47d782e1740f72cdae8b93209f394a
parentd5d5a4424fb0682ccf4ba4d0463755470dde6224 (diff)
downloadmpd-notification-f58f74d21a0555574158ab5ee8b331a4a38d36d5.tar.gz
mpd-notification-f58f74d21a0555574158ab5ee8b331a4a38d36d5.tar.zst
make systemd optional
-rw-r--r--Makefile5
-rw-r--r--mpd-notification.c8
-rw-r--r--mpd-notification.h2
3 files changed, 14 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index a557919..7e4492d 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,10 @@ RM := rm
# flags
CFLAGS += -std=c11 -O2 -fPIC -Wall -Werror
CFLAGS += -liniparser
-CFLAGS += $(shell pkg-config --cflags --libs libsystemd)
+CFLAGS_SYSTEMD := $(shell pkg-config --cflags --libs libsystemd 2>/dev/null)
+ifneq ($(CFLAGS_SYSTEMD),)
+CFLAGS += -DHAVE_SYSTEMD $(CFLAGS_SYSTEMD)
+endif
CFLAGS += $(shell pkg-config --cflags --libs libmpdclient)
CFLAGS += $(shell pkg-config --cflags --libs libnotify)
CFLAGS_LIBAV := $(shell pkg-config --cflags --libs libavformat libavutil 2>/dev/null)
diff --git a/mpd-notification.c b/mpd-notification.c
index 90ed110..4e78e2e 100644
--- a/mpd-notification.c
+++ b/mpd-notification.c
@@ -380,7 +380,9 @@ int main(int argc, char ** argv) {
signal(SIGUSR1, received_signal);
/* report ready to systemd */
+#ifdef HAVE_SYSTEMD
sd_notify(0, "READY=1\nSTATUS=Waiting for mpd event...");
+#endif
while (doexit == 0 && mpd_run_idle_mask(conn, MPD_IDLE_PLAYER)) {
mpd_command_list_begin(conn, true);
@@ -400,7 +402,9 @@ int main(int argc, char ** argv) {
if (title == NULL)
goto nonotification;
+#ifdef HAVE_SYSTEMD
sd_notifyf(0, "READY=1\nSTATUS=Playing: %s", title);
+#endif
/* initial allocation and string termination */
notifystr = strdup("");
@@ -441,10 +445,14 @@ int main(int argc, char ** argv) {
mpd_song_free(song);
} else if (state == MPD_STATE_PAUSE) {
notifystr = strdup(TEXT_PAUSE);
+#ifdef HAVE_SYSTEMD
sd_notify(0, "READY=1\nSTATUS=" TEXT_PAUSE);
+#endif
} else if (state == MPD_STATE_STOP) {
notifystr = strdup(TEXT_STOP);
+#ifdef HAVE_SYSTEMD
sd_notify(0, "READY=1\nSTATUS=" TEXT_STOP);
+#endif
} else
notifystr = strdup(TEXT_UNKNOWN);
diff --git a/mpd-notification.h b/mpd-notification.h
index 7927a5b..8e70abb 100644
--- a/mpd-notification.h
+++ b/mpd-notification.h
@@ -19,7 +19,9 @@
#include <unistd.h>
/* systemd headers */
+#ifdef HAVE_SYSTEMD
#include <systemd/sd-daemon.h>
+#endif
#include <iniparser.h>
#include <libnotify/notify.h>