initial commit

This commit is contained in:
2026-06-05 18:27:10 -05:00
commit a111c1d67d
3 changed files with 231 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) [2026] [Randy Jordan]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+152
View File
@@ -0,0 +1,152 @@
# Compiler Flags
CC := gcc
CFLAGS := -g -Wall -Wextra -Werror -pedantic -fno-omit-frame-pointer
DEPFLAGS = -MMD -MP
# Directory Variables
LIBDIR := lib
OBJ := obj
INC := include
SRC := src
TEST := tests
# Install Paths (override with: make install PREFIX=/usr/local)
PREFIX ?= /usr/local
INSTALL_LIB = $(PREFIX)/lib
INSTALL_INC = $(PREFIX)/include
# Platform Detection and Library Linking
ifeq ($(OS), Windows_NT)
PLATFORM := win32
PLATFORM_SRCS := $(wildcard $(SRC)/win32_*.c)
PLATFORM_OBJS := $(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(PLATFORM_SRCS))
PLATFORM_FLAGS := -D WIN32
PLATFORM_LIBS := -mwindows
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
PLATFORM := linux
PLATFORM_SRCS := $(wildcard $(SRC)/linux_*.c)
PLATFORM_OBJS := $(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(PLATFORM_SRCS))
PLATFORM_FLAGS := -D LINUX
PLATFORM_LIBS := -lX11
else ifeq ($(UNAME_S), Darwin)
PLATFORM := mac
PLATFORM_SRCS := $(wildcard $(SRC)/mac_*.c)
PLATFORM_OBJS := $(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(PLATFORM_SRCS))
PLATFORM_FLAGS := -D MACOS
PLATFORM_LIBS :=
else
$(error Unsupported platform: $(UNAME_S))
endif
endif
# Add platform flags
CFLAGS += $(PLATFORM_FLAGS)
# Filepath Pattern Matching
LIB := $(LIBDIR)/lib.a
# Filter out ALL platform-prefixed files, then add back the correct platform's
SRCS := $(filter-out \
$(wildcard $(SRC)/win32_*.c) \
$(wildcard $(SRC)/linux_*.c) \
$(wildcard $(SRC)/macos_*.c), \
$(wildcard $(SRC)/*.c)) \
$(PLATFORM_SRCS)
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 install uninstall
# Compiler Release Flags (no sanitizers — those belong in CI/debug builds)
release: CFLAGS := -Wall -Wextra -Werror -pedantic -fno-omit-frame-pointer -O2 -DNDEBUG $(PLATFORM_FLAGS)
release: clean $(LIB)
@echo "\nRelease build complete for platform: $(PLATFORM)\n"
# Target for compilation
all: $(LIB)
@echo "\nBuilt for platform: $(PLATFORM)\n"
# Target / Dependencies
$(LIB): $(OBJS) | $(LIBDIR)
ar -cvrs $@ $^
# Compile with automatic dependency tracking
$(OBJ)/%.o: $(SRC)/%.c $(SRC)/%.h | $(OBJ)
$(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@
$(OBJ)/%.o: $(SRC)/%.c | $(OBJ)
$(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@
$(TEST)/bin/%: $(TEST)/%.c $(LIB) | $(TEST)/bin
$(CC) $(CFLAGS) $< $(LIB) $(PLATFORM_LIBS) -o $@
# Make directories if none
$(LIBDIR):
mkdir $@
$(OBJ):
mkdir $@
$(TEST)/bin:
mkdir -p $@
# Run the tests in the bin folder and track results
# Uses perl for nanosecond timing — portable across Linux and macOS
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=$$(perl -MTime::HiRes=time -e 'printf "%d\n", time()*1000'); \
if $$t; then \
RET=0; \
else \
RET=$$?; \
fi; \
END=$$(perl -MTime::HiRes=time -e 'printf "%d\n", time()*1000'); \
ELAPSED_MS=$$((END - START)); \
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
# Install library and public headers
install: $(LIB)
@echo "Installing to $(PREFIX)..."
install -d $(INSTALL_LIB)
install -d $(INSTALL_INC)
install -m 644 $(LIB) $(INSTALL_LIB)/
@if [ -d $(INC) ]; then \
install -m 644 $(INC)/*.h $(INSTALL_INC)/; \
echo "Installed headers from $(INC)/"; \
else \
echo "Warning: no $(INC)/ directory found — skipping header install"; \
fi
@echo "Install complete: lib -> $(INSTALL_LIB) headers -> $(INSTALL_INC)"
uninstall:
@echo "Removing installed files from $(PREFIX)..."
$(RM) $(INSTALL_LIB)/lib.a
@if [ -d $(INC) ]; then \
for h in $(INC)/*.h; do \
$(RM) $(INSTALL_INC)/$$(basename $$h); \
done; \
fi
@echo "Uninstall complete"
clean:
$(RM) -r $(LIBDIR) $(OBJ) $(TEST)/bin/
# Pull in generated dependency files (silently ignored if absent)
-include $(DEPS)
+58
View File
@@ -0,0 +1,58 @@
# ci2
## Description
Inspired by all in the acknowledgments, this is my own personal C codebase.
## Table of Contents
* [Features](#features)
* [Todos](#todos)
* [Usage](#usage)
* [Acknowledgments](#acknowledgments)
* [License](#license)
## Features
## Todos
## Usage
```bash
# Example installation
git clone https://myrepos.dev/Randy-Jordan/ci2.git
# Navigate into the directory
cd ci2
# Build the project
make
# Build and run tests.
make test
```
## Acknowledgments
[C Interfaces and Implementations](https://github.com/drh/cii)<br>
[Unix Networking Programming Sockets Networking API](https://www.amazon.com/Unix-Network-Programming-Sockets-Networking/dp/0131411551)<br>
[Advanced Programming in the UNIX Environment](https://www.amazon.com/Advanced-Programming-UNIX-Environment-3rd/dp/0321637739/146-5615695-5426958)<br>
[stsaz - ffsys](https://github.com/stsaz/ffsys)<br>
[nothings - stb](https://github.com/nothings/stb)<br>
[Sean Barret - Advice for writing small programs](https://youtu.be/eAhWIO1Ra6M)<br>
[Eskil Steenberg - How I program C](https://www.youtube.com/watch?v=443UNeGrFoM)<br>
[Ginger Bill](https://www.gingerbill.org/)<br>
[GingerGill gb](https://github.com/gingerBill/gb)<br>
[Chris Wellons](https://nullprogram.com/)<br>
[Skeeto - W64devkit](https://github.com/skeeto/w64devkit)<br>
[Mongoose Webserver](https://github.com/cesanta/mongoose)<br>
[Tsoding Daily](https://www.youtube.com/c/TsodingDaily)<br>
[Jacob Sorber](https://www.youtube.com/@JacobSorber)<br>
[Crafting Interpreters](https://craftinginterpreters.com/)<br>
## License
This project is licensed under the MIT License - see the [MIT License](LICENSE) file for details.