From d9d142a7ad0bade65b6f8b777259e203dc6d5301 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Thu, 10 Apr 2025 18:58:30 -0500 Subject: Overhaul makefile --- .gitignore | 3 ++- src/Makefile | 19 +++++++++---------- src/depend.sh | 14 ++++++++++++++ src/encryption.c | 3 +-- src/encryption.h | 2 +- src/shared.c | 4 ++-- 6 files changed, 29 insertions(+), 16 deletions(-) create mode 100755 src/depend.sh diff --git a/.gitignore b/.gitignore index 2bba462..72dbe73 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ bin/ *.o *test* *.enc -.vscode/ \ No newline at end of file +.vscode/ +*.dep \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index 53cd9fd..88c5344 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ CC = gcc -SHELL = /usr/bin/env -S bash +SHELL := bash # I need to get better at makefiles so I can write this in a way that isn't absolutely insane/stupid # RELEASE_CFLAGS := -O3 -fipa-pta -fipa-cp -fuse-linker-plugin -flto=auto @@ -9,24 +9,23 @@ CFLAGS = -std=c2x -Wall -Wextra -Wpedantic -pedantic-errors -fanalyzer -Wanalyze LDLIBS += $$(pkg-config --libs-only-l libsodium) LDFLAGS += $$(pkg-config --libs-only-L libsodium) -OBJECTS := $(patsubst %.c,%.o, $(wildcard *.c)) +SOURCES := $(wildcard *.c) +OBJECTS := $(patsubst %.c,%.o,$(SOURCES)) +DEPS := $(patsubst %.c,%.dep,$(SOURCES)) .PHONY: all c clean val .DELETE_ON_ERROR: +.ONESHELL: all: main main: main.o encryption.o shared.o ll.o arena.o - -$(OBJECTS): shared.h -ll.o: ll.c ll.h -main.o: main.c -arena.o: arena.c arena.h -shared.o: shared.c shared.h # Might as well put shared.h in here explicitly -encryption.o: encryption.c encryption.h +$(OBJECTS): %.o: %.dep +%.dep: %.c + ./depend.sh `dirname $*` $(CFLAGS) $*.c > $@ c clean: - -rm -rv main $(OBJECTS) $(wildcard *.test*) $(wildcard *.enc) + @-rm -rv main $(OBJECTS) $(DEPS) $(wildcard *.test*) $(wildcard *.enc) val: $(MAKE) all diff --git a/src/depend.sh b/src/depend.sh new file mode 100755 index 0000000..b6084b1 --- /dev/null +++ b/src/depend.sh @@ -0,0 +1,14 @@ +#!/bin/bash +DIR="$1" +shift 1 +case "$DIR" in + "" | ".") + gcc -MM -MG "$@" | sed -e "s@^\(.*\)\.o:@\1.d \1.o:@" + ;; + *) + gcc -MM -MG "$@" | sed -e "s@^\(.*\)\.o:@$DIR/\1.d $DIR/\1.o:@" + ;; +esac + +# Shamelessly stolen from Peter Miller's "Recursive Make Considered Harmful" + # https://web.archive.org/web/20250404190928/https://aegis.sourceforge.net/auug97.pdf \ No newline at end of file diff --git a/src/encryption.c b/src/encryption.c index 4ff37cc..3530eed 100644 --- a/src/encryption.c +++ b/src/encryption.c @@ -255,8 +255,7 @@ int decrypttofile(FILE *src, FILE *dst, const unsigned char key[crypto_secretstr int genpassword(char **str, unsigned int words) { // Early returns - if(words < 1) - return 0; + if(words < 1) {return 0;} #if ___VXGG___ALWAYS_CHECK_LIBSODIUM___ > 0 checksodium(); #endif diff --git a/src/encryption.h b/src/encryption.h index b02216f..f6c018c 100644 --- a/src/encryption.h +++ b/src/encryption.h @@ -32,7 +32,7 @@ void vxgg_setsodiumfailcb(const vxgg_naclfailcb cb, void *data); // Fuck reading from a file. Even if someone ran strings on the binary and got this they wouldn't be able to regenerate the key #define PASSWORD_WORDS (\ - (const char *[]){\ + (const char * const []){\ "the", "of", "to", "and", "for", "our", "their", "has", "in", "he", "a", "them", "that", "these", "by", "have", "we", \ "us", "people", "which", "all", "is", "with", "laws", "be", "are", "his", "states", "on", "they", "right", "it", "from", \ "government", "such", "among", "powers", "most", "an", "time", "should", "new", "as", "been", "colonies", "assent", \ diff --git a/src/shared.c b/src/shared.c index 093e766..bec0354 100644 --- a/src/shared.c +++ b/src/shared.c @@ -6,7 +6,7 @@ #include #include -static enum XALLOC_TYPE { +enum XALLOC_TYPE { XALLOC_INVAL, // Default when unset XALLOC_MALLOC, @@ -120,7 +120,7 @@ int rwbuf(char **str, unsigned long int initsize, int fd) { int wwbuf(int fd, const unsigned char *buf, int len) { int total = 0; int left = len; - int n; + int n = -1; while(total < len) { if((n = write(fd, buf + total, left)) < 0) -- cgit v1.2.3