2023-01-05 19:28:05 +01:00
|
|
|
LIBRARY_NAME = libcproject
|
|
|
|
CC = gcc
|
|
|
|
CC_FLAGS = -Wall -Wextra -Wfloat-equal -Wundef -Werror -std=c17 -pedantic -pedantic-errors -I./
|
2023-01-05 21:13:10 +01:00
|
|
|
LIB = ./build/${LIBRARY_NAME}.a
|
|
|
|
LIB_CC_FLAGS = -L. -l:${LIB}
|
2023-01-05 19:28:05 +01:00
|
|
|
LIB_SOURCES = $(wildcard lib/*.c)
|
2023-01-06 17:37:50 +01:00
|
|
|
LIB_OBJECTS = $(patsubst %.c, %.o, $(LIB_SOURCES))
|
2023-01-05 19:28:05 +01:00
|
|
|
TEST_SOURCES = $(wildcard test/*.c)
|
2023-01-06 17:37:50 +01:00
|
|
|
TEST_OBJECTS = $(patsubst %.c, %.o, $(TEST_SOURCES))
|
2023-01-05 19:28:05 +01:00
|
|
|
HEADER_FILES = $(wildcard lib/*.h) $(wildcard test/*.h) ./${LIBRARY_NAME}.h
|
|
|
|
MAIN_EXECUTABLE = bin/main.exe
|
2023-01-05 21:13:10 +01:00
|
|
|
SET_VERSION_EXECUTABLE = bin/set_version.exe
|
2023-01-05 19:28:05 +01:00
|
|
|
TEST_EXECUTABLE = bin/test.exe
|
|
|
|
|
2023-01-06 17:37:50 +01:00
|
|
|
${LIB}: $(addprefix build/, ${LIB_OBJECTS})
|
2023-01-05 21:13:10 +01:00
|
|
|
rm --force ${LIB}
|
2023-01-06 17:37:50 +01:00
|
|
|
ar -rcs ${LIB} $(addprefix build/, ${LIB_OBJECTS})
|
2023-01-05 19:28:05 +01:00
|
|
|
|
2023-01-07 18:57:14 +01:00
|
|
|
build/lib:
|
|
|
|
mkdir --parents ./build/lib
|
|
|
|
|
|
|
|
build/test:
|
|
|
|
mkdir --parents ./build/test
|
|
|
|
|
|
|
|
build/lib/%.o: lib/%.c ${HEADER_FILES} | build/lib
|
|
|
|
${CC} ${CC_FLAGS} -c $< -o $@
|
|
|
|
|
|
|
|
build/test/%.o: test/%.c ${HEADER_FILES} | build/test
|
|
|
|
${CC} ${CC_FLAGS} -c $< -o $@
|
|
|
|
|
2023-01-05 19:28:05 +01:00
|
|
|
.PHONY: run
|
2023-01-06 17:37:50 +01:00
|
|
|
run: ${LIB} ./main.c
|
2023-01-05 19:28:05 +01:00
|
|
|
mkdir --parents ./bin
|
|
|
|
${CC} ${CC_FLAGS} -o ${MAIN_EXECUTABLE} ./main.c ${LIB_CC_FLAGS}
|
|
|
|
./${MAIN_EXECUTABLE} ${ARGS}
|
|
|
|
|
2023-01-05 21:13:10 +01:00
|
|
|
.PHONY: set_version
|
2023-01-06 17:37:50 +01:00
|
|
|
set_version: ${LIB} ./set_version.c
|
2023-01-05 21:13:10 +01:00
|
|
|
mkdir --parents ./bin
|
|
|
|
${CC} ${CC_FLAGS} -o ${SET_VERSION_EXECUTABLE} ./set_version.c ${LIB_CC_FLAGS}
|
|
|
|
|
2023-01-05 19:28:05 +01:00
|
|
|
.PHONY: test
|
2023-01-06 17:37:50 +01:00
|
|
|
test: ${LIB} $(addprefix build/, ${TEST_OBJECTS})
|
2023-01-05 19:28:05 +01:00
|
|
|
mkdir --parents ./bin
|
2023-01-06 17:37:50 +01:00
|
|
|
${CC} ${CC_FLAGS} -o ${TEST_EXECUTABLE} $(addprefix build/, ${TEST_OBJECTS}) ${LIB_CC_FLAGS}
|
2023-01-05 19:28:05 +01:00
|
|
|
./${TEST_EXECUTABLE}
|
|
|
|
|
|
|
|
.PHONY: lint
|
|
|
|
lint:
|
|
|
|
clang-format --Werror --dry-run ${LIB_SOURCES} ${TEST_SOURCES} ${HEADER_FILES} ./main.c
|
|
|
|
|
2023-01-06 16:32:29 +01:00
|
|
|
.PHONY: documentation
|
|
|
|
documentation:
|
|
|
|
doxygen ./Doxyfile
|
|
|
|
|
2023-01-05 19:28:05 +01:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2023-01-06 17:37:50 +01:00
|
|
|
rm --recursive --force ./build ./bin ./documentation
|