Initial commit
This commit is contained in:
21
LICENSE
Normal file
21
LICENSE
Normal 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
Makefile
Normal file
152
Makefile
Normal 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)
|
||||
61
README.md
Normal file
61
README.md
Normal file
@@ -0,0 +1,61 @@
|
||||
# ci2
|
||||
|
||||
## Description
|
||||
|
||||
C Interfaces and Implementations 2. Inspired by the [book](https://github.com/drh/cii),
|
||||
and others, this is my personal C codebase. I wanted to improve my C and DSA
|
||||
knowledge, and make some useful tools since C doesn't have many language
|
||||
features. I would like to make it cross-platform for unix and win32, so ci2 is
|
||||
the platform layer prefix.
|
||||
|
||||
|
||||
## 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
|
||||
|
||||
# Navigate into the directory
|
||||
cd ci2
|
||||
|
||||
# Build Project
|
||||
make
|
||||
|
||||
# Build project and run test suite.
|
||||
make test
|
||||
|
||||
# Build project and install / uninstall
|
||||
make install
|
||||
|
||||
make uninstall
|
||||
```
|
||||
|
||||
## Acknowledgments
|
||||
[C Interfaces and Implementations](https://github.com/drh/cii)<br>
|
||||
[Sean Barrett - Advice for Writing Small Programs in C](https://www.youtube.com/watch?v=eAhWIO1Ra6M)<br>
|
||||
[Eskil Steenberg - How I Program C](https://www.youtube.com/watch?v=443UNeGrFoM)<br>
|
||||
[Handmade Hero](https://www.youtube.com/playlist?list=PLnuhp3Xd9PYTt6svyQPyRO_AAuMWGxPzU)<br>
|
||||
[Mr. 4th Programming](https://www.youtube.com/playlist?list=PLT6InxK-XQvNKTyLXk6H6KKy12UYS_KDL)<br>
|
||||
[Chris Wellons](https://nullprogram.com/)<br>
|
||||
[Ginger Bill](https://www.gingerbill.org/)<br>
|
||||
[Tsoding Daily](https://www.youtube.com/@TsodingDaily)<br>
|
||||
[Jacob Sorber](https://www.youtube.com/channel/UCwd5VFu4KoJNjkWJZMFJGHQ)<br>
|
||||
[FFBase](https://github.com/stsaz/ffbase)<br>
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the MIT License - see the [MIT License](LICENSE) file for details.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user