diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | .make.example | 13 | ||||
| -rw-r--r-- | Makefile | 79 |
3 files changed, 54 insertions, 39 deletions
@@ -1 +1,2 @@ compile_commands.json +.make diff --git a/.make.example b/.make.example new file mode 100644 index 0000000..ceb431f --- /dev/null +++ b/.make.example @@ -0,0 +1,13 @@ +# Makefile config + +# Change which C compiler will be used +# +# default: CC=cc +CC= + +# Change where the header and lib files will land +# .h files will land in $(TARGET_PREFIX)/include +# .so and/or .a file will land in $(TARGET_PREFIX)/lib +# +# default: TARGET_PREFIX=/usr/local +TARGET_PREFIX= @@ -1,47 +1,48 @@ -CC=cc -CFLAGS=-std=c99 -Wall -Wextra -Wpedantic -fPIC -I./include -O2 -CFLAGS_TEST=-std=c99 -Wall -Wextra -Wpedantic -Og -ggdb +-include .make +ifeq ($(CC),) + CC=cc +endif +ifeq ($(TARGET_PREFIX),) + TARGET_PREFIX=/usr/local +endif + AR=ar rcs -RUN_TESTS=./run_tests -ifeq ($(shell uname -s),Darwin) - RUN_TESTS=DYLD_FALLBACK_LIBRARY_PATH="/usr/local/lib:$DYLD_FALLBACK_LIBRARY_PATH" - RUN_TESTS+= ./run_tests; rm -rf run_tests.dSYM/ -endif +LIB_DIR=$(TARGET_PREFIX)/lib +LIB_SUDO:=$(shell test -w $(LIB_DIR) || echo sudo) +INC_DIR=$(TARGET_PREFIX)/include +INC_SUDO:=$(shell test -w $(INC_DIR) || echo sudo) + +CFLAGS=-std=c99 -Wall -Wextra -Wpedantic -fPIC -I./include -O2 -c +SRCS:=$(shell find src | grep \\.c$) -both: shared static clean +TESTS_CFLAGS=-std=c99 -Wall -Wextra -Wpedantic -I$(INC_DIR) -Og -ggdb -c +TESTS_LDFLAGS=-L$(LIB_DIR) -Wl,-rpath,$(LIB_DIR) -lmoslib +TESTS_SRCS:=$(shell find tests | grep \\.c$) -shared: compile headers - $(CC) -shared *.o -o libmoslib.so - strip -x libmoslib.so - sudo mv libmoslib.so /usr/local/lib +both: clean shared static + $(MAKE) clean -static: compile headers - $(AR) libmoslib.a *.o - strip -S libmoslib.a - sudo mv libmoslib.a /usr/local/lib +shared: clean compile headers + $(LIB_SUDO) $(CC) -shared *.o -o $(LIB_DIR)/libmoslib.so + $(LIB_SUDO) strip -x $(LIB_DIR)/libmoslib.so + +static: clean compile headers + $(LIB_SUDO) $(AR) $(LIB_DIR)/libmoslib.a *.o + $(LIB_SUDO) strip -S $(LIB_DIR)/libmoslib.a headers: - sudo cp -r include/* /usr/local/include - -compile: structures - $(CC) $(CFLAGS) -c src/tester.c - $(CC) $(CFLAGS) -c src/safe.c - $(CC) $(CFLAGS) -c src/string.c - -structures: - $(CC) $(CFLAGS) -c src/ds/array.c - $(CC) $(CFLAGS) -c src/ds/hashmap.c - -test: - $(CC) $(CFLAGS_TEST) -c tests/safe_tests.c - $(CC) $(CFLAGS_TEST) -c tests/ds/array_tests.c - $(CC) $(CFLAGS_TEST) -c tests/string_tests.c - $(CC) $(CFLAGS_TEST) -c tests/ds/hashmap_tests.c - $(CC) $(CFLAGS_TEST) -lmoslib *.o tests/tests.c -o run_tests - $(RUN_TESTS) - rm run_tests *.o - -.PHONY: clean + $(INC_SUDO) cp -r include/* $(INC_DIR) + +compile: + $(CC) $(CFLAGS) $(SRCS) + +test: clean + $(CC) $(TESTS_CFLAGS) $(TESTS_SRCS) + $(CC) $(TESTS_LDFLAGS) *.o -o run_tests + ./run_tests + $(MAKE) clean + clean: - rm *.o + rm *.o run_tests 2>/dev/null || true + rm -rf *.dSYM/ 2>/dev/null || true |
