aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortony <tsyrogit@users.noreply.github.com>2016-09-25 17:57:31 +0100
committertony <tsyrogit@users.noreply.github.com>2016-09-25 17:57:31 +0100
commit996bd3c547eb93d7bdd4b4e6c149486050607ddc (patch)
tree196417400cc42892d6a19ef9a141c2c19fca07b1
parent11cabf3ec7dd8a10fe863192de4572ec0a6302b5 (diff)
parentcd587a1613cb0904ec3c7118d4d6b7d04d070c05 (diff)
downloadzxcvbn-c-996bd3c547eb93d7bdd4b4e6c149486050607ddc.tar.gz
Merge branch 'build-libs' of https://github.com/spwhitton/zxcvbn-c
-rw-r--r--makefile35
-rw-r--r--test.c2
-rw-r--r--zxcvbn.c2
3 files changed, 34 insertions, 5 deletions
diff --git a/makefile b/makefile
index ca5c352..2cf5c9e 100644
--- a/makefile
+++ b/makefile
@@ -1,9 +1,31 @@
CFLAGS ?= -O2 -Wall -Wextra -Wdeclaration-after-statement
CPPFLAGS ?= -O2 -Wall -Wextra
+# need zxcvbn.h prior to package installation
+CFLAGS += -I.
+CPPFLAGS += -I.
+
+# library metadata
+TARGET_LIB = libzxcvbn.so.0.0.0
+SONAME = libzxcvbn.so.0
+
WORDS = words-10k-pass.txt words-english.txt words-female.txt words-male.txt words-surname.txt
-all: test-file test-inline test-c++inline test-c++file
+all: test-file test-inline test-c++inline test-c++file test-shlib test-statlib
+
+test-shlib: test.c $(TARGET_LIB)
+ if [ ! -e libzxcvbn.so ]; then ln -s $(TARGET_LIB) libzxcvbn.so; fi
+ gcc $(CFLAGS) -o $@ $< -L. -lzxcvbn -lm
+
+$(TARGET_LIB): zxcvbn-inline-pic.o
+ gcc $(CFLAGS) $(LDFLAGS) -fPIC -shared -Wl,-soname,$(SONAME) -o $@ $^ -lm
+ if [ ! -e $(SONAME) ]; then ln -s $(TARGET_LIB) $(SONAME); fi
+
+test-statlib: test.c libzxcvbn.a
+ gcc $(CFLAGS) $(LDFLAGS) -o $@ $^ -lm
+
+libzxcvbn.a: zxcvbn-inline.o
+ ar cvq $@ $^
test-file: test.c zxcvbn-file.o
gcc $(CFLAGS) -DUSE_DICT_FILE -o test-file test.c zxcvbn-file.o -lm
@@ -14,6 +36,9 @@ zxcvbn-file.o: zxcvbn.c dict-crc.h zxcvbn.h
test-inline: test.c zxcvbn-inline.o
gcc $(CFLAGS) -o test-inline test.c zxcvbn-inline.o -lm
+zxcvbn-inline-pic.o: zxcvbn.c dict-src.h zxcvbn.h
+ gcc $(CFLAGS) -fPIC -c -o $@ $<
+
zxcvbn-inline.o: zxcvbn.c dict-src.h zxcvbn.h
gcc $(CFLAGS) -c -o zxcvbn-inline.o zxcvbn.c
@@ -42,11 +67,15 @@ zxcvbn-c++file.o: zxcvbn.c dict-crc.h zxcvbn.h
if [ ! -e zxcvbn.cpp ]; then ln -s zxcvbn.c zxcvbn.cpp; fi
g++ $(CPPFLAGS) -DUSE_DICT_FILE -c -o zxcvbn-c++file.o zxcvbn.cpp
-test: test-file test-inline test-c++inline test-c++file testcases.txt
+test: test-file test-inline test-c++inline test-c++file test-shlib test-statlib testcases.txt
@echo Testing C build, dictionary from file
./test-file -t testcases.txt
@echo Testing C build, dictionary in executable
./test-inline -t testcases.txt
+ @echo Testing C shlib, dictionary in shlib
+ LD_LIBRARY_PATH=. ./test-shlib -t testcases.txt
+ @echo Testing C static lib, dictionary in lib
+ ./test-statlib -t testcases.txt
@echo Testing C++ build, dictionary from file
./test-c++file -t testcases.txt
@echo Testing C++ build, dictionary in executable
@@ -58,4 +87,4 @@ clean:
rm -f test-inline zxcvbn-inline.o test-c++inline zxcvbn-c++inline.o
rm -f dict-*.h zxcvbn.dict zxcvbn.cpp test.cpp
rm -f dictgen
- \ No newline at end of file
+ rm -f ${TARGET_LIB} ${SONAME} libzxcvbn.so test-shlib libzxcvbn.a test-statlib
diff --git a/test.c b/test.c
index 9d74ce5..bb0f8bd 100644
--- a/test.c
+++ b/test.c
@@ -34,7 +34,7 @@
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
-#include "zxcvbn.h"
+#include <zxcvbn.h>
/* For pre-compiled headers under windows */
#ifdef _WIN32
diff --git a/zxcvbn.c b/zxcvbn.c
index c801ae0..bfb40b3 100644
--- a/zxcvbn.c
+++ b/zxcvbn.c
@@ -30,7 +30,7 @@
*
**********************************************************************************/
-#include "zxcvbn.h"
+#include <zxcvbn.h>
#include <ctype.h>
#include <string.h>
#include <stdint.h>