Skip to content

Commit

Permalink
Merge pull request #60 from IOOPM-UU/makefile_refactor
Browse files Browse the repository at this point in the history
Makefile refactor
  • Loading branch information
Truxilla authored Jan 13, 2025
2 parents d713573 + f82c97e commit 12435a5
Show file tree
Hide file tree
Showing 47 changed files with 599 additions and 607 deletions.
58 changes: 44 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,64 @@
# Define compiler and options
C_COMPILER = gcc
C_OPTIONS = -Wall -pedantic -Wextra -g
C_OPTIONS =
C_LINK_OPTIONS = -lm
CUNIT_LINK = -lcunit
C_COVERAGE = gcov -abcfu --coverage
R_COVERAGE = gcovr -r . --html --html-details -o coverage.html

# Source and object files
REF = src/ref.c
REF_OBJ = src/ref.o
REF = src/refmem.c
TEST_SRC = test/test.c
TEST_OBJ = test/test.o
HASH = src/lib/lib_hash_table.c
HASH_OBJ = src/lib/lib_hash_table.o
LIST = src/lib/lib_linked_list.c
LIST_OBJ = src/lib/lib_linked_list.o


# Object files
OBJ_DIR = obj
SRC_DIR = src
LIB_DIR = lib
TEST_DIR = test
REF_OBJ = $(OBJ_DIR)/refmem.o
TEST_OBJ = $(OBJ_DIR)/$(TEST_DIR)/test.o
HASH_OBJ = $(OBJ_DIR)/$(LIB_DIR)/lib_hash_table.o
LIST_OBJ = $(OBJ_DIR)/$(LIB_DIR)/lib_linked_list.o

# Pattern rule to compile .c files into .o files
%.o: %.c
$(OBJ_DIR)/%.o: src/%.c
$(C_COMPILER) $(C_OPTIONS) -c $< -o $@

$(OBJ_DIR)/lib/%.o: src/lib/%.c
$(C_COMPILER) $(C_OPTIONS) -c $< -o $@

$(OBJ_DIR)/test/%.o: test/%.c
$(C_COMPILER) $(C_OPTIONS) -c $< -o $@

# Target for the reference executable
ref: $(REF_OBJ) $(TEST_OBJ) $(HASH_OBJ) $(LIST_OBJ)
$(C_COMPILER) $(C_LINK_OPTIONS) $(REF_OBJ) $(TEST_OBJ) $(HASH_OBJ) $(LIST_OBJ) -o $@ $(CUNIT_LINK)
all: $(REF_OBJ) $(TEST_OBJ) $(HASH_OBJ) $(LIST_OBJ)
$(C_COMPILER) $(C_LINK_OPTIONS) $(REF_OBJ) $(TEST_OBJ) $(HASH_OBJ) $(LIST_OBJ) -o $@ $(CUNIT_LINK)

run: ref
valgrind --leak-check=full --show-leak-kinds=all ./ref
valgrind --leak-check=full --show-leak-kinds=all ./refmem

demo:
$(MAKE) -C demo run_frontend

memdemo:
$(MAKE) -C demo full_val_frontend

# Target for the test executable
ref_test: $(REF_OBJ) $(TEST_OBJ) $(HASH_OBJ) $(LIST_OBJ)
$(C_COMPILER) $(C_LINK_OPTIONS) $(REF_OBJ) $(TEST_OBJ) $(HASH_OBJ) $(LIST_OBJ) -o $@ $(CUNIT_LINK)
valgrind --leak-check=full --show-leak-kinds=all ./ref_test
test: $(REF_OBJ) $(TEST_OBJ) $(HASH_OBJ) $(LIST_OBJ)
$(C_COMPILER) $(C_LINK_OPTIONS) $(REF_OBJ) $(TEST_OBJ) $(HASH_OBJ) $(LIST_OBJ) -o $(OBJ_DIR)/test/test $(CUNIT_LINK)
$(OBJ_DIR)/test/test
$(MAKE) -C demo backend_tests
$(MAKE) -C demo run_backend_tests

memtest: $(REF_OBJ) $(TEST_OBJ) $(HASH_OBJ) $(LIST_OBJ)
$(C_COMPILER) $(C_LINK_OPTIONS) $(REF_OBJ) $(TEST_OBJ) $(HASH_OBJ) $(LIST_OBJ) -o $(OBJ_DIR)/test/test $(CUNIT_LINK)
valgrind --leak-check=full --show-leak-kinds=all $(OBJ_DIR)/test/test
$(MAKE) -C demo backend_tests
$(MAKE) -C demo full_val_backend_tests


