From 5b434b4e0ed6d1da8bac34c7daff8bd894abd674 Mon Sep 17 00:00:00 2001 From: Randy Jordan Date: Sun, 3 Nov 2024 15:22:36 -0600 Subject: [PATCH] Added c files --- c_dev/Makefile | 61 +++++++++++++++++++++++++++++++++++++++++++++++ c_dev/gitignore_c | 59 +++++++++++++++++++++++++++++++++++++++++++++ c_dev/main.c | 7 ++++++ 3 files changed, 127 insertions(+) create mode 100644 c_dev/Makefile create mode 100644 c_dev/gitignore_c create mode 100644 c_dev/main.c diff --git a/c_dev/Makefile b/c_dev/Makefile new file mode 100644 index 0000000..2b7d9da --- /dev/null +++ b/c_dev/Makefile @@ -0,0 +1,61 @@ +# Compiler Flags +CC := gcc +CFLAGS := -g -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined -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 + +# Target for compilation. +all: $(LIB) + +# Compiler Release Flags +release: CFLAGS := -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined -fno-omit-frame-pointer -O2 -DNDEBUG +release: clean $(LIB) + +# Dependancies +$(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. Parent folder is working dir, not test | bin. +test: $(LIB) $(TEST)/bin $(TESTBINS) + for test in $(TESTBINS); do ./$$test ; done + +clean: + $(RM) -r $(LIBDIR) $(OBJ) $(TEST)/bin/ diff --git a/c_dev/gitignore_c b/c_dev/gitignore_c new file mode 100644 index 0000000..966e230 --- /dev/null +++ b/c_dev/gitignore_c @@ -0,0 +1,59 @@ +# 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 + +# Ctags Folder +tags/ +/tags + +bin/ +/bin diff --git a/c_dev/main.c b/c_dev/main.c new file mode 100644 index 0000000..be8a7fc --- /dev/null +++ b/c_dev/main.c @@ -0,0 +1,7 @@ +#include +#include + +int main(int argc, char *argv[]){ + printf("There were %d arguments in %s\n", argc, argv[0]); + return EXIT_SUCCESS; +}