Reviewed-on: #4 Co-authored-by: Abdelrahman <said.abdelrahman89@gmail.com> Co-committed-by: Abdelrahman <said.abdelrahman89@gmail.com>
88 lines
2.5 KiB
Makefile
88 lines
2.5 KiB
Makefile
CC = clang
|
|
CXX = clang++
|
|
AR = ar
|
|
BUILD_TYPE = debug
|
|
CFLAGS = -Wall -Wextra -Werror -pedantic -std=gnu11 -Isrc
|
|
CXXFLAGS = -Wall -Wextra -Werror -pedantic -std=gnu++11 -Isrc
|
|
LIBFLAGS = -fPIC
|
|
KERNEL = $(shell uname -s)
|
|
MACHINE = $(shell uname -m)
|
|
PLATFORM = $(KERNEL)_$(MACHINE)
|
|
TEST_INCLUDE = -Isrc $(shell find tests -type d | xargs -I{} echo -n "-I{} ")
|
|
TEST_SRC = $(shell find tests -type f -name "*.c" | xargs -I{} echo -n "{} ")
|
|
TEST_C_SRC = src/wapp.c $(TEST_SRC)
|
|
TEST_CXX_SRC = $(shell find tests -type f -name "*.cc" | xargs -I{} echo -n "{} ")
|
|
BUILD_DIR = libwapp-build/$(PLATFORM)-$(BUILD_TYPE)
|
|
LIB_NAME = wapp
|
|
OBJ_OUT = $(BUILD_DIR)/$(LIB_NAME).o
|
|
LIB_OUT = $(BUILD_DIR)/lib$(LIB_NAME).a
|
|
TEST_C_OUT = $(BUILD_DIR)/wapptest
|
|
TEST_CXX_OUT = $(BUILD_DIR)/wapptestcc
|
|
|
|
ifeq ($(BUILD_TYPE),debug)
|
|
CFLAGS += -g -fsanitize=address,undefined -DWAPP_DEBUG_ASSERT
|
|
CXXFLAGS += -g -fsanitize=address,undefined -DWAPP_DEBUG_ASSERT
|
|
else ifeq ($(BUILD_TYPE),release)
|
|
CFLAGS += -O3
|
|
CXXFLAGS += -O3
|
|
else
|
|
$(error Invalid BUILD type '$(BUILD_TYPE)'. Use 'debug' or 'release')
|
|
endif
|
|
|
|
ifeq ($(CC),gcc)
|
|
# Used to disable the "ASan runtime does not come first in initial library list" error when compiling with gcc
|
|
export ASAN_OPTIONS=verify_asan_link_order=0
|
|
endif
|
|
|
|
.PHONY: all clean builddir build-test run-test codegen build-lib full prng testing uuid core primitives
|
|
|
|
all: clean builddir codegen run-c-test full run-cc-test
|
|
|
|
clean:
|
|
@rm -rf $(BUILD_DIR)
|
|
|
|
builddir:
|
|
@mkdir -p $(BUILD_DIR)
|
|
|
|
build-c-test:
|
|
$(CC) $(CFLAGS) $(TEST_INCLUDE) $(TEST_C_SRC) -o $(TEST_C_OUT)
|
|
|
|
run-c-test: build-c-test
|
|
@echo -e "\n\033[34;1mRUNNING C TESTS\033[0m"
|
|
@$(TEST_C_OUT)
|
|
@rm $(TEST_C_OUT)
|
|
|
|
build-cc-test:
|
|
$(CXX) $(CXXFLAGS) $(TEST_INCLUDE) $(TEST_CXX_SRC) $(LIB_OUT) -o $(TEST_CXX_OUT)
|
|
|
|
run-cc-test: build-cc-test
|
|
@echo -e "\n\033[34;1mRUNNING C++ TESTS\033[0m"
|
|
@export LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$(BUILD_DIR) && $(TEST_CXX_OUT)
|
|
@rm $(TEST_CXX_OUT)
|
|
|
|
codegen:
|
|
python3 -m codegen
|
|
|
|
build-lib:
|
|
$(CC) -c $(CFLAGS) $(LIBFLAGS) $(LIB_SRC) -o $(OBJ_OUT)
|
|
$(AR) r $(LIB_OUT) $(OBJ_OUT)
|
|
@rm $(OBJ_OUT)
|
|
|
|
full: LIB_SRC = src/wapp.c
|
|
full: build-lib
|
|
|
|
prng: LIB_SRC = src/prng/wapp_prng.c
|
|
prng: build-lib
|
|
|
|
testing: LIB_SRC = src/testing/wapp_testing.c
|
|
testing: build-lib
|
|
|
|
uuid: LIB_SRC = src/uuid/wapp_uuid.c
|
|
uuid: build-lib
|
|
|
|
core: LIB_SRC = src/core/wapp_core.c
|
|
core: build-lib
|
|
|
|
primitives: LIB_SRC = src/core/wapp_primitives.c
|
|
primitives: build-lib
|