From 0385ff1446fc6058bfdda46f6a73a58110ee5692 Mon Sep 17 00:00:00 2001 From: Robert Morrison Date: Sat, 30 Dec 2023 17:52:38 +0000 Subject: [PATCH] refactor: Use header file, and update makefile - Move the definitions and includes to a header file. - Modify the makefile to account for this - add install to makefile --- Makefile | 24 ++++++++++++++++-------- dexedrine.c | 13 +------------ dexedrine.h | 13 +++++++++++++ 3 files changed, 30 insertions(+), 20 deletions(-) create mode 100644 dexedrine.h diff --git a/Makefile b/Makefile index b1a4822..dd1e0bd 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,29 @@ # Define the variables for the compiler and the flags CC = gcc -CFLAGS = -Wall -g +CFLAGS = -Wall -g -std=c99 -pedantic # Define the libraries to link LIBS = -lsystemd -lbsd -# Define the source file and the output binary -BIN = dexedrine -SRC := $(BIN).c +prefix = /usr/local +exec_prefix = $(prefix) +bindir = $(exec_prefix)/bin +dexpath = $(bindir)/dexedrine + +.PHONY: all clean install # Define the default rule to build the program -all: $(BIN) +all: dexedrine # Define the rule to compile the source file -$(BIN): $(SRC) - $(CC) $(CFLAGS) $(SRC) -o $(BIN) $(LIBS) +dexedrine: dexedrine.c dexedrine.h + $(CC) $(CFLAGS) dexedrine.c -o dexedrine $(LIBS) # Define the rule to clean the generated files clean: - rm -f $(BIN) + rm dexedrine + +# Define how to install + +install: + install dexedrine $(DESTDIR)$(dexpath) diff --git a/dexedrine.c b/dexedrine.c index 044a148..ace608e 100644 --- a/dexedrine.c +++ b/dexedrine.c @@ -1,15 +1,4 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -void handleSigs(int sig); - -#define _cleanup_(f) __attribute__((cleanup(f))) +#include "dexedrine.h" int main(int argc, char *argv[]) { _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; diff --git a/dexedrine.h b/dexedrine.h new file mode 100644 index 0000000..d460290 --- /dev/null +++ b/dexedrine.h @@ -0,0 +1,13 @@ +#define _DEFAULT_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include + +void handleSigs(int sig); + +#define _cleanup_(f) __attribute__((cleanup(f)))