77 lines
1.9 KiB
Makefile
77 lines
1.9 KiB
Makefile
BSTRLIB_BASE_URL ?= https://raw.githubusercontent.com/websnarf/bstrlib/208b1f2a4dfc96b806ed499bd1909e87ec15981d
|
|
CFLAGS = -g -O2 -Wall -Wextra -Isrc -Lbuild -rdynamic -DNDEBUG $(OPTFLAGS)
|
|
LDLIBS = -ldl $(OPTLIBS)
|
|
|
|
PREFIX ?= /usr/local
|
|
|
|
FIND ?= find
|
|
CD ?= cd
|
|
PATCH ?= patch
|
|
INSTALL ?= install
|
|
MKDIR ?= mkdir -p
|
|
CURL ?= curl -sSL
|
|
RANLIB ?= ranlib
|
|
RUNTESTS ?= ./tests/runtests
|
|
|
|
SOURCES = $(wildcard src/**/*.c src/*.c)
|
|
OBJECTS = $(patsubst %.c,%.o,$(SOURCES))
|
|
|
|
TEST_SRC = $(wildcard tests/**/*_tests.c tests/*_tests.c)
|
|
TESTS = $(patsubst %.c,%,$(TEST_SRC))
|
|
|
|
LIBNAME = lcthw
|
|
TARGET = build/lib$(LIBNAME).a
|
|
SO_TARGET = $(patsubst %.a,%.so,$(TARGET))
|
|
|
|
all: $(TARGET) $(SO_TARGET) tests
|
|
|
|
dev: CFLAGS = -g -Wall -Isrc -Wall -Wextra $(OPTFLAGS)
|
|
dev: all
|
|
|
|
$(TARGET): CFLAGS += -fPIC
|
|
$(TARGET): build $(OBJECTS)
|
|
$(AR) rcs $@ $(OBJECTS)
|
|
$(RANLIB) $@
|
|
|
|
$(SO_TARGET): $(TARGET) $(OBJECTS)
|
|
$(CC) -shared -o $@ $(OBJECTS)
|
|
|
|
build: bin src/lcthw/bstrlib.c src/lcthw/bstrlib.h
|
|
@$(MKDIR) $@
|
|
|
|
bin:
|
|
@$(MKDIR) $@
|
|
|
|
src/lcthw/bstrlib.c: src/lcthw/bstrlib.h
|
|
$(CURL) -o $@ $(BSTRLIB_BASE_URL)/bstrlib.c
|
|
$(CD) src/lcthw && $(PATCH) -p1 < bstrlib.patch
|
|
|
|
src/lcthw/bstrlib.h:
|
|
$(CURL) -o $@ $(BSTRLIB_BASE_URL)/bstrlib.h
|
|
|
|
.PHONY: tests
|
|
tests: LDLIBS += -static -l$(LIBNAME) -lbsd
|
|
tests: $(RUNTESTS) $(TESTS)
|
|
$(RUNTESTS) ./tests/lcthw
|
|
|
|
valgrind:
|
|
VALGRIND="valgrind --log-file=/tmp/valgrind-%p.log" $(MAKE)
|
|
|
|
clean:
|
|
$(RM) -r build $(OBJECTS) $(TESTS)
|
|
$(RM) tests/tests.log tests/runtests
|
|
$(FIND) . -name "*.gc*" -exec rm {} \;
|
|
$(RM) -r `find . -name "*.dSYM" -print`
|
|
|
|
distclean: clean
|
|
$(RM) src/lcthw/bstrlib.c src/lcthw/bstrlib.h
|
|
|
|
install: all
|
|
$(INSTALL) -d $(DESTDIR)/$(PREFIX)/lib/
|
|
$(INSTALL) $(TARGET) $(DESTDIR)/$(PREFIX)/lib/
|
|
|
|
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
|