Commit d62351f4 authored by Andrea Guzzo's avatar Andrea Guzzo
Browse files

added targets to build both shared and static libraries + make it build on osx

tests are now optional and can be built&run using the 'tests' target (make tests)
parent b8336bbc
......@@ -5,10 +5,23 @@ LLQUEUE_DIR = $(CONTRIB_DIR)/CLinkedListQueue
GCOV_OUTPUT = *.gcda *.gcno *.gcov
GCOV_CCFLAGS = -fprofile-arcs -ftest-coverage
SHELL = /bin/bash
CC = gcc
CCFLAGS = -g -O2 -Werror -Werror=return-type -Werror=uninitialized -Wcast-align -fno-omit-frame-pointer -fno-common -fsigned-char $(GCOV_CCFLAGS) -I$(LLQUEUE_DIR) -Iinclude
CFLAGS += -Iinclude -Werror -Werror=return-type -Werror=uninitialized -Wcast-align -Wno-pointer-sign \
-Wno-implicit-function-declaration -fno-omit-frame-pointer -fno-common -fsigned-char \
$(GCOV_CCFLAGS) -I$(LLQUEUE_DIR) -Iinclude -fPIC -g -O2
all: tests_main
UNAME := $(shell uname)
ifeq ($(UNAME), Darwin)
SHAREDFLAGS = -dynamiclib
SHAREDEXT = dylib
else
SHAREDFLAGS = -shared
SHAREDEXT = so
endif
OBJECTS = raft_server.o raft_server_properties.o raft_node.o raft_log.o
all: static shared
clinkedlistqueue:
mkdir -p $(LLQUEUE_DIR)/.git
......@@ -24,10 +37,22 @@ $(TEST_DIR)/main_test.c:
fi
cd $(TEST_DIR) && sh make-tests.sh "test_*.c" > main_test.c && cd ..
tests_main: raft_server.c raft_server_properties.c raft_log.c raft_node.c $(TEST_DIR)/main_test.c $(TEST_DIR)/test_server.c $(TEST_DIR)/test_node.c $(TEST_DIR)/test_log.c $(TEST_DIR)/test_scenario.c $(TEST_DIR)/mock_send_functions.c $(TEST_DIR)/CuTest.c $(LLQUEUE_DIR)/linked_list_queue.c
$(CC) $(CCFLAGS) -o $@ $^
.PHONY: shared
shared: $(OBJECTS)
$(CC) $(OBJECTS) $(LDFLAGS) $(CFLAGS) $(SHAREDFLAGS) -o libcraft.$(SHAREDEXT)
.PHONY: static
static: $(OBJECTS)
ar -r libcraft.a $(OBJECTS)
.PHONY: tests
tests: raft_server.c raft_server_properties.c raft_log.c raft_node.c $(TEST_DIR)/main_test.c $(TEST_DIR)/test_server.c $(TEST_DIR)/test_node.c $(TEST_DIR)/test_log.c $(TEST_DIR)/test_scenario.c $(TEST_DIR)/mock_send_functions.c $(TEST_DIR)/CuTest.c $(LLQUEUE_DIR)/linked_list_queue.c
$(CC) $(CFLAGS) -o tests_main $^
./tests_main
gcov raft_server.c
clean:
rm -f $(TEST_DIR)/main_test.c *.o $(GCOV_OUTPUT)
@rm -f $(TEST_DIR)/main_test.c *.o $(GCOV_OUTPUT); \
if [ -f "libcraft.$(SHAREDEXT)" ]; then rm libcraft.$(SHAREDEXT); fi;\
if [ -f libcraft.a ]; then rm libcraft.a; fi;\
if [ -f tests_main ]; then rm tests_main; fi;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment