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
This commit is contained in:
Robert Morrison 2023-12-30 17:52:38 +00:00
parent d700ffac51
commit 0385ff1446
Signed by: robert
GPG Key ID: 73E012EB3F4EC696
3 changed files with 30 additions and 20 deletions

View File

@ -1,21 +1,29 @@
# Define the variables for the compiler and the flags # Define the variables for the compiler and the flags
CC = gcc CC = gcc
CFLAGS = -Wall -g CFLAGS = -Wall -g -std=c99 -pedantic
# Define the libraries to link # Define the libraries to link
LIBS = -lsystemd -lbsd LIBS = -lsystemd -lbsd
# Define the source file and the output binary prefix = /usr/local
BIN = dexedrine exec_prefix = $(prefix)
SRC := $(BIN).c bindir = $(exec_prefix)/bin
dexpath = $(bindir)/dexedrine
.PHONY: all clean install
# Define the default rule to build the program # Define the default rule to build the program
all: $(BIN) all: dexedrine
# Define the rule to compile the source file # Define the rule to compile the source file
$(BIN): $(SRC) dexedrine: dexedrine.c dexedrine.h
$(CC) $(CFLAGS) $(SRC) -o $(BIN) $(LIBS) $(CC) $(CFLAGS) dexedrine.c -o dexedrine $(LIBS)
# Define the rule to clean the generated files # Define the rule to clean the generated files
clean: clean:
rm -f $(BIN) rm dexedrine
# Define how to install
install:
install dexedrine $(DESTDIR)$(dexpath)

View File

@ -1,15 +1,4 @@
#include <bsd/libutil.h> #include "dexedrine.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <systemd/sd-bus.h>
#include <unistd.h>
#include <linux/limits.h>
void handleSigs(int sig);
#define _cleanup_(f) __attribute__((cleanup(f)))
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
_cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;

13
dexedrine.h Normal file
View File

@ -0,0 +1,13 @@
#define _DEFAULT_SOURCE
#include <bsd/libutil.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <systemd/sd-bus.h>
#include <unistd.h>
#include <linux/limits.h>
void handleSigs(int sig);
#define _cleanup_(f) __attribute__((cleanup(f)))