gdb: ref
gdb ./ref --tui
Expand All @@ -45,4 +73,6 @@ coverage: cov

# Clean up generated files
clean:
rm -f src/*.o inlupp2_DONOTTOUCH/generic_data_structures/*.o test/*.o ref* cov* test.c.*
rm -f obj/*.o obj/*/*.o obj/test/test obj/backend_tests obj/frontend *.gcda *.gcno ref* cov* test.c.*

.PHONY: demo all
25 changes: 0 additions & 25 deletions README.md

This file was deleted.

Binary file added all
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "../generic_data_structures/hash_table.h"
#include "../generic_data_structures/iterator.h"
#include "../generic_utils/utils.h"
#include "../../ref.h"
#include "../../src/refmem.h"


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "../generic_data_structures/hash_table.h"
#include "../generic_data_structures/iterator.h"
#include "../generic_utils/utils.h"
#include "../../ref.h"
#include "../../src/refmem.h"

#define Successful(o) (o.success == true)
#define Unsuccessful(o) (o.success == false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "../generic_data_structures/hash_table.h"
#include "../generic_data_structures/iterator.h"
#include "../generic_utils/utils.h"
#include "../../ref.h"
#include "../../src/refmem.h"

bool pointer_is_null(void *ptr)
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include "../generic_data_structures/hash_table.h"
#include "../generic_data_structures/iterator.h"
#include "../generic_utils/utils.h"
#include "../../ref.h"

#include "../../src/refmem.h"



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "../generic_data_structures/hash_table.h"
#include "../generic_data_structures/iterator.h"
#include "../generic_utils/utils.h"
#include "../../ref.h"
#include "../../src/refmem.h"

