Switch to using Makefile for *nix systems
This commit is contained in:
57
Makefile
Normal file
57
Makefile
Normal file
@@ -0,0 +1,57 @@
|
||||
CC = clang
|
||||
BUILD_TYPE = debug
|
||||
CFLAGS = -Wall -Wextra -Werror -pedantic
|
||||
LIBFLAGS = -fPIC -shared
|
||||
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 = src/wapp.c $(shell find tests -type f -name "*.c" | xargs -I{} echo -n "{} ")
|
||||
BUILD_DIR = libwapp-build/$(PLATFORM)-$(BUILD_TYPE)
|
||||
LIB_OUT = $(BUILD_DIR)/libwapp.so
|
||||
TEST_OUT = $(BUILD_DIR)/wapptest
|
||||
|
||||
ifeq ($(BUILD_TYPE),debug)
|
||||
CFLAGS += -g -fsanitize=address,undefined
|
||||
else ifeq ($(BUILD_TYPE),release)
|
||||
CFLAGS += -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 codegen build-test run-test build-lib full testing core
|
||||
|
||||
all: clean builddir codegen run-test full
|
||||
|
||||
clean:
|
||||
@rm -rf $(BUILD_DIR)
|
||||
|
||||
builddir:
|
||||
@mkdir -p $(BUILD_DIR)
|
||||
|
||||
codegen:
|
||||
python3 -m codegen
|
||||
|
||||
build-test:
|
||||
$(CC) $(CFLAGS) $(TEST_INCLUDE) $(TEST_SRC) -o $(TEST_OUT)
|
||||
|
||||
run-test: build-test
|
||||
@$(TEST_OUT)
|
||||
@rm $(TEST_OUT)
|
||||
|
||||
build-lib:
|
||||
$(CC) $(CFLAGS) $(LIBFLAGS) $(LIB_SRC) -o $(LIB_OUT)
|
||||
|
||||
full: LIB_SRC = src/wapp.c
|
||||
full: build-lib
|
||||
|
||||
testing: LIB_SRC = src/testing/wapp_testing.c
|
||||
testing: build-lib
|
||||
|
||||
core: LIB_SRC = src/core/wapp_core.c
|
||||
core: build-lib
|
Reference in New Issue
Block a user