aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2016-09-28 08:53:50 -0700
committerSean Whitton <spwhitton@spwhitton.name>2016-09-28 08:53:50 -0700
commitbafd7db81b225b45743256c5f151c4acba0221b1 (patch)
tree808de09c88924102d369e7575155746af0057dbb
parent90c1e81cf32c6b208865b3dc9143426152d8ddab (diff)
parent915dd05d5e269e37e276b2a9c2fc37bd3677de15 (diff)
downloadzxcvbn-c-bafd7db81b225b45743256c5f151c4acba0221b1.tar.gz
Merge tag '0.20160925'
-rw-r--r--makefile40
-rw-r--r--test.c2
-rw-r--r--zxcvbn.c4
3 files changed, 38 insertions, 8 deletions
diff --git a/makefile b/makefile
index 2007411..2cf5c9e 100644
--- a/makefile
+++ b/makefile
@@ -1,9 +1,31 @@
-CFLAGS = -O2 -Wall -Wextra -Wdeclaration-after-statement
-CPPFLAGS = -O2 -Wall -Wextra
+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
@@ -56,5 +85,6 @@ test: test-file test-inline test-c++inline test-c++file testcases.txt
clean:
rm -f test-file zxcvbn-file.o test-c++file zxcvbn-c++file.o
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 c29c20c..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>
@@ -212,7 +212,7 @@ static inline void MyOpenFile(FileHandle & f, const char *Name)
}
static inline bool MyReadFile(FileHandle & f, void *Buf, unsigned int Num)
{
- return f.read((char *)Buf, Num);
+ return (bool)f.read((char *)Buf, Num);
}
static inline void MyCloseFile(FileHandle & f)
{