From 307493b3f1b72f5eaf45ce2a79fb8eb9ad2cb4a5 Mon Sep 17 00:00:00 2001 From: Randy Jordan Date: Wed, 15 Apr 2026 10:02:20 -0500 Subject: [PATCH] Makefile and main template --- README.md | 5 ++- c_dev/C.gitignore | 58 ++++++++++++++++++++++++++++++++ c_dev/Makefile | 85 +++++++++++++++++++++++++++++++++++++++++++++++ c_dev/main.c | 11 ++++++ 4 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 c_dev/C.gitignore create mode 100644 c_dev/Makefile create mode 100644 c_dev/main.c diff --git a/README.md b/README.md index 9d6ea12..1e36412 100644 --- a/README.md +++ b/README.md @@ -28,10 +28,9 @@ you can use the dropdown menu to easily create files. ## Todos -* [ ] Add new feature X +* [ ] Simple Makefile * [ ] Improve documentation -* [ ] Write tests -* [ ] Optimize performance + --- diff --git a/c_dev/C.gitignore b/c_dev/C.gitignore new file mode 100644 index 0000000..a2cc4a3 --- /dev/null +++ b/c_dev/C.gitignore @@ -0,0 +1,58 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +# debug information files +*.dwo + +#ctags +/tags diff --git a/c_dev/Makefile b/c_dev/Makefile new file mode 100644 index 0000000..f1b409e --- /dev/null +++ b/c_dev/Makefile @@ -0,0 +1,85 @@ +# Compiler Flags +CC := gcc +CFLAGS := -g -Wall -Wextra -Werror -pedantic -fno-omit-frame-pointer + +# Directory variables +LIBDIR := lib +OBJ := obj +INC := include +SRC := src +TEST := tests + +# Filepath Pattern Matching +LIB := $(LIBDIR)/lib.a +SRCS := $(wildcard $(SRC)/*.c) +OBJS := $(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SRCS)) +TESTS := $(wildcard $(TEST)/*.c) +TESTBINS := $(patsubst $(TEST)/%.c, $(TEST)/bin/%, $(TESTS)) + +# Commands must be labeled PHONY +.PHONY: all release clean test + +# Compiler Release Flags +release: CFLAGS := -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined -fno-omit-frame-pointer -O2 -DNDEBUG +release: clean $(LIB) + +# Target for compilation. +all: $(LIB) + +# Target / Dependencies +$(LIB): $(OBJS) | $(LIBDIR) + $(RM) $(LIB) + ar -cvrs $@ $^ + +$(OBJ)/%.o: $(SRC)/%.c $(SRC)/%.h | $(OBJ) + $(CC) $(CFLAGS) -c $< -o $@ + +$(OBJ)/%.o: $(SRC)/%.c | $(OBJ) + $(CC) $(CFLAGS) -c $< -o $@ + +$(TEST)/bin/%: $(TEST)/%.c $(LIB) | $(TEST)/bin + $(CC) $(CFLAGS) $< $(LIB) -o $@ + +# Make directories if none. +$(LIBDIR): + mkdir $@ + +$(INC): + mkdir $@ + +$(OBJ): + mkdir $@ + +$(TEST)/bin: + mkdir $@ + +# Run the tests in the bin folder and track results +test: $(LIB) $(TESTBINS) + @SUCCESS=0; FAILURE=0; \ + RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'; \ + for t in $(TESTBINS); do \ + NAME=$$(basename $$t); \ + START=$$(date +%s%N); \ + if $$t; then \ + RET=0; \ + else \ + RET=$$?; \ + fi; \ + END=$$(date +%s%N); \ + ELAPSED_NS=$$((END - START)); \ + ELAPSED_MS=$$((ELAPSED_NS / 1000000)); \ + if [ $$RET -eq 0 ]; then \ + printf "%-20s %bPASS%b (%b%4d ms%b)\n" "$$NAME" "$$GREEN" "$$NC" "$$YELLOW" "$$ELAPSED_MS" "$$NC"; \ + SUCCESS=$$((SUCCESS + 1)); \ + else \ + printf "%-20s %bFAIL%b (%b%4d ms%b)\n" "$$NAME" "$$RED" "$$NC" "$$YELLOW" "$$ELAPSED_MS" "$$NC"; \ + FAILURE=$$((FAILURE + 1)); \ + fi; \ + done; \ + printf "\nTests completed\n"; \ + printf "SUCCESS: %b%d%b\n" "$$GREEN" "$$SUCCESS" "$$NC"; \ + printf "FAILURE: %b%d%b\n" "$$RED" "$$FAILURE" "$$NC"; \ + test $$FAILURE -eq 0 + +clean: + $(RM) -r $(LIBDIR) $(OBJ) $(TEST)/bin/ diff --git a/c_dev/main.c b/c_dev/main.c new file mode 100644 index 0000000..2dc650c --- /dev/null +++ b/c_dev/main.c @@ -0,0 +1,11 @@ +#define DEBUG +#include "../include/template.h" + +#include +#include + +int main(int argc, char *argv[]){ + (void) argc; + (void) argv; + return EXIT_SUCCESS; +}