From c588f3ae65c0af26e08b30d16916281c52fbaeb5 Mon Sep 17 00:00:00 2001 From: randomuser Date: Sun, 13 Nov 2022 16:03:55 +0000 Subject: [PATCH] migrate tstatus to an object-based compiliation format --- Makefile | 15 ++++++++++----- battery.c | 2 +- battery.h | 2 +- bspwm.h | 2 ++ datetime.c | 1 + datetime.h | 2 +- file.c | 3 +++ thermal.c | 3 ++- tstatus.c | 13 ++++++------- 9 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 8a94eca..ce23610 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,13 @@ -tstatus: - cc tstatus.c -o tstatus -lxcb -lasound -Wall -Wextra -std=c99 +CC = cc +CFLAGS = -Wall -Wextra -Wno-missing-field-initializers -std=c99 +LDFLAGS = -lxcb -lasound +OBJFILES = alsa.o battery.o bspwm.o datetime.o file.o thermal.o tstatus.o +TARGET = tstatus -debug: - cc tstatus.c -o tstatus -lxcb -Wall -Wextra -std=c99 -ggdb +all: $(TARGET) + +$(TARGET): $(OBJFILES) + $(CC) $(CFLAGS) -o $(TARGET) $(OBJFILES) $(LDFLAGS) clean: - rm tstatus + rm -f $(OBJFILES) $(TARGET) *~ diff --git a/battery.c b/battery.c index 1718fff..386fb7a 100644 --- a/battery.c +++ b/battery.c @@ -3,7 +3,7 @@ #include #include "module.h" -#include "file.c" +#include "file.h" #include "battery.h" int battery_update(struct module *module) { diff --git a/battery.h b/battery.h index 76bcdf2..1c636a1 100644 --- a/battery.h +++ b/battery.h @@ -13,7 +13,7 @@ #define BATTERY_PRE "/sys/class/power_supply/" #define BATTERY_CAP "/capacity" -int battery_module(struct module *module); +int battery_update(struct module *module); #endif #define TSTATUS_BATTERY_H diff --git a/bspwm.h b/bspwm.h index 2b78cab..20aa1b9 100644 --- a/bspwm.h +++ b/bspwm.h @@ -24,6 +24,8 @@ * modifications made by randomuser for use in tstatus */ +#define LENGTH(x) (sizeof(x) / sizeof(*x)) + #define RUNTIME_DIR_ENV "XDG_RUNTIME_DIR" #define SOCKET_PATH_TPL "/tmp/bspwm%s_%i_%i-socket" #define SOCKET_ENV_VAR "BSPWM_SOCKET" diff --git a/datetime.c b/datetime.c index 2f7fe27..4d0096f 100644 --- a/datetime.c +++ b/datetime.c @@ -2,6 +2,7 @@ #include #include +#include "module.h" #include "datetime.h" int datetime_update(struct module *module) { diff --git a/datetime.h b/datetime.h index 78eb8ba..dc2c8ca 100644 --- a/datetime.h +++ b/datetime.h @@ -1,7 +1,7 @@ /* see LICENSE file for details on license */ #ifndef TSTATUS_TIMEDATE_H -int timedate_update(struct module *module); +int datetime_update(struct module *module); #endif #define TSTATUS_TIMEDATE_H diff --git a/file.c b/file.c index 50c62e5..b519820 100644 --- a/file.c +++ b/file.c @@ -1,6 +1,9 @@ /* see LICENSE file for details on license */ #ifndef TSTATUS_FILE_C +#include +#include +#include #include "file.h" void populate_buffer(char *buffer, char pattern) { diff --git a/thermal.c b/thermal.c index 4f1999f..312706d 100644 --- a/thermal.c +++ b/thermal.c @@ -1,9 +1,10 @@ /* see LICENSE file for details on license */ #include +#include #include #include "module.h" -#include "file.c" +#include "file.h" #include "thermal.h" int convert_milli_to_reg(int millidegree) { diff --git a/tstatus.c b/tstatus.c index 4e16187..7dd7af9 100644 --- a/tstatus.c +++ b/tstatus.c @@ -1,14 +1,13 @@ /* see LICENSE file for details on license */ +#define _POSIX_C_SOURCE 2 #include -#define LENGTH(x) (sizeof(x) / sizeof(*x)) - #include "module.h" -#include "bspwm.c" -#include "battery.c" -#include "thermal.c" -#include "datetime.c" -#include "alsa.c" +#include "bspwm.h" +#include "battery.h" +#include "thermal.h" +#include "datetime.h" +#include "alsa.h" struct module table[] = { {0, 10, bspwm_update, {'\0'}},