chiark / gitweb /
Control libgpiod code with #ifdef.
authorBen Harris <bjh21@bjh21.me.uk>
Sat, 24 Nov 2018 11:12:03 +0000 (11:12 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sat, 8 Dec 2018 22:30:09 +0000 (22:30 +0000)
That way I can build on older Linux systems.

clunk.c

diff --git a/clunk.c b/clunk.c
index 868a5c8502266d127578fbfb5c524ea7ad848512..0637a71fbbf31dd0ac09f2dbc2d0fd6495522b63 100644 (file)
--- a/clunk.c
+++ b/clunk.c
@@ -3,7 +3,9 @@
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
+#ifdef WITH_LIBGPIOD
 #include <gpiod.h>
+#endif /* WITH_LIBGPIOD */
 #include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -64,6 +66,7 @@ dummy_out(bool state)
        }
 }
 
+#ifdef WITH_LIBGPIOD
 static struct gpiod_line *libgpiod_line;
 
 static void
@@ -73,6 +76,7 @@ libgpiod_out(bool state)
        if (gpiod_line_set_value(libgpiod_line, state) == -1)
                err(1, "gpiod_line_set_value");
 }
+#endif /* WITH_LIBGPIOD */
 
 static void (*outfn)(bool) = &dummy_out;
 
@@ -189,6 +193,7 @@ init_statefile(char const *statefilename)
        }
 }
 
+#ifdef WITH_LIBGPIOD
 static void
 init_libgpiod(char const *gpio_name)
 {
@@ -200,6 +205,7 @@ init_libgpiod(char const *gpio_name)
                err(1, "requesting '%s'", gpio_name);
        outfn = &libgpiod_out;
 }
+#endif /* WITH_LIBGPIOD */
 
 static void
 init(int argc, char **argv)
@@ -226,7 +232,11 @@ init(int argc, char **argv)
        if (timer_create(CLOCK_REALTIME, &sev, &main_timer) != 0)
                err(1, "timer_create");
 
-       while ((opt = getopt(argc, argv, "f:g:s:")) != -1) {
+       while ((opt = getopt(argc, argv, "f:s:"
+#ifdef WITH_LIBGPIOD
+                            "g:"
+#endif /* WITH_LIBGPIOD */
+                       )) != -1) {
                switch (opt) {
                case 'f':
                        statefile = optarg;
@@ -234,9 +244,11 @@ init(int argc, char **argv)
                case 's':
                        statestr = optarg;
                        break;
+#ifdef WITH_LIBGPIOD
                case 'g':
                        init_libgpiod(optarg);
                        break;
+#endif /* WITH_LIBGPIOD */
                }
        }
        if (statefile != NULL)