void shop_destructor(obj *shop) {
if (!shop) return;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdbool.h>
#include <string.h>
#include "linked_list.h"
#include "../../ref.h"
#include "../../src/refmem.h"

#define Success(k, v) \
(ioopm_option_t) { .success = true, .key = k, .value = v }
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdlib.h>
#include "common.h"
#include <stddef.h>
#include "../../ref.h"
#include "../../src/refmem.h"

#define null_elem \
(elem_t) { 0 }
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern char *strdup(const char *);
#include <ctype.h> //för isdigit
#include <stdio.h>
#include "utils.h"
#include "../../ref.h"
#include "../../src/refmem.h"

bool not_empty(char *str)
{
Expand Down
File renamed without changes.
117 changes: 117 additions & 0 deletions demo/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Define compiler and options
CC = gcc
CFLAGS = -g -Wall -pedantic -Wextra -w
LDFLAGS = -lcunit -lm
OBJ_DIR = ../obj
SRC_DIR = ../src
GEN_UTILS_DIR = generic_utils
GEN_DS_DIR = generic_data_structures
BUS_LOGIC_DIR = business_logic
TESTS_DIR = tests
UI_DIR = user_interface
LIB_DIR = ../src/lib



# Source files for frontend
FRONTEND_SRC = $(UI_DIR)/frontend.c $(GEN_UTILS_DIR)/utils.c $(GEN_DS_DIR)/linked_list.c \
$(GEN_DS_DIR)/hash_table.c $(BUS_LOGIC_DIR)/shop.c $(BUS_LOGIC_DIR)/merch.c \
$(BUS_LOGIC_DIR)/cart.c $(BUS_LOGIC_DIR)/common.c $(SRC_DIR)/refmem.c \
$(LIB_DIR)/lib_hash_table.c $(LIB_DIR)/lib_linked_list.c

# Source files for backend tests
BACKEND_TEST_SRC = $(BUS_LOGIC_DIR)/common.c $(BUS_LOGIC_DIR)/shop.c $(BUS_LOGIC_DIR)/merch.c \
$(BUS_LOGIC_DIR)/cart.c $(TESTS_DIR)/backend_tests.c $(GEN_UTILS_DIR)/utils.c \
$(GEN_DS_DIR)/linked_list.c $(GEN_DS_DIR)/hash_table.c $(SRC_DIR)/refmem.c \
$(LIB_DIR)/lib_hash_table.c $(LIB_DIR)/lib_linked_list.c

# Targets
.PHONY: all clean run valgrind debug test

all: frontend backend_tests

# Frontend target
frontend: $(FRONTEND_SRC) | $(OBJ_DIR)
$(CC) $(CFLAGS) $^ -o $(OBJ_DIR)/frontend $(LDFLAGS)

run_frontend: frontend
clear
./$(OBJ_DIR)/frontend

val_frontend: frontend
valgrind -s ./$(OBJ_DIR)/frontend

full_val_frontend: frontend
clear
valgrind -s --leak-check=full ./$(OBJ_DIR)/frontend

clean_frontend:
make clean; make frontend; make run_frontend

# Backend tests target
backend_tests: $(BACKEND_TEST_SRC) | $(OBJ_DIR)
$(CC) $(CFLAGS) $^ -o $(OBJ_DIR)/backend_tests $(LDFLAGS)

run_backend_tests: backend_tests
./$(OBJ_DIR)/backend_tests

val_backend_tests: backend_tests
valgrind -s ./$(OBJ_DIR)/backend_tests

full_val_backend_tests: backend_tests
valgrind -s --leak-check=full ./$(OBJ_DIR)/backend_tests

clean_val_backend_tests:
make clean; make backend_tests; make val_backend_tests

test: clean_val_backend_tests

# Debug target
debug: backend_tests
gdb ./$(OBJ_DIR)/backend_tests --tui

# Coverage target
backend_tests_cov: $(BACKEND_TEST_SRC) | $(OBJ_DIR)
$(CC) $(CFLAGS) $^ -o $(OBJ_DIR)/backend_tests_coverage --coverage $(LDFLAGS)

cov_run: backend_tests_cov
./$(OBJ_DIR)/backend_tests_coverage

gcov:
gcov -b -c $(OBJ_DIR)/backend_tests_coverage.gcda > coverage.txt

# Old hash target
old_hash: $(GEN_DS_DIR)/hash_table.c $(GEN_DS_DIR)/linked_list.c $(GEN_DS_DIR)/hash_table_tests.c $(SRC_DIR)/refmem.c $(LIB_DIR)/lib_hash_table.c $(LIB_DIR)/lib_linked_list.c
$(CC) $(CFLAGS) $^ -o $(OBJ_DIR)/old_hash $(LDFLAGS)
valgrind -s --leak-check=full ./$(OBJ_DIR)/old_hash

# Old list target
old_list: $(GEN_DS_DIR)/linked_list.c $(GEN_DS_DIR)/linked_list_tests.c $(SRC_DIR)/refmem.c $(LIB_DIR)/lib_hash_table.c $(LIB_DIR)/lib_linked_list.c
$(CC) $(CFLAGS) $^ -o $(OBJ_DIR)/old_list $(LDFLAGS)
valgrind -s --leak-check=full ./$(OBJ_DIR)/old_list

old_list_full: old_list
valgrind -s --leak-check=full --show-leak-kinds=all ./$(OBJ_DIR)/old_list

# Hidden tests
tests_hidden: frontend
@GREEN='\033[1;32m'; \
RED='\033[1;31m'; \
NC='\033[0m'; \
for file in ./$(UI_DIR)/ui-tests/*.txt; do \
base_name=$$(basename $$file .txt); \
echo "Running test: $$base_name"; \
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(OBJ_DIR)/frontend < $$file > temp_output.txt 2>&1; \
if grep -q "ERROR SUMMARY: 0 errors" temp_output.txt; then \
echo -e "$$base_name $$GREEN PASSED $$NC"; \
else \
echo -e "$$base_name $$RED FAILED $$NC"; \
cat temp_output.txt; \
fi; \
done
@rm -f temp_output.txt

# Clean target
clean:
rm -rf $(OBJ_DIR) *.gcno *.gcda *.gcov coverage.txt
rm -f frontend backend_tests old_hash ol
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
#include "../generic_data_structures/linked_list.h"
#include "../generic_data_structures/hash_table.h"
#include "../generic_data_structures/iterator.h"
#include "../../ref.h"
#include "../../src/refmem.h"

typedef struct merch ioopm_merch_t;
typedef struct shelf ioopm_shelf_t;
typedef struct shop ioopm_shop_t;
typedef struct shopping_carts shopping_carts_t;
typedef struct cart cart_t;
typedef struct cart_item cart_item_t;

#define Successful(o) (o.success == true)
#define Unsuccessful(o) (o.success == false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "../generic_data_structures/hash_table.h"
#include "../generic_data_structures/iterator.h"
#include "../generic_utils/utils.h"
#include "../../ref.h"
#include "../../src/refmem.h"

#define ValidOptions "AaLlDdEeSsPpCcRr+-=OoQq"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added obj/backend_tests
Binary file not shown.
Binary file added obj/frontend
Binary file not shown.
Binary file added obj/test/test
Binary file not shown.
47 changes: 0 additions & 47 deletions proj/design_report.md

This file was deleted.

Loading

0 comments on commit 12435a5

Please sign in to comment.