2016-04-16 18:48:19 +00:00
|
|
|
CFLAGS = -g -O2 -Wall -Wextra -Isrc -Lbuild -rdynamic -DNDEBUG $(OPTFLAGS)
|
|
|
|
LDLIBS = -ldl $(OPTLIBS)
|
|
|
|
|
2016-04-16 17:39:22 +00:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
|
|
|
|
SOURCES = $(wildcard src/**/*.c src/*.c)
|
|
|
|
OBJECTS = $(patsubst %.c,%.o,$(SOURCES))
|
|
|
|
|
|
|
|
TEST_SRC = $(wildcard tests/*_tests.c)
|
|
|
|
TESTS = $(patsubst %.c,%,$(TEST_SRC))
|
|
|
|
|
2016-04-16 18:48:19 +00:00
|
|
|
LIBNAME = YOUR_LIBRARY
|
|
|
|
TARGET = build/lib$(LIBNAME).a
|
2016-04-16 17:39:22 +00:00
|
|
|
SO_TARGET = $(patsubst %.a,%.so,$(TARGET))
|
|
|
|
|
|
|
|
# The Target Build
|
|
|
|
all: $(TARGET) $(SO_TARGET) tests
|
|
|
|
|
|
|
|
dev: CFLAGS = -g -Wall -Isrc -Wall -Wextra $(OPTFLAGS)
|
|
|
|
dev: all
|
|
|
|
|
|
|
|
$(TARGET): CFLAGS += -fPIC
|
|
|
|
$(TARGET): build $(OBJECTS)
|
2016-04-16 18:48:19 +00:00
|
|
|
$(AR) rcs $@ $(OBJECTS)
|
2016-04-16 17:39:22 +00:00
|
|
|
ranlib $@
|
|
|
|
|
|
|
|
$(SO_TARGET): $(TARGET) $(OBJECTS)
|
|
|
|
$(CC) -shared -o $@ $(OBJECTS)
|
|
|
|
|
|
|
|
build:
|
|
|
|
@mkdir -p build
|
|
|
|
@mkdir -p bin
|
|
|
|
|
|
|
|
# The Unit Tests
|
|
|
|
.PHONY: tests
|
2016-04-16 18:48:19 +00:00
|
|
|
tests: LDLIBS += -static -l$(LIBNAME)
|
2016-04-16 17:39:22 +00:00
|
|
|
tests: $(TESTS)
|
|
|
|
sh ./tests/runtests.sh
|
|
|
|
|
|
|
|
valgrind:
|
|
|
|
VALGRIND="valgrind --log-file=/tmp/valgrind-%p.log" $(MAKE)
|
|
|
|
|
|
|
|
# The Cleaner
|
|
|
|
clean:
|
|
|
|
rm -rf build $(OBJECTS) $(TESTS)
|
|
|
|
rm -f tests/tests.log
|
|
|
|
find . -name "*.gc*" -exec rm {} \;
|
|
|
|
rm -rf `find . -name "*.dSYM" -print`
|
|
|
|
|
|
|
|
# The Install
|
|
|
|
install: all
|
|
|
|
install -d $(DESTDIR)/$(PREFIX)/lib/
|
|
|
|
install $(TARGET) $(DESTDIR)/$(PREFIX)/lib/
|
|
|
|
|
|
|
|
# The Checker
|
|
|
|
BADFUNCS='[^_.>a-zA-Z0-9](str(n?cpy|n?cat|xfrm|n?dup|str|pbrk|tok|_)|stpn?cpy|a?sn?printf|byte_)'
|
|
|
|
check:
|
|
|
|
@echo Files with potentially dangerous functions
|
|
|
|
@egrep $(BADFUNCS) $(SOURCES) || true
|