commit 6b1d09afdbdca560398c966b3ef612e442b590c7
parent 169af3960f151e84c88eceef641da58e73f2b3a7
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Tue, 13 Jul 2021 21:45:28 -0700
Add ap utility library for common functions
- Update the library structure to support multiple libraries
- Update TODO
Diffstat:
17 files changed, 66 insertions(+), 36 deletions(-)
diff --git a/TODO b/TODO
@@ -1,3 +1,2 @@
- Create a client library using functions from apc.c
-- Organize where functions are defined
-- Rename strutures where appropriate
+- Install library headers
diff --git a/apc/apc.c b/apc/apc.c
@@ -21,21 +21,14 @@
#include <errno.h>
#include <limits.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ap.h>
+#include <aputil.h>
#include "config.h"
-void
-die(char *s)
-{
- perror(s);
- exit(1);
-}
-
int
apc_send(struct apcon *c, char **argv)
{
diff --git a/apc/mkfile b/apc/mkfile
@@ -3,10 +3,11 @@
name = apc
src = apc.c
obj = ${src:%.c=%.o}
+lib = ap aputil
-cppflags = -I../lib
-ldflags = -L../lib
-ldlibs = -lap
+cppflags = ${lib:%=-I../lib/%}
+ldflags = ${lib:%=-L../lib/%}
+ldlibs = ${lib:%=-l%}
all:V: $name
diff --git a/aps/aps.c b/aps/aps.c
@@ -30,6 +30,8 @@
#include <unistd.h>
#endif
+#include <aputil.h>
+
#include "aps.h"
#include "command.h"
#include "config.h"
@@ -38,13 +40,6 @@
static struct aps aps;
void
-die(char *s)
-{
- perror(s);
- exit(1);
-}
-
-void
sigclose(int sig)
{
aps.close = 1;
diff --git a/aps/mkfile b/aps/mkfile
@@ -3,10 +3,11 @@
name = aps
src = aps.c buf.c command.c find.c item.c match.c player.c queue.c response.c split.c
obj = ${src:%.c=%.o}
+lib = ap aputil
-cppflags = -I../lib
-ldflags = -L../lib
-ldlibs = -lap
+cppflags = ${lib:%=-I../lib/%}
+ldflags = ${lib:%=-L../lib/%}
+ldlibs = ${lib:%=-l%}
all:V: $name
diff --git a/lib/ap.h b/lib/ap/ap.h
diff --git a/lib/apcon.c b/lib/ap/apcon.c
diff --git a/lib/apcon.h b/lib/ap/apcon.h
diff --git a/lib/ap/mkfile b/lib/ap/mkfile
@@ -0,0 +1,12 @@
+# Copyright 2021 Jacob R. Edwards
+
+name = libap.a
+src = apcon.c sock.c
+obj = ${src:%.c=%.o}
+
+all:V: $name
+
+< ../../mk/config.mk
+< ../../mk/clean.mk
+< ../../mk/obj.mk
+< ../../mk/lib.mk
diff --git a/lib/sock.c b/lib/ap/sock.c
diff --git a/lib/sock.h b/lib/ap/sock.h
diff --git a/lib/aputil/aputil.h b/lib/aputil/aputil.h
@@ -0,0 +1 @@
+#include "die.h"
diff --git a/lib/aputil/die.c b/lib/aputil/die.c
@@ -0,0 +1,27 @@
+/* Copyright 2021 Jacob R. Edwards
+ *
+ * ap -- audio player
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+void
+die(char *s)
+{
+ perror(s);
+ exit(1);
+}
diff --git a/lib/aputil/die.h b/lib/aputil/die.h
@@ -0,0 +1 @@
+void die(char *);
diff --git a/lib/aputil/mkfile b/lib/aputil/mkfile
@@ -0,0 +1,12 @@
+# Copyright 2021 Jacob R. Edwards
+
+name = libaputil.a
+src = die.c
+obj = ${src:%.c=%.o}
+
+all:V: $name
+
+< ../../mk/config.mk
+< ../../mk/clean.mk
+< ../../mk/obj.mk
+< ../../mk/lib.mk
diff --git a/lib/mkfile b/lib/mkfile
@@ -1,12 +0,0 @@
-# Copyright 2021 Jacob R. Edwards
-
-name = libap.a
-src = apcon.c sock.c
-obj = ${src:%.c=%.o}
-
-all:V: $name
-
-< ../mk/config.mk
-< ../mk/clean.mk
-< ../mk/obj.mk
-< ../mk/lib.mk
diff --git a/mkfile b/mkfile
@@ -1,6 +1,6 @@
# Copyright 2021 Jacob R. Edwards
-subdirs = lib aps apc
+subdirs = lib/ap lib/aputil aps apc
targets = all install uninstall clean
all:V: