Switch to using Makefile for *nix systems
This commit is contained in:
parent
c83c652b37
commit
0e5942af34
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
|
19
build
19
build
@ -1,3 +1,20 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
bear -- ./compile $@
|
BUILD_TYPE="debug"
|
||||||
|
ARGS=""
|
||||||
|
|
||||||
|
while [[ $# > 0 ]];do
|
||||||
|
case $1 in
|
||||||
|
--release)
|
||||||
|
BUILD_TYPE="release"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*|-*|--*)
|
||||||
|
rest=("$@")
|
||||||
|
ARGS+=" ${rest[0]}"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
bear -- make BUILD_TYPE=$BUILD_TYPE $ARGS
|
||||||
|
103
compile
103
compile
@ -1,103 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
BUILD_TYPE="debug"
|
|
||||||
COMPONENTS="all"
|
|
||||||
|
|
||||||
function join_array {
|
|
||||||
DELIM="$1"
|
|
||||||
shift
|
|
||||||
local IFS="$DELIM"
|
|
||||||
echo "$*"
|
|
||||||
}
|
|
||||||
|
|
||||||
SUPPORTED_COMPONENTS=("all" "testing" "core")
|
|
||||||
COMPONENTS_STRING="$(join_array "|" ${SUPPORTED_COMPONENTS[@]})"
|
|
||||||
|
|
||||||
while [[ $# > 0 ]];do
|
|
||||||
case $1 in
|
|
||||||
--release)
|
|
||||||
BUILD_TYPE="release"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--components)
|
|
||||||
COMPONENTS="$2"
|
|
||||||
shift
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
*|-*|--*)
|
|
||||||
echo "Unknown option $1"
|
|
||||||
echo "Usage: $0 [--release] [--components $COMPONENTS_STRING (Default: all)]"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
CC=clang
|
|
||||||
CFLAGS="-Wall -Wextra -Werror -pedantic"
|
|
||||||
LIBFLAGS="-fPIC -shared"
|
|
||||||
KERNEL="$(uname -s)"
|
|
||||||
MACHINE="$(uname -m)"
|
|
||||||
PLATFORM="${KERNEL}_${MACHINE}"
|
|
||||||
|
|
||||||
if [[ $CC == "gcc" ]]; then
|
|
||||||
# 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
|
|
||||||
fi
|
|
||||||
|
|
||||||
case $COMPONENTS in
|
|
||||||
all)
|
|
||||||
SRC="src/wapp.c"
|
|
||||||
;;
|
|
||||||
testing)
|
|
||||||
SRC="src/testing/wapp_testing.c"
|
|
||||||
;;
|
|
||||||
core)
|
|
||||||
SRC="src/core/wapp_core.c"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unrecognised option for components: $COMPONENTS"
|
|
||||||
echo "Accepted options: $COMPONENTS_STRING"
|
|
||||||
exit 2
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Run code generation
|
|
||||||
(set -x ; python3 -m codegen)
|
|
||||||
|
|
||||||
TEST_INCLUDE="-Isrc $(find tests -type d | xargs -I{} echo -n "-I{} ")"
|
|
||||||
TEST_SRC="$(find tests -type f -name "*.c" | xargs -I{} echo -n "{} ")"
|
|
||||||
|
|
||||||
BUILD_DIR="libwapp-build/$PLATFORM-$BUILD_TYPE"
|
|
||||||
if [[ -d $BUILD_DIR ]]; then
|
|
||||||
rm -rf $BUILD_DIR
|
|
||||||
fi
|
|
||||||
mkdir -p $BUILD_DIR
|
|
||||||
|
|
||||||
if [[ $BUILD_TYPE == "release" ]]; then
|
|
||||||
CFLAGS+=" -O3"
|
|
||||||
else
|
|
||||||
CFLAGS+=" -g -fsanitize=address,undefined"
|
|
||||||
fi
|
|
||||||
|
|
||||||
OUT="$BUILD_DIR/libwapp.so"
|
|
||||||
TEST_OUT="$BUILD_DIR/wapptest"
|
|
||||||
|
|
||||||
# Compile tests
|
|
||||||
if [[ $(echo $TEST_SRC | xargs) != "" ]]; then
|
|
||||||
(set -x ; $CC $CFLAGS $TEST_INCLUDE $SRC $TEST_SRC -o $TEST_OUT)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Run tests and exit on failure
|
|
||||||
if [[ -f $TEST_OUT ]]; then
|
|
||||||
$TEST_OUT
|
|
||||||
STATUS="$?"
|
|
||||||
|
|
||||||
rm $TEST_OUT
|
|
||||||
|
|
||||||
if [[ $STATUS != "0" ]]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Compile library
|
|
||||||
(set -x ; $CC $CFLAGS $LIBFLAGS $SRC -o $OUT)
|
|
Loading…
Reference in New Issue
Block a user