pca-in-c/Makefile
Ethan Smith-Coss 9fb5cefa08
C implementation of KLT
The committed files are a fully functioning implementation of the
Karhunen–Loève transform (KLT) as defined on Wikipedia, and verified
using multiple languages - Python, R and MATLAB. Note. It may be common
for libraries to call this algorithm 'covariance', 'eig' or similar to
distiguish from the SVD alogrithm or otherwise.

The source code is built entirely on the GNU GSL (2.7) library, to
utilise BLAS optimised functionality.
2025-05-30 23:30:35 +01:00

65 lines
1.5 KiB
Makefile

CC = gcc
INCLUDE_DIR = ./include
SOURCE_DIR = ./src
CFLAGS += -I$(INCLUDE_DIR) -ansi -std=c99
LIBS += -lgsl -lopenblas -lm
# Debug flags and release flags for GCC
ifeq ($(BUILD),release)
CFLAGS += -O2 -s -DNDEBUG
_BUILD_DIR = ./build/release
_OBJECT_DIR = ./obj/release
else
CFLAGS += -O0 -g
_BUILD_DIR = ./build/debug
_OBJECT_DIR = ./obj/debug
endif
# Check for required directories for GCC outputs
ifeq ($(wildcard $(OBJECT_DIR)/.),)
$(shell mkdir -p $(OBJECT_DIR))
endif
# Valgrind specific flags for debugging help
VALGRIND_ARGS += -s --leak-check=full --track-origins=yes \
--show-leak-kinds=all
# Get the system architecture if not specified
ifeq ($(ARCH),)
ARCH = $(shell uname -m)
BUILD_DIR = $(addsuffix $(ARCH), $(_BUILD_DIR)/)
OBJECT_DIR = $(addsuffix $(ARCH), $(_OBJECT_DIR)/)
endif
# Create directories if they don't exist
ifeq ($(wildcard $(BUILD_DIR)/.),)
$(shell mkdir -p $(BUILD_DIR))
endif
ifeq ($(wildcard $(OBJECT_DIR)/.),)
$(shell mkdir -p $(OBJECT_DIR))
endif
# Binary name for executable to compile
BINARY_NAME = main
# Source list files
SRC = pca matio
OBJ = $(patsubst %,$(OBJECT_DIR)/%.o,$(SRC) $(BINARY_NAME))
$(OBJECT_DIR)/%.o: $(SOURCE_DIR)/%.c
$(CC) -c -o $@ $< $(CFLAGS)
$(BUILD_DIR)/$(BINARY_NAME).$(ARCH): $(OBJ)
gcc -std=c99 $(CFLAGS) $(OBJ) $(LIBS) -o $(BUILD_DIR)/$(BINARY_NAME).$(ARCH)
.PHONY : release
release:
$(MAKE) "BUILD=release"
.PHONY : clean
clean:
rm -rf $(OBJECT_DIR)/*.o build
.PHONY : valgrind
valgrind:
valgrind $(VALGRIND_ARGS) $(BUILD_DIR)/$(BINARY_NAME).$(ARCH)